Skip to content

Commit

Permalink
x86/build: generate syscalls-{64,32}.built-in.o
Browse files Browse the repository at this point in the history
After uncommenting FIXME:
It will add sc_exec_table_32 for compatible tasks to sys-exec-tbl.c

Now it does:
 - add two different 32/64 syscall tables for cr-exec
   sys-exec-tbl-{64,32}.
 - add two different syscall headers syscall-{64,32}.h,
   that are included from more x86 generic syscall.h depending
   on -DCONFIG_X86_{32,64} option.
 - builds two different syscalls-{32,64}.built-in.o
 - for criu core files, that need SYS_memfd_create and other
   SYS_* __NR_* defines (currently kerndat.c and shmem.c),
   create simple syscall-codes.h that includes syscall-codes-64.h
   [Added after rebase on master]

That way after apply, the compatible patch set will be simply
able to bisect for regressions.

Signed-off-by: Dmitry Safonov <[email protected]>
Acked-by: Cyrill Gorcunov <[email protected]>
Signed-off-by: Pavel Emelyanov <[email protected]>
Signed-off-by: Andrei Vagin <[email protected]>
  • Loading branch information
0x7f454c46 authored and avagin committed Mar 14, 2017
1 parent 0aa355e commit bbc2f13
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 64 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ images/google/protobuf/*.c
images/google/protobuf/*.h
.gitid
criu/criu
criu/arch/*/sys-exec-tbl.c
criu/arch/*/syscalls.S
criu/arch/*/sys-exec-tbl*.c
criu/arch/*/syscalls*.S
criu/include/config.h
criu/include/syscall-codes.h
criu/include/syscall.h
criu/include/syscall-codes*.h
criu/include/syscall*.h
soccr/config.h
criu/include/version.h
criu/pie/restorer-blob.h
Expand Down
5 changes: 5 additions & 0 deletions criu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ include $(SRC_DIR)/criu/Makefile.packages

#
# System calls library.
ifeq ($(ARCH),x86)
# Do not need 32-bit compatible syscall lib compiled in criu
SYSCALL-LIB := $(ARCH_DIR)/syscalls-64.built-in.o
else
SYSCALL-LIB := $(ARCH_DIR)/syscalls.built-in.o
endif
syscalls_lib:
$(Q) $(MAKE) $(call build-as,Makefile.syscalls,$(ARCH_DIR)) all
.PHONY: syscalls_lib
Expand Down
3 changes: 3 additions & 0 deletions criu/arch/ppc64/Makefile.syscalls
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ SYS-EXEC-TBL := sys-exec-tbl.c
$(obj)/$(SYS-EXEC-TBL): $(obj)/syscalls/$(SYS-DEF) $(obj)/$(SYS-CODES) $(obj)/$(SYS-PROTO)
$(E) " GEN " $@
$(Q) echo "/* Autogenerated, don't edit */" > $@
$(Q) echo "static struct syscall_exec_desc sc_exec_table[] = {" >> $@
$(Q) cat $< | awk '/^__NR/{print "SYSCALL(", substr($$3, 5), ",", $$2, ")"}' >> $@
$(Q) echo " { }, /* terminator */" >> $@
$(Q) echo "};" >> $@
mrproper-y += $(obj)/$(SYS-EXEC-TBL)
all-y += $(obj)/$(SYS-EXEC-TBL)
4 changes: 4 additions & 0 deletions criu/arch/scripts/arm/gen-sys-exec-tbl.pl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
open IN, "<", $in or die $!;

print TBLOUT "/* Autogenerated, don't edit */\n";
print TBLOUT "static struct syscall_exec_desc sc_exec_table[] = {\n";

for (<IN>) {
if ($_ =~ /\#/) {
Expand All @@ -37,3 +38,6 @@
print TBLOUT "SYSCALL($sys_name, $sys_num)\n";
}
}

