[CRIU] [PATCH 02/22] multiarch: introduced the multiarch support into the build system.

Alexander Kartashov alekskartashov at parallels.com
Thu Dec 27 01:50:53 EST 2012


* The build scripts for x86 are left intact as suggested by Pavel.

* Replaced the shell interpreter with bash to run the script
  test/zdtm.sh corretly.

* The linker script pie/pie.lds.S is generated from the template
  pie/pie.lds.S.in by prepending the output architecture specification.
  The output architecture is defined by the variable LDARCH.

* Blobs are generated by objcopy instead of ld because the ARM linker
  fails to produce a binary when supplied a script.
  (See http://lists.gnu.org/archive/html/bug-binutils/2008-10/msg00091.html).

Signed-off-by: Alexander Kartashov <alekskartashov at parallels.com>
---
 Makefile                        |   20 ++++++++++++--------
 arch/x86/Makefile               |    3 ++-
 pie/Makefile                    |   17 ++++++++++++-----
 pie/{pie.lds.S => pie.lds.S.in} |    2 --
 4 files changed, 26 insertions(+), 16 deletions(-)
 rename pie/{pie.lds.S => pie.lds.S.in} (91%)

diff --git a/Makefile b/Makefile
index 6f0d479..623722d 100644
--- a/Makefile
+++ b/Makefile
@@ -20,8 +20,9 @@ CC		:= gcc
 ECHO		:= echo
 NM		:= nm
 AWK		:= awk
-SH		:= sh
+SH		:= bash
 MAKE		:= make
+OBJCOPY		:= objcopy
 
 # Additional ARCH settings for x86
 ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
@@ -38,11 +39,13 @@ endif
 ifeq ($(uname_M),x86_64)
 	ARCH         := x86
 	DEFINES      := -DCONFIG_X86_64
+	LDARCH       := i386:x86-64
 endif
 
 SRC_DIR		?= $(shell pwd)
+ARCH_DIR	:= $(SRC_DIR)/arch/$(ARCH)
 
-CFLAGS		= -I$(SRC_DIR)/include -I$(SRC_DIR)/pie -I$(SRC_DIR)/arch/$(ARCH)/ -fno-strict-aliasing
+CFLAGS		+= -I$(SRC_DIR)/include -I$(SRC_DIR)/pie -I$(ARCH_DIR) -iquote $(ARCH_DIR)/include -fno-strict-aliasing
 
 LIBS		:= -lrt -lpthread -lprotobuf-c
 
@@ -70,7 +73,7 @@ CFLAGS		+= $(WARNINGS) $(DEFINES)
 SYSCALL-LIB	= $(SRC_DIR)/arch/$(ARCH)/syscalls.o
 PROTOBUF-LIB	= $(SRC_DIR)/protobuf/protobuf-lib.o
 
-export E Q CC ECHO MAKE CFLAGS LIBS ARCH DEFINES MAKEFLAGS SRC_DIR SYSCALL-LIB SH
+export E Q CC ECHO MAKE CFLAGS LIBS ARCH DEFINES MAKEFLAGS SRC_DIR SYSCALL-LIB SH OBJCOPY LDARCH ARCH_DIR
 
 
 PROGRAM		:= crtools
@@ -118,11 +121,12 @@ OBJS		+= protobuf.o
 OBJS		+= tty.o
 OBJS		+= cr-exec.o
 OBJS		+= cpu.o
+OBJS		+= $(ARCH_DIR)/crtools.o
 
 DEPS		:= $(patsubst %.o,%.d,$(OBJS))
 
 .PHONY: all zdtm test rebuild clean distclean tags cscope	\
-	docs help pie protobuf x86
+	docs help pie protobuf $(ARCH)
 
 ifeq ($(GCOV),1)
 %.o $(PROGRAM): override CFLAGS += --coverage
@@ -137,8 +141,8 @@ pie: protobuf $(ARCH)
 protobuf:
 	$(Q) $(MAKE) -C protobuf/
 
-x86:
-	$(Q) $(MAKE) -C arch/x86/
+$(ARCH):
+	$(Q) $(MAKE) -C arch/$(ARCH)/
 
 %.o: %.c
 	$(E) "  CC      " $@
@@ -158,7 +162,7 @@ x86:
 
 $(PROGRAM): $(OBJS) $(SYSCALL-LIB) $(PROTOBUF-LIB)
 	$(E) "  LINK    " $@
-	$(Q) $(CC) $(CFLAGS) $^ $(LIBS) -o $@
+	$(Q) $(CC) $(CFLAGS) $(LINKFLAGS) $^ $(LIBS) -o $@
 
 zdtm: all
 	$(Q) $(MAKE) -C test/zdtm all
@@ -187,7 +191,7 @@ clean:
 	$(Q) $(RM) -f ./*.gcov ./*.gcda ./*.gcno
 	$(Q) $(RM) -rf ./gcov
 	$(Q) $(MAKE) -C protobuf/ clean
-	$(Q) $(MAKE) -C arch/x86/ clean
+	$(Q) $(MAKE) -C arch/$(ARCH)/ clean
 	$(Q) $(MAKE) -C pie/ clean
 	$(Q) $(MAKE) -C test/zdtm cleandep
 	$(Q) $(MAKE) -C test/zdtm clean
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index c0108a1..3e8df60 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -1,4 +1,4 @@
-SYS-DEF		:= $(SRC_DIR)/include/syscall-x86-64.def
+SYS-DEF		:= $(ARCH_DIR)/syscall-x86-64.def
 SYS-ASM-COMMON	:= syscall-common-x86-64.S
 SYS-TYPES	:= $(SRC_DIR)/include/syscall-types.h
 
@@ -47,5 +47,6 @@ clean:
 	$(Q) $(RM) -f $(SYS-PROTO)
 	$(Q) $(RM) -f $(SYS-OBJ)
 	$(Q) $(RM) -f $(SYS-EXEC-TBL)
+	$(Q) $(RM) -f *.o *.d
 
 .PHONY: clean x86
diff --git a/pie/Makefile b/pie/Makefile
index efb7532..c77c847 100644
--- a/pie/Makefile
+++ b/pie/Makefile
@@ -3,7 +3,8 @@ CFLAGS		+=  -fpie  -Wa,--noexecstack -fno-strict-aliasing
 
 GEN-OFFSETS	:= gen-offsets.sh
 
-PASM-OBJS	+= parasite-head-x86-64.o
+PASM-OBJS	+= $(ARCH_DIR)/parasite-head.o
+RESTORER-ARCH-OBJS := $(ARCH_DIR)/restorer.o
 
 PARASITE	+= parasite.bin.o parasite.bin
 RESTORER	:= restorer.bin.o restorer.bin
@@ -16,7 +17,12 @@ ASMFLAGS	:= -D__ASSEMBLY__
 LIB-OBJS	= log-simple.o blob-util-net.o $(SYSCALL-LIB)
 
 $(PARASITE): $(LIB-OBJS) $(PASM-OBJS) $(PIELDS)
-$(RESTORER): $(LIB-OBJS) $(PIELDS)
+$(RESTORER): $(LIB-OBJS) $(RESTORER-ARCH-OBJS) $(PIELDS)
+
+$(PIELDS): $(PIELDS).in
+	$(E) "  GEN     " $@
+	$(Q) $(SH) -c "echo 'OUTPUT_ARCH($(LDARCH))' > $(PIELDS)"
+	$(Q) $(SH) -c "cat $(PIELDS).in >> $(PIELDS)"
 
 blob-util-net.o: $(SRC_DIR)/util-net.c
 	$(E) "  CC      " $@
@@ -32,11 +38,11 @@ blob-util-net.o: $(SRC_DIR)/util-net.c
 
 %.bin.o: %.o
 	$(E) "  GEN     " $@
-	$(Q) $(LD) --oformat=elf64-x86-64 -T $(PIELDS) -o $@ $(^:$(PIELDS)=)
+	$(Q) $(LD) -T $(PIELDS) -o $@ $(^:$(PIELDS)=)
 
-%.bin: %.o
+%.bin: %.bin.o
 	$(E) "  GEN     " $@
-	$(Q) $(LD) --oformat=binary -T $(PIELDS) -o $@ $(^:$(PIELDS)=)
+	$(Q) $(OBJCOPY) -O binary $< $@
 
 %-blob.h: %.bin %.bin.o $(GEN-OFFSETS)
 	$(E) "  GEN     " $@
@@ -51,6 +57,7 @@ clean:
 	$(Q) $(RM) -f ./*.d
 	$(Q) $(RM) -f ./*.bin
 	$(Q) $(RM) -f ./*.bin.o
+	$(Q) $(RM) -f $(PIELDS)
 
 .PHONY: clean pie
 .SECONDARY:
diff --git a/pie/pie.lds.S b/pie/pie.lds.S.in
similarity index 91%
rename from pie/pie.lds.S
rename to pie/pie.lds.S.in
index 1b62941..29fef54 100644
--- a/pie/pie.lds.S
+++ b/pie/pie.lds.S.in
@@ -1,5 +1,3 @@
-OUTPUT_ARCH(i386:x86-64)
-
 SECTIONS
 {
 	.crblob 0x0 : {
-- 
1.7.10.4



More information about the CRIU mailing list