[CRIU] [PATCH 3/5] make: Redesign building of parasite and restorer blobs

Cyrill Gorcunov gorcunov at openvz.org
Tue Mar 27 09:01:40 EDT 2012


In order to make further modifications of parasite
and restorer blobs easier the following is done

 1) Everything related to parasite/restorer is moved
    into separate Makefile.pie because there are special
    rules needed to build this files so escape messing with
    general Makefile

 2) No need to host two lds files which do the same thing,
    just merge them into one pie.lds.S.

 3) Tune up restorer-log.c functions declarations, they
    are not always_inline but merged into built file with
    ld help

 4) Along with .bin files generate correspond .bin.o files
    in debug purpose (one could disassemble them and check
    the contents).

There is no easy way to split this patch because it touches
all parts of building (compiling, linkind, generating deps
and such).

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 Makefile       |   76 ++++++-------------------------------------------------
 Makefile.pie   |   63 ++++++++++++++++++++++++++++++++++++++++++++++
 parasite.lds.S |   19 --------------
 pie.lds.S      |   25 ++++++++++++++++++
 restorer-log.c |   17 ++++--------
 restorer.lds.S |   19 --------------
 6 files changed, 103 insertions(+), 116 deletions(-)
 create mode 100644 Makefile.pie
 delete mode 100644 parasite.lds.S
 create mode 100644 pie.lds.S
 delete mode 100644 restorer.lds.S

diff --git a/Makefile b/Makefile
index 94161f9..33a0682 100644
--- a/Makefile
+++ b/Makefile
@@ -23,11 +23,8 @@ PROGRAM		:= crtools
 
 export CC ECHO MAKE CFLAGS LIBS ARCH DEFINES
 
-OBJS_GEN_DEP	+= parasite-syscall.o
-OBJS_GEN_DEP	+= cr-restore.o
-DEPS_GEN	:= $(patsubst %.o,%.d,$(OBJS_GEN_DEP))
-
-OBJS		+= $(OBJS_GEN_DEP)
+OBJS		+= parasite-syscall.o
+OBJS		+= cr-restore.o
 OBJS		+= crtools.o
 OBJS		+= proc_parse.o
 OBJS		+= cr-dump.o
@@ -47,66 +44,12 @@ OBJS		+= namespaces.o
 OBJS		+= uts_ns.o
 OBJS		+= ipc_ns.o
 
-OBJS-BLOB	+= parasite.o
-SRCS-BLOB	+= $(patsubst %.o,%.c,$(OBJS-BLOB))
-
-HEAD-BLOB-GEN	:= $(patsubst %.o,%-blob.h,$(OBJS-BLOB))
-HEAD-BIN	:= $(patsubst %.o,%.bin,$(OBJS-BLOB))
-HEAD-LDS	:= $(patsubst %.o,%.lds.S,$(OBJS-BLOB))
-
-ROBJS-BLOB	:= restorer.o
-#
-# Everything embedded into restorer as a separate
-# object file should go here.
-ROBJS		:= $(ROBJS-BLOB)
-ROBJS		+= restorer-log.o
-
-RSRCS-BLOB	+= $(patsubst %.o,%.c,$(ROBJS))
-
-RSRCS-BLOB	+= $(patsubst %.o,%.c,$(ROBJS-BLOB))
+DEPS		+= $(patsubst %.o,%.d,$(OBJS))
 
-RHEAD-BLOB-GEN	:= $(patsubst %.o,%-blob.h,$(ROBJS-BLOB))
-RHEAD-BIN	:= $(patsubst %.o,%.bin,$(ROBJS-BLOB))
-RHEAD-LDS	:= $(patsubst %.o,%.lds.S,$(ROBJS-BLOB))
-
-DEPS		:= $(patsubst %.o,%.d,$(OBJS))		\
-       		   $(patsubst %.o,%.d,$(OBJS-BLOB))	\
-		   $(patsubst %.o,%.d,$(ROBJS-BLOB))
-
-GEN-OFFSETS	:= gen-offsets.sh
+-include Makefile.pie
 
 all: $(PROGRAM)
 
