[CRIU] [PATCH 2/5] make: Generate offsets from linked files only

Cyrill Gorcunov gorcunov at openvz.org
Wed Apr 18 07:44:45 EDT 2012


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 at openvz.org>
---
 Makefile           |    6 ++++--
 cr-restore.c       |    4 ++--
 gen-offsets.sh     |    4 ++--
 include/parasite.h |    6 +++---
 include/restorer.h |    4 ++--
 parasite.c         |   16 ++++++++--------
 pie.lds.S          |    3 ---
 restorer.c         |    4 ++--
 8 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/Makefile b/Makefile
index aa2f801..0a6df29 100644
--- a/Makefile
+++ b/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     " $@
diff --git a/cr-restore.c b/cr-restore.c
index 5faacda..2fa36cf 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1229,8 +1229,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));
 
diff --git a/gen-offsets.sh b/gen-offsets.sh
index 545b6d7..cc5c6fd 100644
--- a/gen-offsets.sh
+++ b/gen-offsets.sh
@@ -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
 
diff --git a/include/parasite.h b/include/parasite.h
index 0bd01b5..038fb5c 100644
--- a/include/parasite.h
+++ b/include/parasite.h
@@ -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_ */
diff --git a/include/restorer.h b/include/restorer.h
index cbb6a28..4a75763 100644
--- a/include/restorer.h
+++ b/include/restorer.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);
diff --git a/parasite.c b/parasite.c
index 60169ee..1af4c98 100644
--- a/parasite.c
+++ b/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");
 }
 
diff --git a/pie.lds.S b/pie.lds.S
index 3cd9840..4055af7 100644
--- a/pie.lds.S
+++ b/pie.lds.S
@@ -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/ : {
diff --git a/restorer.c b/restorer.c
index b408574..7af708d 100644
--- a/restorer.c
+++ b/restorer.c
@@ -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;
-- 
1.7.7.6



More information about the CRIU mailing list