[CRIU] [PATCH 2/2] x86: ia32 -- Add needed bits to be compilable for x86-32
Cyrill Gorcunov
gorcunov at openvz.org
Mon Apr 13 13:10:41 PDT 2015
This is a big commit which can't be split (well it can of course
but not much because things are coupled so I keep them all in one
place). The idea is to at least be able to complile CRIU in 32bit
mode.
Note once compiled it will *not* work simply because not all code
aspects are implemented but rather stubs put in.
Now some details
- I use x86-64 environment for development so as result need
to pass at least -m32 to compiler so it would generate 32bit
code. For this sake one can run build proceudre as
ARCH=ia32 make
for native 32bit kernel this should not be needed, plain "make"
is enought.
Also note that 32bit version of libraries are needed (including
libc, protobuf and such);
- Same time linker needs "-m elf_i386" argument so @ldflags-y variable
introduced in make engine;
- In a few places we use %lx for printing u64 objects, 'cause it's
x86 only code and we're not that interested in high bits at the
moment I put explicit @long type conversion;
- And a huge number of ifdef CONFIG_X86_64: most of assembler code
now commented out simply because I've not yet implemented it,
vdso code is a stub as well.
Anyway both builds (x86-32 and x86-64) pass well so consider merging.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
Makefile | 19 ++++++++++++++++++-
arch/x86/Makefile | 2 +-
arch/x86/crtools.c | 10 +++++++---
arch/x86/include/asm/restore.h | 10 +++++++++-
arch/x86/include/asm/restorer.h | 23 ++++++++++++++++++++++-
arch/x86/include/asm/types.h | 10 +++++++---
arch/x86/parasite-head.S | 9 +++++++++
arch/x86/restorer.c | 3 ++-
arch/x86/vdso-pie.c | 30 ++++++++++++++++++++++++++++++
pie/Makefile | 8 +++++++-
protobuf/Makefile | 4 ++--
scripts/Makefile.build | 4 ++--
12 files changed, 116 insertions(+), 16 deletions(-)
diff --git a/Makefile b/Makefile
index 6e6efb290823..71398f73494a 100644
--- a/Makefile
+++ b/Makefile
@@ -51,6 +51,8 @@ ifeq ($(ARCH),i386)
SRCARCH := x86-32
DEFINES := -DCONFIG_X86_32
VDSO := y
+ PROTOUFIX := y
+ export PROTOUFIX
endif
ifeq ($(ARCH),x86_64)
SRCARCH := x86
@@ -58,6 +60,16 @@ ifeq ($(ARCH),x86_64)
LDARCH := i386:x86-64
VDSO := y
endif
+ifeq ($(ARCH),ia32)
+ SRCARCH := x86
+ DEFINES := -DCONFIG_X86_32
+ LDARCH := i386
+ ldflags-y += -m elf_i386
+ VDSO := y
+ USERCFLAGS += -m32
+ PROTOUFIX := y
+ export PROTOUFIX ldflags-y
+endif
ifeq ($(shell echo $(ARCH) | sed -e 's/arm.*/arm/'),arm)
ARMV := $(shell echo $(ARCH) | sed -nr 's/armv([[:digit:]]).*/\1/p; t; i7')
@@ -78,6 +90,11 @@ ifeq ($(ARCH),aarch64)
VDSO := y
endif
+ifeq ($(SRCARCH),arm)
+ PROTOUFIX := y
+ export PROTOUFIX
+endif
+
SRCARCH ?= $(ARCH)
LDARCH ?= $(SRCARCH)
@@ -197,7 +214,7 @@ $(SYSCALL-LIB) $(ARCH-LIB) $(PROGRAM-BUILTINS): config
$(PROGRAM): $(SYSCALL-LIB) $(ARCH-LIB) $(PROGRAM-BUILTINS)
$(E) " LINK " $@
- $(Q) $(CC) $(CFLAGS) $^ $(LIBS) $(LDFLAGS) $(GMONLDOPT) -rdynamic -o $@
+ $(Q) $(CC) $(CFLAGS) $^ $(LIBS) $(GMONLDOPT) -rdynamic -o $@
crit:
$(Q) $(MAKE) -C pycriu all
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 6f7eb132168d..35ad6d2db836 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -29,7 +29,7 @@ syscalls-asm-y-asmflags := -Wstrict-prototypes -Wa,--noexecstack
endif
syscalls-asm-y-asmflags += -nostdlib -fomit-frame-pointer -I$(obj)
-ifeq ($(ARCH),i386)
+ifneq ($(filter i386 ia32,$(ARCH)),)
syscalls-obj-y += syscalls/syscall32.o
$(obj)/syscalls/syscall32.o: $(obj)/$(SYS-CODES) $(obj)/$(SYS-PROTO)
endif
diff --git a/arch/x86/crtools.c b/arch/x86/crtools.c
index 02ce2e5bc2ce..f5bc371206c6 100644
--- a/arch/x86/crtools.c
+++ b/arch/x86/crtools.c
@@ -361,9 +361,9 @@ static void show_rt_xsave_frame(struct xsave_struct *x)
(int)i387->fop, (int)i387->mxcsr, (int)i387->mxcsr_mask);
pr_debug("magic1:%x extended_size:%x xstate_bv:%lx xstate_size:%x\n",
- fpx->magic1, fpx->extended_size, fpx->xstate_bv, fpx->xstate_size);
+ fpx->magic1, fpx->extended_size, (long)fpx->xstate_bv, fpx->xstate_size);
- pr_debug("xstate_bv: %lx\n", xsave_hdr->xstate_bv);
+ pr_debug("xstate_bv: %lx\n", (long)xsave_hdr->xstate_bv);
pr_debug("-----------------------\n");
}
@@ -443,8 +443,12 @@ void *mmap_seized(struct parasite_ctl *ctl,
unsigned long map;
int err;
+#ifdef CONFIG_X86_64
err = syscall_seized(ctl, __NR_mmap, &map,
- (unsigned long)addr, length, prot, flags, fd, offset);
+#else
+ err = syscall_seized(ctl, __NR_mmap2, &map,
+#endif
+ (unsigned long)addr, length, prot, flags, fd, offset);
if (err < 0 || map > TASK_SIZE)
map = 0;
diff --git a/arch/x86/include/asm/restore.h b/arch/x86/include/asm/restore.h
index 7c39e0060e34..5747f4ed4d98 100644
--- a/arch/x86/include/asm/restore.h
+++ b/arch/x86/include/asm/restore.h
@@ -5,6 +5,7 @@
#include "protobuf/core.pb-c.h"
+#ifdef CONFIG_X86_64
#define JUMP_TO_RESTORER_BLOB(new_sp, restore_task_exec_start, \
task_args) \
asm volatile( \
@@ -18,7 +19,14 @@
"g"(restore_task_exec_start), \
"g"(task_args) \
: "rsp", "rdi", "rsi", "rbx", "rax", "memory")
-
+#else /* CONFIG_X86_64 */
+#define JUMP_TO_RESTORER_BLOB(new_sp, restore_task_exec_start, \
+ task_args) \
+ (void)new_sp; \
+ (void)restore_task_exec_start; \
+ (void)task_args; \
+ ;
+#endif /* CONFIG_X86_64 */
#define core_get_tls(pcore, ptls)
diff --git a/arch/x86/include/asm/restorer.h b/arch/x86/include/asm/restorer.h
index c04fb9426799..4e457dad52a3 100644
--- a/arch/x86/include/asm/restorer.h
+++ b/arch/x86/include/asm/restorer.h
@@ -72,7 +72,7 @@ struct rt_sigframe {
fpu_state_t fpu_state;
};
-
+#ifdef CONFIG_X86_64
#define ARCH_RT_SIGRETURN(new_sp) \
asm volatile( \
"movq %0, %%rax \n" \
@@ -129,6 +129,27 @@ struct rt_sigframe {
: \
: "r"(ret) \
: "memory")
+#else /* CONFIG_X86_64 */
+#define ARCH_RT_SIGRETURN(new_sp) \
+ ;
+#define RUN_CLONE_RESTORE_FN(ret, clone_flags, new_sp, parent_tid, \
+ thread_args, clone_restore_fn) \
+ (void)ret; \
+ (void)clone_flags; \
+ (void)new_sp; \
+ (void)parent_tid; \
+ (void)thread_args; \
+ (void)clone_restore_fn; \
+ ;
+#define ARCH_FAIL_CORE_RESTORE \
+ asm volatile( \
+ "movl %0, %%esp \n" \
+ "xorl %%eax, %%eax \n" \
+ "jmp *%%rax \n" \
+ : \
+ : "r"(ret) \
+ : "memory")
+#endif /* CONFIG_X86_64 */
#define RT_SIGFRAME_UC(rt_sigframe) rt_sigframe->uc
#define RT_SIGFRAME_REGIP(rt_sigframe) (rt_sigframe)->uc.uc_mcontext.rip
diff --git a/arch/x86/include/asm/types.h b/arch/x86/include/asm/types.h
index d7e869a50a4c..7d33a613ca08 100644
--- a/arch/x86/include/asm/types.h
+++ b/arch/x86/include/asm/types.h
@@ -109,7 +109,11 @@ typedef struct {
#define ASSIGN_TYPED(a, b) do { a = (typeof(a))b; } while (0)
#define ASSIGN_MEMBER(a,b,m) do { ASSIGN_TYPED((a)->m, (b)->m); } while (0)
-#define TASK_SIZE ((1UL << 47) - PAGE_SIZE)
+#ifdef CONFIG_X86_64
+# define TASK_SIZE ((1UL << 47) - PAGE_SIZE)
+#else
+# define TASK_SIZE (0xc0000000ul)
+#endif
typedef u64 auxv_t;
typedef u32 tls_t;
@@ -126,7 +130,7 @@ typedef u32 tls_t;
typedef UserX86RegsEntry UserRegsEntry;
-static inline u64 encode_pointer(void *p) { return (u64)p; }
-static inline void *decode_pointer(u64 v) { return (void*)v; }
+static inline u64 encode_pointer(void *p) { return (u64)(long)p; }
+static inline void *decode_pointer(u64 v) { return (void *)(long)v; }
#endif /* __CR_ASM_TYPES_H__ */
diff --git a/arch/x86/parasite-head.S b/arch/x86/parasite-head.S
index 8caf9b3b9172..1d8c4adbd168 100644
--- a/arch/x86/parasite-head.S
+++ b/arch/x86/parasite-head.S
@@ -2,6 +2,8 @@
#include "parasite.h"
.section .head.text, "ax"
+
+#ifdef CONFIG_X86_64
ENTRY(__export_parasite_head_start)
subq $16, %rsp
andq $~15, %rsp
@@ -15,3 +17,10 @@ ENTRY(__export_parasite_head_start)
__export_parasite_cmd:
.long 0
END(__export_parasite_head_start)
+#else /* CONFIG_X86_64 */
+ENTRY(__export_parasite_head_start)
+ .align 8
+__export_parasite_cmd:
+ .long 0
+END(__export_parasite_head_start)
+#endif /* CONFIG_X86_64 */
diff --git a/arch/x86/restorer.c b/arch/x86/restorer.c
index 8dc5ac452ce9..364b156be91e 100644
--- a/arch/x86/restorer.c
+++ b/arch/x86/restorer.c
@@ -11,6 +11,7 @@
int restore_nonsigframe_gpregs(UserX86RegsEntry *r)
{
+#ifdef CONFIG_X86_64
long ret;
unsigned long fsgs_base;
@@ -27,6 +28,6 @@ int restore_nonsigframe_gpregs(UserX86RegsEntry *r)
pr_info("SET_GS fail %ld\n", ret);
return -1;
}
-
+#endif
return 0;
}
diff --git a/arch/x86/vdso-pie.c b/arch/x86/vdso-pie.c
index da86a5bc6b77..313c2ec4dcaa 100644
--- a/arch/x86/vdso-pie.c
+++ b/arch/x86/vdso-pie.c
@@ -26,6 +26,8 @@
#endif
#define LOG_PREFIX "vdso: "
+#ifdef CONFIG_X86_64
+
typedef struct {
u16 movabs;
u64 imm64;
@@ -438,3 +440,31 @@ int vdso_proxify(char *who, struct vdso_symtable *sym_rt,
sys_mprotect((void *)vdso_rt_parked_at, vdso_vma_size(sym_rt), VDSO_PROT);
return 0;
}
+
+#else /* CONFIG_X86_64 */
+
+int vdso_redirect_calls(void *base_to, void *base_from,
+ struct vdso_symtable *to,
+ struct vdso_symtable *from)
+{
+ return 0;
+}
+
+int vdso_fill_symtable(char *mem, size_t size, struct vdso_symtable *t)
+{
+ return 0;
+}
+
+int vdso_do_park(struct vdso_symtable *sym_rt, unsigned long park_at, unsigned long park_size)
+{
+ return 0;
+}
+
+int vdso_proxify(char *who, struct vdso_symtable *sym_rt,
+ unsigned long vdso_rt_parked_at, size_t index,
+ VmaEntry *vmas, size_t nr_vmas)
+{
+ return 0;
+}
+
+#endif /* CONFIG_X86_64 */
diff --git a/pie/Makefile b/pie/Makefile
index 3e0b3a7a25cd..7ed7b1665be9 100644
--- a/pie/Makefile
+++ b/pie/Makefile
@@ -28,10 +28,16 @@ restorer-libs-e += $(SYSCALL-LIB)
#
CFLAGS := $(filter-out -pg,$(CFLAGS))
+ifneq ($(filter-out i386 ia32, $(ARCH)),)
cflags-y += -DCR_NOGLIBC -fpie -Wa,--noexecstack -fno-stack-protector
+else
+cflags-y += -DCR_NOGLIBC -Wa,--noexecstack -fno-stack-protector
+endif
+
ifeq ($(SRCARCH), arm)
cflags-y += -marm
endif
+
ASMFLAGS += -D__ASSEMBLY__
GEN-OFFSETS := ../scripts/gen-offsets.sh
@@ -48,7 +54,7 @@ $(obj)/$(PIELDS): $(obj)/$(PIELDS).in
$(obj)/%.built-in.bin.o: $(obj)/%.built-in.o $(obj)/$(PIELDS)
$(E) " GEN " $@
- $(Q) $(LD) -T $(obj)/$(PIELDS) -o $@ $<
+ $(Q) $(LD) $(ldflags-y) -T $(obj)/$(PIELDS) -o $@ $<
$(obj)/%.built-in.bin: $(obj)/%.built-in.bin.o
$(E) " GEN " $@
diff --git a/protobuf/Makefile b/protobuf/Makefile
index 3cb44862e043..d4e177462d11 100644
--- a/protobuf/Makefile
+++ b/protobuf/Makefile
@@ -74,7 +74,7 @@ define gen-proto-rules
$(obj)/$(1).pb-c.c $(obj)/$(1).pb-c.h: $(obj)/$(1).proto $(addsuffix .pb-c.c,$(addprefix $(obj)/,$(2)))
$$(E) " PBCC " $$@
$$(Q) protoc-c --proto_path=$(obj)/ --c_out=$(obj)/ $$<
-ifeq ($(SRCARCH),arm)
+ifeq ($(PROTOUFIX),y)
$$(Q) sed -i -e 's/4294967295/0xFFFFFFFF/g' $$@
$$(Q) sed -i -e 's/4294967295/0xFFFFFFFF/g' $$(patsubst %.c,%.h,$$@)
$$(Q) sed -i -e 's/4294967295/0xFFFFFFFF/g' $$(patsubst %.h,%.c,$$@)
@@ -95,7 +95,7 @@ $(obj)/%.o: $(obj)/%.pb-c.c $(obj)/%.pb-c.h
$(obj)/built-in.o: $(addprefix $(obj)/,$(proto-obj-y))
$(E) " LINK " $@
- $(Q) $(LD) -r -o $@ $^
+ $(Q) $(LD) $(ldflags-y) -r -o $@ $^
_all += $(obj)/built-in.o
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index ad0b24587de1..177d09669f7f 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -172,7 +172,7 @@ $(1)-all-objs += $(all-objs)
$$(obj)/$(1).built-in.o: $$($(1)-all-objs) $$($(1)-libs-e) $(libs-e)
$$(E) " LINK " $$@
- $$(Q) $$(LD) -r -o $$@ $$^
+ $$(Q) $$(LD) $$(ldflags-y) -r -o $$@ $$^
_all += $$(obj)/$(1).built-in.o
cleanup-y += $$(obj)/$(1).built-in.o
@@ -193,7 +193,7 @@ ifeq ($(targets),)
ifneq ($(all-objs),)
$(obj)/built-in.o: $(all-objs) $(libs-e)
$(E) " LINK " $@
- $(Q) $(LD) -r -o $@ $^
+ $(Q) $(LD) $(ldflags-y) -r -o $@ $^
_all += $(obj)/built-in.o
cleanup-y += $(obj)/built-in.o
--
1.9.3
More information about the CRIU
mailing list