-$(OBJS-BLOB): $(SRCS-BLOB)
-	$(E) "  CC      " $@
-	$(Q) $(CC) -c $(CFLAGS) -fpic $< -o $@
-
-parasite-util-net.o: util-net.c
-	$(E) "  CC      " $@
-	$(Q) $(CC) -c $(CFLAGS) -fpic $< -o $@
-
-$(HEAD-BIN): $(HEAD-LDS) $(OBJS-BLOB) parasite-util-net.o
-	$(E) "  GEN     " $@
-	$(Q) $(LD) -T $^ -o $@
-
-$(HEAD-BLOB-GEN): $(HEAD-BIN) $(GEN-OFFSETS)
-	$(E) "  GEN     " $@
-	$(Q) $(SH) $(GEN-OFFSETS) parasite > $@ || rm -f $@
-	$(Q) sync
-
-$(ROBJS): $(RSRCS-BLOB)
-	$(E) "  CC      " $@
-	$(Q) $(CC) -c $(CFLAGS) -fpic $(patsubst %.o,%.c,$@) -o $@
-
-$(RHEAD-BIN): $(ROBJS) $(RHEAD-LDS)
-	$(E) "  GEN     " $@
-	$(Q) $(LD) -T $(patsubst %.bin,%.lds.S,$@) -o $@ $(ROBJS)
-
-$(RHEAD-BLOB-GEN): $(RHEAD-BIN) $(GEN-OFFSETS)
-	$(E) "  GEN     " $@
-	$(Q) $(SH) $(GEN-OFFSETS) restorer > $@ || rm -f $@
-	$(Q) sync
-
 %.o: %.c
 	$(E) "  CC      " $@
 	$(Q) $(CC) -c $(CFLAGS) $< -o $@
@@ -119,12 +62,11 @@ $(RHEAD-BLOB-GEN): $(RHEAD-BIN) $(GEN-OFFSETS)
 	$(E) "  CC      " $@
 	$(Q) $(CC) -S $(CFLAGS) -fverbose-asm $< -o $@
 
-$(PROGRAM): $(OBJS)
+$(PROGRAM): $(OBJS) | $(PIE-GEN)
 	$(E) "  LINK    " $@
 	$(Q) $(CC) $(CFLAGS) $(OBJS) $(LIBS) -o $@
 
-$(DEPS_GEN): $(HEAD-BLOB-GEN) $(RHEAD-BLOB-GEN)
-%.d: %.c
+%.d: %.c | $(PIE-GEN)
 	$(Q) $(CC) -M -MT $(patsubst %.d,%.o,$@) $(CFLAGS) $< -o $@
 
 test-legacy: $(PROGRAM)
@@ -146,7 +88,7 @@ rebuild:
 	$(Q) $(MAKE)
 .PHONY: rebuild
 
