[CRIU] [PATCH 05/20] multiarch: introduced the multiarch support into the build system.
alekskartashov at parallels.com
alekskartashov at parallels.com
Wed Dec 12 08:34:15 EST 2012
From: Alexander Kartashov <alekskartashov at parallels.com>
* The build scripts for x86 are left intact as suggested by Pavel.
* The linker script pie/pie.lds.S is generated from the template
pie/pie.lds.S.in by prepending the output architecture specification.
* The parasite head is compiled while executing the $(ARCH) target.
* 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 | 21 +++++-----
arch/arm/Makefile | 4 +-
arch/arm/gen-syscalls.pl | 104 ++++++++++++++++++++++++++++++++++++++++++++++
arch/arm/syscall.def | 74 +++++++++++++++++++++++++++++++++
arch/x86/Makefile | 4 +-
pie/Makefile | 13 ++++--
pie/pie.lds.S | 25 -----------
7 files changed, 202 insertions(+), 43 deletions(-)
create mode 100755 arch/arm/gen-syscalls.pl
create mode 100644 arch/arm/syscall.def
delete mode 100644 pie/pie.lds.S
diff --git a/Makefile b/Makefile
index 18db408..5012580 100644
--- a/Makefile
+++ b/Makefile
@@ -14,13 +14,11 @@ FIND := find
CSCOPE := cscope
TAGS := ctags
RM := rm
-LD := ld
HEXDUMP := hexdump
-CC := gcc
ECHO := echo
NM := nm
AWK := awk
-SH := sh
+SH := bash
MAKE := make
# Additional ARCH settings for x86
@@ -40,9 +38,12 @@ ifeq ($(uname_M),x86_64)
DEFINES := -DCONFIG_X86_64
endif
+include arch/$(ARCH)/Makefile.inc
+
SRC_DIR ?= $(shell pwd)
+ARCH_DIR := $(SRC_DIR)/arch/$(ARCH)
-CFLAGS = -I$(SRC_DIR)/include -I$(SRC_DIR)/pie -fno-strict-aliasing
+CFLAGS += -I$(SRC_DIR)/include -I$(SRC_DIR)/pie -I$(ARCH_DIR) -fno-strict-aliasing
LIBS := -lrt -lpthread -lprotobuf-c
@@ -70,7 +71,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 ARCH_BITS LDARCH ARCH_DIR
PROGRAM := crtools
@@ -120,7 +121,7 @@ OBJS += tty.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)
all: pie
$(Q) $(MAKE) $(PROGRAM)
@@ -131,8 +132,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 " $@
@@ -152,7 +153,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
@@ -179,7 +180,7 @@ clean:
$(Q) $(RM) -f ./$(PROGRAM)
$(Q) $(RM) -rf ./test/dump/
$(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/arm/Makefile b/arch/arm/Makefile
index 4e1a955..931a532 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -1,4 +1,4 @@
-SYS-DEF := $(SRC_DIR)/include/syscall.def
+SYS-DEF := $(ARCH_DIR)/syscall.def
SYS-ASM-COMMON := syscall-common.S
SYS-TYPES := $(SRC_DIR)/include/syscall-types.h
@@ -6,7 +6,7 @@ SYS-CODES := $(SRC_DIR)/include/syscall-codes.h
SYS-PROTO := $(SRC_DIR)/include/syscall.h
SYS-ASM := syscalls.S
-SYS-GEN := $(SRC_DIR)/gen-syscalls.pl
+SYS-GEN := $(ARCH_DIR)/gen-syscalls.pl
SYS-OBJ := syscalls.o
diff --git a/arch/arm/gen-syscalls.pl b/arch/arm/gen-syscalls.pl
new file mode 100755
index 0000000..3745161
--- /dev/null
+++ b/arch/arm/gen-syscalls.pl
@@ -0,0 +1,104 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+my $in = $ARGV[0];
+my $codesout = $ARGV[1];
+my $codes = $ARGV[1] =~ s/.*include\///gr;
+my $protosout = $ARGV[2];
+my $protos = $ARGV[2] =~ s/.*include\///gr;
+my $asmout = $ARGV[3];
+my $asmcommon = $ARGV[4];
+my $prototypes = $ARGV[5] =~ s/.*include\///gr;
+my $bits = $ARGV[6];
+
+my $codesdef = $codes =~ tr/.-/_/r;
+my $protosdef = $protos =~ tr/.-/_/r;
+my $code = "code$bits";
+my $need_aux = 0;
+
+unlink $codesout;
+unlink $protosout;
+unlink $asmout;
+
+open CODESOUT, ">", $codesout or die $!;
+open PROTOSOUT, ">", $protosout or die $!;
+open ASMOUT, ">", $asmout or die $!;
+open IN, "<", $in or die $!;
+
+print CODESOUT <<"END";
+/* Autogenerated, don't edit */
+#ifndef $codesdef
+#define $codesdef
+END
+
+print PROTOSOUT <<"END";
+/* Autogenerated, don't edit */
+#ifndef $protosdef
+#define $protosdef
+#include "$prototypes"
+#include "$codes"
+END
+
+print ASMOUT <<"END";
+/* Autogenerated, don't edit */
+#include "$codes"
+#include "$asmcommon"
+END
+
+
+for (<IN>) {
+ if ($_ =~ /\#/) {
+ next;
+ }
+
+ my $code_macro;
+ my $sys_name;
+
+ if (/(?<name>\S+)\s+(?<alias>\S+)\s+(?<code64>\d+)\s+(?<code32>(?:\d+|\!))\s+\((?<args>.+)\)/) {
+ $code_macro = "__NR_$+{name}";
+ $sys_name = "sys_$+{alias}";
+ } elsif (/(?<name>\S+)\s+(?<code64>\d+)\s+(?<code32>(?:\d+|\!))\s+\((?<args>.+)\)/) {
+ $code_macro = "__NR_$+{name}";
+ $sys_name = "sys_$+{name}";
+ } else {
+ unlink $codesout;
+ unlink $protosout;
+ unlink $asmout;
+
+ die "Invalid syscall definition file: invalid entry $_\n";
+ }
+
+ if ($+{$code} ne "!") {
+ print CODESOUT "#define $code_macro $+{$code}\n";
+
+ my $nargs;
+
+ if ($+{args} eq "void") {
+ $nargs = 0;
+ } else {
+ my $tmp = $+{args};
+ $nargs = 1 + ($tmp =~ tr/\,/\,/);
+
+ if ($nargs <= 4) {
+ $nargs = 0;
+ }
+ }
+
+ print ASMOUT "syscall$nargs $sys_name, $code_macro\n";
+
+ } else {
+ $need_aux = 1;
+ }
+
+ print PROTOSOUT "extern long $sys_name($+{args});\n";
+}
+
+if ($need_aux == 1) {
+ print ASMOUT "#include <syscall-aux.S>\n";
+ print CODESOUT "#include <syscall-aux.h>\n";
+}
+
+print CODESOUT "#endif /* $codesdef */";
+print PROTOSOUT "#endif /* $protosdef */";
diff --git a/arch/arm/syscall.def b/arch/arm/syscall.def
new file mode 100644
index 0000000..9e397a8
--- /dev/null
+++ b/arch/arm/syscall.def
@@ -0,0 +1,74 @@
+#
+# System calls table, please make sure the table consist only the syscalls
+# really used somewhere in project.
+#
+# The template is (name and arguments are optinal if you need only __NR_x
+# defined, but no realy entry point in syscalls lib).
+#
+# name/alias code code32 arguments
+# -----------------------------------------------------------------------
+#
+read 0 3 (int fd, void *buf, unsigned long count)
+write 1 4 (int fd, const void *buf, unsigned long count)
+open 2 5 (const char *filename, unsigned long flags, unsigned long mode)
+close 3 6 (int fd)
+lseek 8 19 (int fd, unsigned long offset, unsigned long origin)
+mmap 9 ! (void *addr, unsigned long len, unsigned long prot, unsigned long flags, unsigned long fd, unsigned long offset)
+mprotect 10 125 (const void *addr, unsigned long len, unsigned long prot)
+munmap 11 91 (void *addr, unsigned long len)
+brk 12 45 (void *addr)
+rt_sigaction sigaction 13 174 (int signum, const rt_sigaction_t *act, rt_sigaction_t *oldact, size_t sigsetsize)
+rt_sigprocmask sigprocmask 14 175 (int how, k_rtsigset_t *set, k_rtsigset_t *old, size_t sigsetsize)
+rt_sigreturn 15 173 (void)
+mincore 27 219 (void *addr, unsigned long size, unsigned char *vec)
+ioctl 16 54 (unsigned int fd, unsigned int cmd, unsigned long arg)
+mremap 25 163 (unsigned long addr, unsigned long old_len, unsigned long new_len, unsigned long flag, unsigned long new_addr)
+madvise 28 220 (unsigned long start, size_t len, int behavior)
+shmat 30 305 (int shmid, void *shmaddr, int shmflag)
+pause 34 29 (void)
+nanosleep 35 162 (struct timespec *req, struct timespec *rem)
+getitimer 36 105 (int which, const struct itimerval *val)
+setitimer 38 104 (int which, const struct itimerval *val, struct itimerval *old)
+getpid 39 20 (void)
+socket 41 281 (int domain, int type, int protocol)
+connect 42 283 (int sockfd, struct sockaddr *addr, int addrlen)
+sendmsg 46 296 (int sockfd, const struct msghdr *msg, int flags)
+recvmsg 47 297 (int sockfd, struct msghdr *msg, int flags)
+bind 49 282 (int sockfd, const struct sockaddr *addr, int addrlen)
+setsockopt 54 294 (int sockfd, int level, int optname, const void *optval, socklen_t optlen)
+getsockopt 55 295 (int sockfd, int level, int optname, const void *optval, socklen_t *optlen)
+clone 56 120 (unsigned long flags, void *child_stack, void *parent_tid, void *child_tid)
+exit 60 1 (unsigned long error_code)
+wait4 61 114 (int pid, int *status, int options, struct rusage *ru)
+kill 62 37 (long pid, int sig)
+fcntl 72 55 (int fd, int type, long arg)
+flock 73 143 (int fd, unsigned long cmd)
+mkdir 83 39 (const char *name, int mode)
+rmdir 84 40 (const char *name)
+unlink 87 10 (char *pathname)
+readlink 89 85 (const char *path, char *buf, int bufsize)
+getgroups 115 205 (int gsize, unsigned int *groups)
+setresuid 117 164 (int uid, int euid, int suid)
+setresgid 119 170 (int gid, int egid, int sgid)
+getpgid 121 132 (pid_t pid)
+setfsuid 122 138 (int fsuid)
+setfsgid 123 139 (int fsgid)
+getsid 124 147 (void)
+capset 126 185 (struct cap_header *h, struct cap_data *d)
+setpriority 141 97 (int which, int who, int nice)
+sched_setscheduler 144 156 (int pid, int policy, struct sched_param *p)
+personality 135 136 (unsigned int personality)
+prctl 157 172 (int option, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5)
+arch_prctl 158 17 (int option, unsigned long addr)
+mount 165 21 (char *dev_nmae, char *dir_name, char *type, unsigned long flags, void *data)
+umount2 166 52 (char *name, int flags)
+gettid 186 224 (void)
+futex 202 240 (u32 *uaddr, int op, u32 val, struct timespec *utime, u32 *uaddr2, u32 val3)
+set_tid_address 218 256 (int *tid_addr)
+restart_syscall 219 0 (void)
+exit_group 231 248 (int error_code)
+set_robust_list 273 338 (struct robust_list_head *head, size_t len)
+get_robust_list 274 339 (int pid, struct robust_list_head **head_ptr, size_t *len_ptr)
+open_by_handle_at 304 371 (int mountdirfd, struct file_handle *handle, int flags)
+setns 308 375 (int fd, int nstype)
+kcmp 312 7 (pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2)
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index d81e0f7..e08398a 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
@@ -29,7 +29,7 @@ $(SYS-ASM): $(SYS-GEN) $(SYS-DEF) $(SYS-ASM-COMMON) $(SYS-TYPES)
$(E) " CC " $@
$(Q) $(CC) $(CFLAGS) $^ -o $@
-x86: $(SYS-OBJ)
+x86: $(SYS-OBJ) parasite-head.o
clean:
$(E) " CLEAN SYSCALLS"
diff --git a/pie/Makefile b/pie/Makefile
index efb7532..e678429 100644
--- a/pie/Makefile
+++ b/pie/Makefile
@@ -3,7 +3,7 @@ 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
PARASITE += parasite.bin.o parasite.bin
RESTORER := restorer.bin.o restorer.bin
@@ -18,6 +18,10 @@ LIB-OBJS = log-simple.o blob-util-net.o $(SYSCALL-LIB)
$(PARASITE): $(LIB-OBJS) $(PASM-OBJS) $(PIELDS)
$(RESTORER): $(LIB-OBJS) $(PIELDS)
+$(PIELDS): $(PIELDS).in
+ $(SH) -c "echo 'OUTPUT_ARCH($(LDARCH))' > $(PIELDS)"
+ $(SH) -c "cat $(PIELDS).in >> $(PIELDS)"
+
blob-util-net.o: $(SRC_DIR)/util-net.c
$(E) " CC " $@
$(Q) $(CC) $(CFLAGS) $< -o $@
@@ -32,11 +36,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 +55,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
deleted file mode 100644
index 4055af7..0000000
--- a/pie/pie.lds.S
+++ /dev/null
@@ -1,25 +0,0 @@
-OUTPUT_ARCH(i386:x86-64)
-
-SECTIONS
-{
- .crblob 0x0 : {
- *(.head.text)
- *(.text)
- . = ALIGN(32);
- *(.data*)
- . = ALIGN(32);
- *(.rodata*)
- . = ALIGN(32);
- *(.bss*)
- . = ALIGN(32);
- } =0x00000000
-
- /DISCARD/ : {
- *(.debug*)
- *(.comment*)
- *(.note*)
- *(.group*)
- *(.eh_frame*)
- *(*)
- }
-}
--
1.7.9.5
More information about the CRIU
mailing list