print TBLOUT " { }, /* terminator */";
print TBLOUT "};"
217 changes: 162 additions & 55 deletions criu/arch/x86/Makefile.syscalls
Original file line number Diff line number Diff line change
@@ -1,71 +1,178 @@
include $(__nmk_dir)msg.mk
builtin-name := syscalls.built-in.o

CFLAGS := $(filter-out -pg $(CFLAGS-GCOV),$(CFLAGS))
CFLAGS := $(filter-out -DCONFIG_X86_64,$(CFLAGS))

SYS-TYPES := ../../include/syscall-types.h
SYS-CODES := ../../include/syscall-codes.h
SYS-PROTO := ../../include/syscall.h
SYS-PROTO-GENERIC := $(obj)/../../include/syscall.h
SYS-EXEC-TBL-GENERIC := sys-exec-tbl.c

SYS-CODES-GENERIC = $(obj)/../../include/syscall-codes.h
SYS-CODES = $(obj)/../../include/syscall-codes-$(1).h
SYS-PROTO = $(obj)/../../include/syscall-$(1).h
SYS-DEF = $(obj)/syscalls/syscall_$(1).tbl
SYS-ASM = syscalls-$(1).S
SYS-ASM-COMMON = syscall-common-x86-$(1).S
SYS-EXEC-TBL = $(obj)/sys-exec-tbl-$(1).c

target :=
target_32 := syscalls-32
target_64 := syscalls-64

SYS-BITS := 32

# native x86_64
ifeq ($(ARCH),x86)
SYS-DEF := syscall_64.tbl
SYS-ASM-COMMON := syscall-common-x86-64.S
asflags-y += -fpie -Wstrict-prototypes -Wa,--noexecstack
else
SYS-DEF := syscall_32.tbl
SYS-ASM-COMMON := syscall-common-x86-32.S
asflags-y += -fno-pic -Wstrict-prototypes -Wa,--noexecstack
obj-y += syscalls/syscall32.o

$(obj)/syscalls/syscall32.o: $(obj)/$(SYS-CODES) $(obj)/$(SYS-PROTO)
SYS-BITS += 64
endif

# targets
define gen-targets
target += $(target_$(1))
endef

$(eval $(call map,gen-targets,$(SYS-BITS)))

# AFLAGS, LDFLAGS
asflags-y += -Wstrict-prototypes -Wa,--noexecstack
asflags-y += -D__ASSEMBLY__ -nostdlib -fomit-frame-pointer
asflags-y += -iquote $(obj) -iquote $(obj)/include -iquote $(SRC_DIR)/criu/include
asflags-y += -iquote $(obj) -iquote $(obj)/include
asflags-y += -iquote $(SRC_DIR)/criu/include

SYS-ASM := syscalls.S
obj-y += $(SYS-ASM:.S=).o
AFLAGS_$(target_32) += -fno-pic -m32
AFLAGS_$(target_64) += -fpie
LDFLAGS_$(target_32) += -m elf_i386

$(obj)/$(SYS-CODES): $(obj)/syscalls/$(SYS-DEF)
$(call msg-gen, $@)
$(Q) echo "/* Autogenerated, don't edit */" > $@
$(Q) echo "#ifndef __ASM_CR_SYSCALL_CODES_H__" >> $@
$(Q) echo "#define __ASM_CR_SYSCALL_CODES_H__" >> $@
$(Q) cat $< | awk '/^__NR/{SYSN=$$1; sub("^__NR", "SYS", SYSN);'\
'print "\n#ifndef ", $$1, "\n#define", $$1, $$2, "\n#endif";'\
'print "#ifndef ", SYSN, "\n#define ", SYSN, $$1, "\n#endif"}' >> $@
$(Q) echo "#endif /* __ASM_CR_SYSCALL_CODES_H__ */" >> $@
mrproper-y += $(obj)/$(SYS-CODES)

$(obj)/$(SYS-PROTO): $(obj)/syscalls/$(SYS-DEF)
$(call msg-gen, $@)
$(Q) echo "/* Autogenerated, don't edit */" > $@
$(Q) echo "#ifndef __ASM_CR_SYSCALL_PROTO_H__" >> $@
$(Q) echo "#define __ASM_CR_SYSCALL_PROTO_H__" >> $@
$(Q) echo "#ifndef CR_NOGLIBC" >> $@
$(Q) echo "# error This file should only be used in the parasite code" >> $@
$(Q) echo "#endif" >> $@
$(Q) echo "#include \"syscall-codes.h\"" >> $@
$(Q) echo "#include \"syscall-types.h\"" >> $@
ifneq ($(ARCH),x86)
$(Q) echo "#include \"asm/syscall32.h\"" >> $@
$(target_32)-obj-y += syscalls/syscall32.o
$(obj)/syscalls/syscall32.d: $(obj)/../../include/syscall-codes-32.h \
$(obj)/../../include/syscall-32.h

CFLAGS_syscall32.o += -fno-pic -m32 -DCR_NOGLIBC -DCONFIG_X86_32
CFLAGS_syscall32.d += -fno-pic -m32 -DCR_NOGLIBC -DCONFIG_X86_32
cleanup-y += $(obj)/syscalls/syscall32.o

# Here are rules for 32/64-bit platforms. For compat mode we need both
# 32 and 64 bit syscalls, so generate the rules with SYS-BIT being
# $1 parameter in all gen-rule-*

# awk variable should be escaped twice
AV := $$$$

define gen-rule-sys-codes
$(SYS-CODES): $(SYS-DEF)
$(call msg-gen, $$@)
$(Q) echo "/* Autogenerated, don't edit */" > $$@
$(Q) echo "#ifndef __ASM_CR_SYSCALL_CODES_H_$(1)__" >> $$@
$(Q) echo "#define __ASM_CR_SYSCALL_CODES_H_$(1)__" >> $$@
$(Q) cat $$< | awk '/^__NR/{SYSN=$(AV)1; \
sub("^__NR", "SYS", SYSN); \
print "\n#ifndef ", $(AV)1; \
print "#define", $(AV)1, $(AV)2; \
print "#endif"; \
print "\n#ifndef ", SYSN; \
print "#define ", SYSN, $(AV)1; \
print "#endif";}' >> $$@
$(Q) echo "#endif /* __ASM_CR_SYSCALL_CODES_H_$(1)__ */" >> $$@
mrproper-y += $(SYS-CODES)
endef

define gen-rule-sys-proto
$(SYS-PROTO): $(SYS-DEF)
$(call msg-gen, $$@)
$(Q) echo "/* Autogenerated, don't edit */" > $$@
$(Q) echo "#ifndef __ASM_CR_SYSCALL_PROTO_H_$(1)__" >> $$@
$(Q) echo "#define __ASM_CR_SYSCALL_PROTO_H_$(1)__" >> $$@
$(Q) echo "#ifndef CR_NOGLIBC" >> $$@
$(Q) echo "# error This file should only be used in the parasite code" \
>> $$@
$(Q) echo "#endif" >> $$@
$(Q) echo '#include "syscall-codes-$(1).h"' >> $$@
$(Q) echo '#include "syscall-types.h"' >> $$@
ifeq ($(1),32)
$(Q) echo '#include "asm/syscall32.h"' >> $$@
endif
$(Q) cat $< | awk '/^__NR/{print "extern long", $$3, substr($$0, index($$0,$$4)), ";"}' >> $@
$(Q) echo "#endif /* __ASM_CR_SYSCALL_PROTO_H__ */" >> $@
mrproper-y += $(obj)/$(SYS-PROTO)
$(Q) cat $$< | awk '/^__NR/{print "extern long", $(AV)3, \
substr($(AV)0, index($(AV)0,$(AV)4)), ";"}' >> $$@
$(Q) echo "#endif /* __ASM_CR_SYSCALL_PROTO_H_$(1)__ */" >> $$@
mrproper-y += $(SYS-PROTO)
endef

$(obj)/$(SYS-ASM): $(obj)/syscalls/$(SYS-DEF) $(obj)/syscalls/$(SYS-ASM-COMMON) $(obj)/$(SYS-CODES) $(obj)/$(SYS-PROTO)
$(call msg-gen, $@)
$(Q) echo "/* Autogenerated, don't edit */" > $@
$(Q) echo "#include \"syscall-codes.h\"" >> $@
$(Q) echo "#include \"syscalls/$(SYS-ASM-COMMON)\"" >> $@
$(Q) cat $< | awk '/^__NR/{print "SYSCALL(", $$3, ",", $$2, ")"}' >> $@
define gen-rule-sys-asm
$(obj)/$(SYS-ASM): $(SYS-DEF) $(obj)/syscalls/$(SYS-ASM-COMMON) \
$(SYS-CODES) $(SYS-PROTO)
$(call msg-gen, $$@)
$(Q) echo "/* Autogenerated, don't edit */" > $$@
$(Q) echo '#include "syscall-codes-$(1).h"' >> $$@
$(Q) echo '#include "syscalls/$(SYS-ASM-COMMON)"' >> $$@
$(Q) cat $$< | awk '/^__NR/{print "SYSCALL(", $(AV)3, ",", $(AV)2, ")"}'\
>> $$@
mrproper-y += $(obj)/$(SYS-ASM)
$(target_$(1))-obj-y += $(SYS-ASM:.S=).o
endef

# for 32-bit $(SYS-ASM)
AFLAGS_syscalls-32.o += -fno-pic -m32

define gen-rule-sys-exec-tbl
$(SYS-EXEC-TBL): $(SYS-DEF) $(SYS-CODES) $(SYS-PROTO) $(SYS-PROTO-GENERIC)
$(call msg-gen, $$@)
$(Q) echo "/* Autogenerated, don't edit */" > $$@
$(Q) cat $$< | awk '/^__NR/{print \
"SYSCALL(", substr($(AV)3, 5), ",", $(AV)2, ")"}' >> $$@
mrproper-y += $(SYS-EXEC-TBL)
all-y += $(SYS-EXEC-TBL)
endef

# Some parts of criu need SYS_memfd_create and other ifndef/define syscalls
# Use 64-bit, native syscalls as-is, add __NR32_*/SYS32_* defines
# to generic file
$(SYS-CODES-GENERIC): $(obj)/syscalls/syscall_32.tbl
$(call msg-gen, $@)
$(Q) echo "/* Autogenerated, don't edit */" > $@
$(Q) echo "#ifndef __ASM_CR_SYSCALL_CODES_H__" >> $@
$(Q) echo "#define __ASM_CR_SYSCALL_CODES_H__" >> $@
$(Q) echo '#include "syscall-codes-64.h"' >> $@
$(Q) cat $< | awk '/^__NR/{NR32=$$1; \
sub("^__NR", "__NR32", NR32); \
print "\n#ifndef ", NR32; \
print "#define ", NR32, $$2; \
print "#endif";}' >> $@
$(Q) echo "#endif /* __ASM_CR_SYSCALL_CODES_H__ */" >> $@
mrproper-y += $(SYS-CODES-GENERIC)
all-y += $(SYS-CODES-GENERIC)

SYS-EXEC-TBL := sys-exec-tbl.c
$(obj)/$(SYS-EXEC-TBL): $(obj)/syscalls/$(SYS-DEF) $(obj)/$(SYS-CODES) $(obj)/$(SYS-PROTO)
$(SYS-PROTO-GENERIC): $(strip $(call map,SYS-PROTO,$(SYS-BITS)))
$(call msg-gen, $@)
$(Q) echo "/* Autogenerated, don't edit */" > $@
$(Q) cat $< | awk '/^__NR/{print "SYSCALL(", substr($$3, 5), ",", $$2, ")"}' >> $@
mrproper-y += $(obj)/$(SYS-EXEC-TBL)
all-y += $(obj)/$(SYS-EXEC-TBL)
$(Q) echo "/* Autogenerated, don't edit */" > $@
$(Q) echo "#ifndef __ASM_CR_SYSCALL_PROTO_H__" >> $@
$(Q) echo "#define __ASM_CR_SYSCALL_PROTO_H__" >> $@
$(Q) echo "" >> $@
$(Q) echo "#ifdef CONFIG_X86_32" >> $@
$(Q) echo '#include "syscall-32.h"' >> $@
$(Q) echo "#else" >> $@
$(Q) echo '#include "syscall-64.h"' >> $@
$(Q) echo "#endif /* CONFIG_X86_32 */" >> $@
$(Q) echo "" >> $@
$(Q) echo "#endif /* __ASM_CR_SYSCALL_PROTO_H__ */" >> $@
mrproper-y += $(SYS-PROTO-GENERIC)

$(obj)/$(SYS-EXEC-TBL-GENERIC):
$(Q) echo "/* Autogenerated, don't edit */" > $@
$(Q) echo "static struct syscall_exec_desc sc_exec_table[] = {" >> $@
ifeq ($(ARCH),x86)
$(Q) echo '#include "sys-exec-tbl-64.c"' >> $@
$(Q) echo " { }, /* terminator */" >> $@
$(Q) echo "};" >> $@
$(Q) echo "" >> $@
# FIXME: uncomment to support 32-bit task
# $(Q) echo "static struct syscall_exec_desc sc_exec_table_32[] = {" >> $@
endif
# $(Q) echo '#include "sys-exec-tbl-32.c"' >> $@
# $(Q) echo " { }, /* terminator */" >> $@
# $(Q) echo "};" >> $@
mrproper-y += $(obj)/$(SYS-EXEC-TBL-GENERIC)
all-y += $(obj)/$(SYS-EXEC-TBL-GENERIC)

$(eval $(call map,gen-rule-sys-codes,$(SYS-BITS)))
$(eval $(call map,gen-rule-sys-proto,$(SYS-BITS)))
$(eval $(call map,gen-rule-sys-asm,$(SYS-BITS)))
$(eval $(call map,gen-rule-sys-exec-tbl,$(SYS-BITS)))
2 changes: 1 addition & 1 deletion criu/arch/x86/syscalls/syscall32.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "asm/types.h"
#include "syscall.h"
#include "syscall-32.h"

#define SYS_SOCKET 1 /* sys_socket(2) */
#define SYS_BIND 2 /* sys_bind(2) */
Expand Down
3 changes: 0 additions & 3 deletions criu/cr-exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ struct syscall_exec_desc {
unsigned nr;
};

static struct syscall_exec_desc sc_exec_table[] = {
#define SYSCALL(__name, __nr) { .name = #__name, .nr = __nr, },
#include "sys-exec-tbl.c"
#undef SYSCALL
{ }, /* terminator */
};

static struct syscall_exec_desc *find_syscall(char *name)
{
Expand Down
9 changes: 8 additions & 1 deletion criu/pie/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ target += restorer

parasite-obj-y += parasite.o
parasite-obj-y += ./$(ARCH_DIR)/parasite-head.o
parasite-obj-e += ./$(ARCH_DIR)/syscalls.built-in.o

restorer-obj-y += restorer.o
restorer-obj-y += ./$(ARCH_DIR)/restorer.o

ifeq ($(ARCH),x86)
# FIXME: depend on 32/64 pie type
parasite-obj-e += ./$(ARCH_DIR)/syscalls-64.built-in.o
restorer-obj-e += ./$(ARCH_DIR)/syscalls-64.built-in.o
else
parasite-obj-e += ./$(ARCH_DIR)/syscalls.built-in.o
restorer-obj-e += ./$(ARCH_DIR)/syscalls.built-in.o
endif

#
# We can't provide proper mount implementation
Expand Down

0 comments on commit bbc2f13

Please sign in to comment.