2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-22 01:51:51 +00:00
criu/gen-offsets.sh
Cyrill Gorcunov 4a2a290137 make: Generate offsets from linked files only
Instead of generating offsets from early compiled
object files (one day the offsets obtained from
there might be changed during linkage stage) better
to get them from a final stage where all object
files involved are linked into complete binary blob.

That happened that at early stage we indeed were using
only single file per parasite and restorer but at present
there a couple of file involved (and will be more in
future) so we need a safe approach.

Also note the symbols being exported are prefixed as
"__export_". This is easier approach for now. Putting
such symbols into separate section requires a way
more efforts to handle.

The main reason of having two files (Elf object
and binary blob) is to get 1:1 mapping between
symbols definition and their position in binary
target.

The exported symbols name addresses are obtained
from object file and used as offsets in binary
target.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-18 18:22:15 +04:00

36 lines
501 B
Bash

#!/bin/sh
set -e
set -u
NAME=$1
INC_GUARD=__${NAME}_h__
PREFIX=${NAME}_blob_offset__
BLOB=${NAME}_blob
OBJNAME=${NAME}.bin.o
BINARY=${NAME}.bin
AWK_CMD='$2 ~ /^[tT]$/ { print "#define '$PREFIX'" $3 " 0x" $1; }'
cat << EOF
/* Autogenerated by $0, do not edit */
#ifndef $INC_GUARD
#define $INC_GUARD
EOF
nm $OBJNAME | grep "__export_" | tr . _ | awk "$AWK_CMD"
cat << EOF
static char $BLOB[] = {
EOF
hexdump -v -e '"\t" 8/1 "0x%02x, " "\n"' $BINARY
cat << EOF
};
#endif /* $INC_GUARD */
EOF