Commit 4a2a2901 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

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: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 662bfd5f
...@@ -89,7 +89,8 @@ parasite-util-net.o: util-net.c ...@@ -89,7 +89,8 @@ parasite-util-net.o: util-net.c
$(HEAD-BIN): $(PIE-LDS) $(OBJS-BLOB) parasite-util-net.o $(HEAD-BIN): $(PIE-LDS) $(OBJS-BLOB) parasite-util-net.o
$(E) " GEN " $@ $(E) " GEN " $@
$(Q) $(LD) -T $(PIE-LDS) $(OBJS-BLOB) parasite-util-net.o -o $@ $(Q) $(LD) --oformat=binary -T $(PIE-LDS) $(OBJS-BLOB) parasite-util-net.o -o $@
$(Q) $(LD) --oformat=elf64-x86-64 -T $(PIE-LDS) $(OBJS-BLOB) parasite-util-net.o -o $@.o
$(HEAD-BLOB-GEN): $(HEAD-BIN) $(GEN-OFFSETS) $(HEAD-BLOB-GEN): $(HEAD-BIN) $(GEN-OFFSETS)
$(E) " GEN " $@ $(E) " GEN " $@
...@@ -102,7 +103,8 @@ $(ROBJS): $(RSRCS-BLOB) ...@@ -102,7 +103,8 @@ $(ROBJS): $(RSRCS-BLOB)
$(RHEAD-BIN): $(ROBJS) $(PIE-LDS) $(RHEAD-BIN): $(ROBJS) $(PIE-LDS)
$(E) " GEN " $@ $(E) " GEN " $@
$(Q) $(LD) -T $(PIE-LDS) $(ROBJS) -o $@ $(Q) $(LD) --oformat=binary -T $(PIE-LDS) $(ROBJS) -o $@
$(Q) $(LD) --oformat=elf64-x86-64 -T $(PIE-LDS) $(ROBJS) -o $@.o
$(RHEAD-BLOB-GEN): $(RHEAD-BIN) $(GEN-OFFSETS) $(RHEAD-BLOB-GEN): $(RHEAD-BIN) $(GEN-OFFSETS)
$(E) " GEN " $@ $(E) " GEN " $@
......
...@@ -1233,8 +1233,8 @@ static int sigreturn_restore(pid_t pid, struct list_head *tgt_vmas, int nr_vmas) ...@@ -1233,8 +1233,8 @@ static int sigreturn_restore(pid_t pid, struct list_head *tgt_vmas, int nr_vmas)
* might be completely unused so it's here just for convenience. * might be completely unused so it's here just for convenience.
*/ */
restore_code_start = mem; restore_code_start = mem;
restore_thread_exec_start = restore_code_start + restorer_blob_offset__restore_thread; restore_thread_exec_start = restore_code_start + restorer_blob_offset____export_restore_thread;
restore_task_exec_start = restore_code_start + restorer_blob_offset__restore_task; restore_task_exec_start = restore_code_start + restorer_blob_offset____export_restore_task;
task_args = restore_code_start + restore_code_len; task_args = restore_code_start + restore_code_len;
thread_args = (void *)((long)task_args + sizeof(*task_args)); thread_args = (void *)((long)task_args + sizeof(*task_args));
......
...@@ -7,7 +7,7 @@ NAME=$1 ...@@ -7,7 +7,7 @@ NAME=$1
INC_GUARD=__${NAME}_h__ INC_GUARD=__${NAME}_h__
PREFIX=${NAME}_blob_offset__ PREFIX=${NAME}_blob_offset__
BLOB=${NAME}_blob BLOB=${NAME}_blob
OBJNAME=${NAME}.o OBJNAME=${NAME}.bin.o
BINARY=${NAME}.bin BINARY=${NAME}.bin
AWK_CMD='$2 ~ /^[tT]$/ { print "#define '$PREFIX'" $3 " 0x" $1; }' AWK_CMD='$2 ~ /^[tT]$/ { print "#define '$PREFIX'" $3 " 0x" $1; }'
...@@ -19,7 +19,7 @@ cat << EOF ...@@ -19,7 +19,7 @@ cat << EOF
EOF EOF
nm $OBJNAME | tr . _ | awk "$AWK_CMD" nm $OBJNAME | grep "__export_" | tr . _ | awk "$AWK_CMD"
cat << EOF cat << EOF
......
...@@ -96,10 +96,10 @@ struct parasite_drain_fd { ...@@ -96,10 +96,10 @@ struct parasite_drain_fd {
*/ */
#define PARASITE_ARGS_ADDR(start) \ #define PARASITE_ARGS_ADDR(start) \
((start) + parasite_blob_offset__parasite_args) ((start) + parasite_blob_offset____export_parasite_args)
#define PARASITE_CMD_ADDR(start) \ #define PARASITE_CMD_ADDR(start) \
((start) + parasite_blob_offset__parasite_cmd) ((start) + parasite_blob_offset____export_parasite_cmd)
#define PARASITE_HEAD_ADDR(start) \ #define PARASITE_HEAD_ADDR(start) \
((start) + parasite_blob_offset__parasite_head_start) ((start) + parasite_blob_offset____export_parasite_head_start)
#endif /* CR_PARASITE_H_ */ #endif /* CR_PARASITE_H_ */
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
struct task_restore_core_args; struct task_restore_core_args;
struct thread_restore_args; struct thread_restore_args;
extern long restore_task(struct task_restore_core_args *args); extern long __export_restore_task(struct task_restore_core_args *args);
extern long restore_thread(struct thread_restore_args *args); extern long __export_restore_thread(struct thread_restore_args *args);
typedef long (*task_restore_fcall_t) (struct task_restore_core_args *args); typedef long (*task_restore_fcall_t) (struct task_restore_core_args *args);
typedef long (*thread_restore_fcall_t) (struct thread_restore_args *args); typedef long (*thread_restore_fcall_t) (struct thread_restore_args *args);
......
...@@ -487,29 +487,29 @@ static int __used parasite_service(unsigned long cmd, void *args) ...@@ -487,29 +487,29 @@ static int __used parasite_service(unsigned long cmd, void *args)
return -1; return -1;
} }
static void __head parasite_head(void) static void __head __export_parasite_head(void)
{ {
/* /*
* The linker will handle the stack allocation. * The linker will handle the stack allocation.
*/ */
asm volatile("parasite_head_start: \n" asm volatile("__export_parasite_head_start: \n"
"leaq parasite_stack(%rip), %rsp \n" "leaq __export_parasite_stack(%rip), %rsp \n"
"subq $16, %rsp \n" "subq $16, %rsp \n"
"andq $~15, %rsp \n" "andq $~15, %rsp \n"
"pushq $0 \n" "pushq $0 \n"
"movq %rsp, %rbp \n" "movq %rsp, %rbp \n"
"movl parasite_cmd(%rip), %edi \n" "movl __export_parasite_cmd(%rip), %edi \n"
"leaq parasite_args(%rip), %rsi \n" "leaq __export_parasite_args(%rip), %rsi \n"
"call parasite_service \n" "call parasite_service \n"
"int $0x03 \n" "int $0x03 \n"
".align 8 \n" ".align 8 \n"
"parasite_cmd: \n" "__export_parasite_cmd: \n"
".long 0 \n" ".long 0 \n"
"parasite_args: \n" "__export_parasite_args: \n"
".long 0 \n" ".long 0 \n"
".space "__stringify(PARASITE_ARG_SIZE)",0 \n" ".space "__stringify(PARASITE_ARG_SIZE)",0 \n"
".space "__stringify(PARASITE_STACK_SIZE)", 0 \n" ".space "__stringify(PARASITE_STACK_SIZE)", 0 \n"
"parasite_stack: \n" "__export_parasite_stack: \n"
".long 0 \n"); ".long 0 \n");
} }
......
OUTPUT_FORMAT("binary")
OUTPUT_ARCH(i386:x86-64) OUTPUT_ARCH(i386:x86-64)
SECTIONS SECTIONS
...@@ -13,8 +12,6 @@ SECTIONS ...@@ -13,8 +12,6 @@ SECTIONS
. = ALIGN(32); . = ALIGN(32);
*(.bss*) *(.bss*)
. = ALIGN(32); . = ALIGN(32);
*(.export)
. = ALIGN(32);
} =0x00000000 } =0x00000000
/DISCARD/ : { /DISCARD/ : {
......
...@@ -128,7 +128,7 @@ static void restore_creds(struct creds_entry *ce) ...@@ -128,7 +128,7 @@ static void restore_creds(struct creds_entry *ce)
* Threads restoration via sigreturn. Note it's locked * Threads restoration via sigreturn. Note it's locked
* routine and calls for unlock at the end. * routine and calls for unlock at the end.
*/ */
long restore_thread(struct thread_restore_args *args) long __export_restore_thread(struct thread_restore_args *args)
{ {
long ret = -1; long ret = -1;
struct core_entry *core_entry; struct core_entry *core_entry;
...@@ -335,7 +335,7 @@ static u64 restore_mapping(const struct vma_entry *vma_entry) ...@@ -335,7 +335,7 @@ static u64 restore_mapping(const struct vma_entry *vma_entry)
* and jump execution to some predefined ip read from * and jump execution to some predefined ip read from
* core file. * core file.
*/ */
long restore_task(struct task_restore_core_args *args) long __export_restore_task(struct task_restore_core_args *args)
{ {
long ret = -1; long ret = -1;
struct task_entry *task_entry; struct task_entry *task_entry;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment