mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-22 01:51:51 +00:00
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>
This commit is contained in:
parent
662bfd5fbc
commit
4a2a290137
6
Makefile
6
Makefile
@ -89,7 +89,8 @@ parasite-util-net.o: util-net.c
|
||||
|
||||
$(HEAD-BIN): $(PIE-LDS) $(OBJS-BLOB) parasite-util-net.o
|
||||
$(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)
|
||||
$(E) " GEN " $@
|
||||
@ -102,7 +103,8 @@ $(ROBJS): $(RSRCS-BLOB)
|
||||
|
||||
$(RHEAD-BIN): $(ROBJS) $(PIE-LDS)
|
||||
$(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)
|
||||
$(E) " GEN " $@
|
||||
|
@ -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.
|
||||
*/
|
||||
restore_code_start = mem;
|
||||
restore_thread_exec_start = restore_code_start + restorer_blob_offset__restore_thread;
|
||||
restore_task_exec_start = restore_code_start + restorer_blob_offset__restore_task;
|
||||
restore_thread_exec_start = restore_code_start + restorer_blob_offset____export_restore_thread;
|
||||
restore_task_exec_start = restore_code_start + restorer_blob_offset____export_restore_task;
|
||||
task_args = restore_code_start + restore_code_len;
|
||||
thread_args = (void *)((long)task_args + sizeof(*task_args));
|
||||
|
||||
|
@ -7,7 +7,7 @@ NAME=$1
|
||||
INC_GUARD=__${NAME}_h__
|
||||
PREFIX=${NAME}_blob_offset__
|
||||
BLOB=${NAME}_blob
|
||||
OBJNAME=${NAME}.o
|
||||
OBJNAME=${NAME}.bin.o
|
||||
BINARY=${NAME}.bin
|
||||
|
||||
AWK_CMD='$2 ~ /^[tT]$/ { print "#define '$PREFIX'" $3 " 0x" $1; }'
|
||||
@ -19,7 +19,7 @@ cat << EOF
|
||||
|
||||
EOF
|
||||
|
||||
nm $OBJNAME | tr . _ | awk "$AWK_CMD"
|
||||
nm $OBJNAME | grep "__export_" | tr . _ | awk "$AWK_CMD"
|
||||
|
||||
cat << EOF
|
||||
|
||||
|
@ -96,10 +96,10 @@ struct parasite_drain_fd {
|
||||
*/
|
||||
|
||||
#define PARASITE_ARGS_ADDR(start) \
|
||||
((start) + parasite_blob_offset__parasite_args)
|
||||
((start) + parasite_blob_offset____export_parasite_args)
|
||||
#define PARASITE_CMD_ADDR(start) \
|
||||
((start) + parasite_blob_offset__parasite_cmd)
|
||||
((start) + parasite_blob_offset____export_parasite_cmd)
|
||||
#define PARASITE_HEAD_ADDR(start) \
|
||||
((start) + parasite_blob_offset__parasite_head_start)
|
||||
((start) + parasite_blob_offset____export_parasite_head_start)
|
||||
|
||||
#endif /* CR_PARASITE_H_ */
|
||||
|
@ -18,8 +18,8 @@
|
||||
struct task_restore_core_args;
|
||||
struct thread_restore_args;
|
||||
|
||||
extern long restore_task(struct task_restore_core_args *args);
|
||||
extern long restore_thread(struct thread_restore_args *args);
|
||||
extern long __export_restore_task(struct task_restore_core_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 (*thread_restore_fcall_t) (struct thread_restore_args *args);
|
||||
|
16
parasite.c
16
parasite.c
@ -487,29 +487,29 @@ static int __used parasite_service(unsigned long cmd, void *args)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void __head parasite_head(void)
|
||||
static void __head __export_parasite_head(void)
|
||||
{
|
||||
/*
|
||||
* The linker will handle the stack allocation.
|
||||
*/
|
||||
asm volatile("parasite_head_start: \n"
|
||||
"leaq parasite_stack(%rip), %rsp \n"
|
||||
asm volatile("__export_parasite_head_start: \n"
|
||||
"leaq __export_parasite_stack(%rip), %rsp \n"
|
||||
"subq $16, %rsp \n"
|
||||
"andq $~15, %rsp \n"
|
||||
"pushq $0 \n"
|
||||
"movq %rsp, %rbp \n"
|
||||
"movl parasite_cmd(%rip), %edi \n"
|
||||
"leaq parasite_args(%rip), %rsi \n"
|
||||
"movl __export_parasite_cmd(%rip), %edi \n"
|
||||
"leaq __export_parasite_args(%rip), %rsi \n"
|
||||
"call parasite_service \n"
|
||||
"int $0x03 \n"
|
||||
".align 8 \n"
|
||||
"parasite_cmd: \n"
|
||||
"__export_parasite_cmd: \n"
|
||||
".long 0 \n"
|
||||
"parasite_args: \n"
|
||||
"__export_parasite_args: \n"
|
||||
".long 0 \n"
|
||||
".space "__stringify(PARASITE_ARG_SIZE)",0 \n"
|
||||
".space "__stringify(PARASITE_STACK_SIZE)", 0 \n"
|
||||
"parasite_stack: \n"
|
||||
"__export_parasite_stack: \n"
|
||||
".long 0 \n");
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
OUTPUT_FORMAT("binary")
|
||||
OUTPUT_ARCH(i386:x86-64)
|
||||
|
||||
SECTIONS
|
||||
@ -13,8 +12,6 @@ SECTIONS
|
||||
. = ALIGN(32);
|
||||
*(.bss*)
|
||||
. = ALIGN(32);
|
||||
*(.export)
|
||||
. = ALIGN(32);
|
||||
} =0x00000000
|
||||
|
||||
/DISCARD/ : {
|
||||
|
@ -128,7 +128,7 @@ static void restore_creds(struct creds_entry *ce)
|
||||
* Threads restoration via sigreturn. Note it's locked
|
||||
* 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;
|
||||
struct core_entry *core_entry;
|
||||
@ -335,7 +335,7 @@ static u64 restore_mapping(const struct vma_entry *vma_entry)
|
||||
* and jump execution to some predefined ip read from
|
||||
* core file.
|
||||
*/
|
||||
long restore_task(struct task_restore_core_args *args)
|
||||
long __export_restore_task(struct task_restore_core_args *args)
|
||||
{
|
||||
long ret = -1;
|
||||
struct task_entry *task_entry;
|
||||
|
Loading…
x
Reference in New Issue
Block a user