-clean:
+clean: cleanpie
 	$(E) "  CLEAN"
 	$(Q) $(RM) -f ./*.o
 	$(Q) $(RM) -f ./*.d
@@ -155,8 +97,6 @@ clean:
 	$(Q) $(RM) -f ./*.out
 	$(Q) $(RM) -f ./*.bin
 	$(Q) $(RM) -f ./$(PROGRAM)
-	$(Q) $(RM) -f ./$(HEAD-BLOB-GEN)
-	$(Q) $(RM) -f ./$(RHEAD-BLOB-GEN)
 	$(Q) $(RM) -rf ./test/dump/
 	$(Q) $(MAKE) -C test/legacy clean
 	$(Q) $(MAKE) -C test/zdtm cleandep
@@ -200,6 +140,8 @@ help:
 	$(E) '      test            - Run zdtm test-suite'
 .PHONY: help
 
+.DEFAULT_GOAL	:= $(PROGRAM)
+
 ifeq ($(filter-out no-deps-targets, $(MAKECMDGOALS)),)
 -include $(DEPS)
 endif
diff --git a/Makefile.pie b/Makefile.pie
new file mode 100644
index 0000000..bfeb2be
--- /dev/null
+++ b/Makefile.pie
@@ -0,0 +1,63 @@
+GEN-OFFSETS	:= gen-offsets.sh
+
+POBJS		+= parasite.o
+PSRCS		+= $(patsubst %.o,%.c,$(POBJS))
+
+PBLOB-NAME	:= parasite
+PBLOB-HDR	:= parasite-blob.h
+PBLOB-BIN	:= parasite.bin
+PBLOB-LDS	:= pie.lds.S
+
+ROBJS		+= restorer.o
+ROBJS		+= restorer-log.o
+RSRCS		+= $(patsubst %.o,%.c,$(ROBJS))
+
+RBLOB-NAME	:= restorer
+RBLOB-HDR	:= restorer-blob.h
+RBLOB-BIN	:= restorer.bin
+RBLOB-LDS	:= pie.lds.S
+
+DEPS		+= $(patsubst %.o,%.d,$(POBJS))
+DEPS		+= $(patsubst %.o,%.d,$(ROBJS))
+
+PIEFLAGS	:= -fpic
+
+$(POBJS): $(PSRCS)
+	$(E) "  CC      " $@
+	$(Q) $(CC) -c $(CFLAGS) $(PIEFLAGS) $(patsubst %.o,%.c,$@) -o $@
+
+parasite-util-net.o: util-net.c
+	$(E) "  CC      " $@
+	$(Q) $(CC) -c $(CFLAGS) $(PIEFLAGS) $< -o $@
+
+POBJS		+= parasite-util-net.o
+
+$(PBLOB-BIN): $(PBLOB-LDS) $(POBJS)
+	$(E) "  GEN     " $@
+	$(Q) $(LD) --oformat=binary -T $(PBLOB-LDS) -o $(PBLOB-BIN) $(POBJS)
+	$(Q) $(LD) --oformat=elf64-x86-64 -T $(PBLOB-LDS) -o $(PBLOB-BIN).o $(POBJS)
+
+$(PBLOB-HDR): $(PBLOB-BIN) $(GEN-OFFSETS)
+	$(E) "  GEN     " $@
+	$(Q) $(SH) $(GEN-OFFSETS) $(PBLOB-NAME) > $@ || rm -f $@
+
+$(ROBJS): $(RSRCS)
+	$(E) "  CC      " $@
+	$(Q) $(CC) -c $(CFLAGS) $(PIEFLAGS) $(patsubst %.o,%.c,$@) -o $@
+
+$(RBLOB-BIN): $(RBLOB-LDS) $(ROBJS)
+	$(E) "  GEN     " $@
+	$(Q) $(LD) --oformat=binary -T $(RBLOB-LDS) -o $(RBLOB-BIN) $(ROBJS)
+	$(Q) $(LD) --oformat=elf64-x86-64 -T $(RBLOB-LDS) -o $(RBLOB-BIN).o $(ROBJS)
+
+$(RBLOB-HDR): $(RBLOB-BIN) $(GEN-OFFSETS)
+	$(E) "  GEN     " $@
+	$(Q) $(SH) $(GEN-OFFSETS) $(RBLOB-NAME) > $@ || rm -f $@
+
+PIE-GEN	:= $(PBLOB-HDR) $(RBLOB-HDR)
+
+cleanpie:
+	$(E) "  CLEAN PIE"
+	$(Q) $(RM) -f ./$(PBLOB-HDR)
+	$(Q) $(RM) -f ./$(RBLOB-HDR)
+.PHONY: cleanpie
diff --git a/parasite.lds.S b/parasite.lds.S
deleted file mode 100644
index 0f3aa32..0000000
--- a/parasite.lds.S
+++ /dev/null
@@ -1,19 +0,0 @@
-OUTPUT_FORMAT("binary")
-OUTPUT_ARCH(i386:x86-64)
-
-SECTIONS
-{
-	. = 0;
-	.text : {
-		*(.parasite.head.text)
-		*(.text)
-		. = ALIGN(8);
-	}
-	.data : {
-		*(.data)
-		*(.rodata)
-		*(.bss)
-		*(.parasite.stack)
-		. = ALIGN(8);
-	}
-}
diff --git a/pie.lds.S b/pie.lds.S
new file mode 100644
index 0000000..55833f6
--- /dev/null
+++ b/pie.lds.S
@@ -0,0 +1,25 @@
+OUTPUT_ARCH(i386:x86-64)
+
+SECTIONS
+{
+	.text 0x0 : {
+		*(.parasite.head.text)
+		*(.text)
+		. = ALIGN(32);
+		*(.data*)
+		. = ALIGN(32);
+		*(.rodata*)
+		. = ALIGN(32);
+		*(.bss*)
+		. = ALIGN(32);
+	} =0x00000000
+
+	/DISCARD/ : {
+		*(.debug*)
+		*(.comment*)
+		*(.note*)
+		*(.group*)
+		*(.eh_frame*)
+		*(*)
+	}
+}
diff --git a/restorer-log.c b/restorer-log.c
index 634513e..41fdf8d 100644
--- a/restorer-log.c
+++ b/restorer-log.c
@@ -16,12 +16,7 @@ void restorer_set_logfd(int fd)
 			c += 'a' - 10;	\
 	} while (0)
 
-static void always_inline write_char(char c)
-{
-	sys_write(logfd, &c, 1);
-}
-
-void always_inline write_string(char *str)
+void write_string(char *str)
 {
 	int len = 0;
 
@@ -31,7 +26,7 @@ void always_inline write_string(char *str)
 	sys_write(logfd, str, len);
 }
 
-void always_inline write_string_n(char *str)
+void write_string_n(char *str)
 {
 	char new_line = '\n';
 
@@ -39,7 +34,7 @@ void always_inline write_string_n(char *str)
 	sys_write(logfd, &new_line, 1);
 }
 
-void always_inline write_num(long num)
+void write_num(long num)
 {
 	unsigned long d = 1000000000000000000;
 	unsigned int started = 0;
@@ -66,7 +61,7 @@ void always_inline write_num(long num)
 	}
 }
 
-void always_inline write_num_n(long num)
+void write_num_n(long num)
 {
 	unsigned char c;
 	write_num(num);
@@ -74,7 +69,7 @@ void always_inline write_num_n(long num)
 	sys_write(logfd, &c, sizeof(c));
 }
 
-long always_inline vprint_num(char *buf, long num)
+long vprint_num(char *buf, long num)
 {
 	unsigned long d = 1000000000000000000;
 	unsigned int started = 0;
@@ -105,7 +100,7 @@ long always_inline vprint_num(char *buf, long num)
 	return i;
 }
 
-void always_inline write_hex_n(unsigned long num)
+void write_hex_n(unsigned long num)
 {
 	unsigned char *s = (unsigned char *)&num;
 	unsigned char c;
diff --git a/restorer.lds.S b/restorer.lds.S
deleted file mode 100644
index 42bd518..0000000
--- a/restorer.lds.S
+++ /dev/null
@@ -1,19 +0,0 @@
-OUTPUT_FORMAT("binary")
-OUTPUT_ARCH(i386:x86-64)
-
-SECTIONS
-{
-	. = 0;
-	.text : {
-		*(.restorer.head.text)
-		*(.text)
-		. = ALIGN(8);
-	}
-	.data : {
-		*(.data)
-		*(.rodata)
-		*(.bss)
-		*(.restorer.stack)
-		. = ALIGN(8);
-	}
-}
-- 
1.7.7.6



More information about the CRIU mailing list