[CRIU] [PATCH 8/9] compel: make plugins .a archives
Kir Kolyshkin
kir at openvz.org
Fri Mar 24 15:07:45 PDT 2017
The objective is to only do parasite code linking once -- when we link
parasite objects with compel plugin(s). So, let's use ar (rather than
ld) here. This way we'll have a single ld invocation with the proper
flags (from compel ldflags) etc.
There are two tricks in doing it:
1. The order of objects while linking is important. Therefore, compel
plugins should be the last to add to ld command line.
2. Somehow ld doesn't want to include parasite-head.o in the output
(probably because no one else references it), so we have to force
it in with the modification to our linker scripts.
NB: compel makefiles are still a big mess, but I'll get there.
Signed-off-by: Kir Kolyshkin <kir at openvz.org>
---
Makefile.compel | 8 +++---
compel/arch/aarch64/scripts/compel-pack.lds.S | 4 +++
.../arm/plugins/std/syscalls/Makefile.syscalls | 2 +-
compel/arch/arm/scripts/compel-pack.lds.S | 4 +++
.../ppc64/plugins/std/syscalls/Makefile.syscalls | 2 +-
compel/arch/ppc64/scripts/compel-pack.lds.S | 4 +++
.../x86/plugins/std/syscalls/Makefile.syscalls | 2 +-
compel/arch/x86/scripts/compel-pack-compat.lds.S | 4 +++
compel/arch/x86/scripts/compel-pack.lds.S | 4 +++
compel/plugins/Makefile | 30 +++++++++++-----------
compel/src/main.c | 8 +++---
11 files changed, 47 insertions(+), 25 deletions(-)
diff --git a/Makefile.compel b/Makefile.compel
index 5012435..1ef7f8c 100644
--- a/Makefile.compel
+++ b/Makefile.compel
@@ -22,7 +22,7 @@ compel-deps += compel/include/asm
compel-deps += $(COMPEL_VERSION_HEADER)
compel-deps += $(CONFIG_HEADER)
compel-deps += include/common/asm
-compel-plugins += compel/plugins/std.built-in.o compel/plugins/fds.built-in.o
+compel-plugins += compel/plugins/std.lib.a compel/plugins/fds.lib.a
LIBCOMPEL_SO := libcompel.so
LIBCOMPEL_A := libcompel.a
@@ -47,13 +47,13 @@ compel/plugins/%: $(compel-deps) .FORCE
# GNU make 4.x supports targets matching via wide
# match targeting, where GNU make 3.x series (used on
# Travis) is not, so we have to write them here explicitly.
-compel/plugins/std.built-in.o: $(compel-deps) .FORCE
+compel/plugins/std.lib.a: $(compel-deps) .FORCE
$(Q) $(MAKE) $(build)=compel/plugins $@
-compel/plugins/shmem.built-in.o: $(compel-deps) compel/plugins/std.built-in.o .FORCE
+compel/plugins/shmem.lib.a: $(compel-deps) compel/plugins/std.lib.a .FORCE
$(Q) $(MAKE) $(build)=compel/plugins $@
-compel/plugins/fds.built-in.o: $(compel-deps) compel/plugins/std.built-in.o .FORCE
+compel/plugins/fds.lib.a: $(compel-deps) compel/plugins/std.lib.a .FORCE
$(Q) $(MAKE) $(build)=compel/plugins $@
compel/compel: compel/built-in.o compel/$(LIBCOMPEL_A) | $(compel-deps)
diff --git a/compel/arch/aarch64/scripts/compel-pack.lds.S b/compel/arch/aarch64/scripts/compel-pack.lds.S
index b07e68c..eba89cd 100644
--- a/compel/arch/aarch64/scripts/compel-pack.lds.S
+++ b/compel/arch/aarch64/scripts/compel-pack.lds.S
@@ -1,8 +1,12 @@
OUTPUT_ARCH(aarch64)
+EXTERN(__export_parasite_head_start)
+
SECTIONS
{
.crblob 0x0 : {
*(.head.text)
+ ASSERT(DEFINED(__export_parasite_head_start),
+ "Symbol __export_parasite_head_start is missing");
*(.text*)
. = ALIGN(32);
*(.data*)
diff --git a/compel/arch/arm/plugins/std/syscalls/Makefile.syscalls b/compel/arch/arm/plugins/std/syscalls/Makefile.syscalls
index 6be8cac..5695b86 100644
--- a/compel/arch/arm/plugins/std/syscalls/Makefile.syscalls
+++ b/compel/arch/arm/plugins/std/syscalls/Makefile.syscalls
@@ -15,7 +15,7 @@ sys-gen := $(PLUGIN_ARCH_DIR)/std/syscalls/gen-syscalls.pl
sys-gen-tbl := $(PLUGIN_ARCH_DIR)/std/syscalls/gen-sys-exec-tbl.pl
sys-asm := ./$(PLUGIN_ARCH_DIR)/std/syscalls/syscalls.S
-std-obj-y += $(sys-asm:.S=).o
+std-lib-y += $(sys-asm:.S=).o
ifeq ($(ARCH),arm)
arch_bits := 32
diff --git a/compel/arch/arm/scripts/compel-pack.lds.S b/compel/arch/arm/scripts/compel-pack.lds.S
index fe40278..f8a4739 100644
--- a/compel/arch/arm/scripts/compel-pack.lds.S
+++ b/compel/arch/arm/scripts/compel-pack.lds.S
@@ -1,8 +1,12 @@
OUTPUT_ARCH(arm)
+EXTERN(__export_parasite_head_start)
+
SECTIONS
{
.crblob 0x0 : {
*(.head.text)
+ ASSERT(DEFINED(__export_parasite_head_start),
+ "Symbol __export_parasite_head_start is missing");
*(.text*)
. = ALIGN(32);
*(.data*)
diff --git a/compel/arch/ppc64/plugins/std/syscalls/Makefile.syscalls b/compel/arch/ppc64/plugins/std/syscalls/Makefile.syscalls
index 3a0d172..c0c22bf 100644
--- a/compel/arch/ppc64/plugins/std/syscalls/Makefile.syscalls
+++ b/compel/arch/ppc64/plugins/std/syscalls/Makefile.syscalls
@@ -12,7 +12,7 @@ sys-asm-types := $(obj)/include/uapi/std/asm/syscall-types.h
sys-exec-tbl = $(PLUGIN_ARCH_DIR)/std/sys-exec-tbl.c
sys-asm := ./$(PLUGIN_ARCH_DIR)/std/syscalls/syscalls.S
-std-obj-y += $(sys-asm:.S=).o
+std-lib-y += $(sys-asm:.S=).o
$(sys-codes): $(sys-def)
$(E) " GEN " $@
diff --git a/compel/arch/ppc64/scripts/compel-pack.lds.S b/compel/arch/ppc64/scripts/compel-pack.lds.S
index 5da9a08..e0f826d 100644
--- a/compel/arch/ppc64/scripts/compel-pack.lds.S
+++ b/compel/arch/ppc64/scripts/compel-pack.lds.S
@@ -1,8 +1,12 @@
OUTPUT_ARCH(powerpc:common64)
+EXTERN(__export_parasite_head_start)
+
SECTIONS
{
.text : {
*(.head.text)
+ ASSERT(DEFINED(__export_parasite_head_start),
+ "Symbol __export_parasite_head_start is missing");
*(.text*)
*(.compel.exit)
*(.compel.init)
diff --git a/compel/arch/x86/plugins/std/syscalls/Makefile.syscalls b/compel/arch/x86/plugins/std/syscalls/Makefile.syscalls
index 522ee89..4ba4b56 100644
--- a/compel/arch/x86/plugins/std/syscalls/Makefile.syscalls
+++ b/compel/arch/x86/plugins/std/syscalls/Makefile.syscalls
@@ -1,4 +1,4 @@
-std-obj-y += ./$(PLUGIN_ARCH_DIR)/std/syscalls-64.o
+std-lib-y += ./$(PLUGIN_ARCH_DIR)/std/syscalls-64.o
sys-proto-types := $(obj)/include/uapi/std/syscall-types.h
sys-proto-generic := $(obj)/include/uapi/std/syscall.h
diff --git a/compel/arch/x86/scripts/compel-pack-compat.lds.S b/compel/arch/x86/scripts/compel-pack-compat.lds.S
index 67adf96..ff9c2c6 100644
--- a/compel/arch/x86/scripts/compel-pack-compat.lds.S
+++ b/compel/arch/x86/scripts/compel-pack-compat.lds.S
@@ -1,9 +1,13 @@
OUTPUT_ARCH(i386)
TARGET(elf32-i386)
+EXTERN(__export_parasite_head_start)
+
SECTIONS
{
.text : {
*(.head.text)
+ ASSERT(DEFINED(__export_parasite_head_start),
+ "Symbol __export_parasite_head_start is missing");
*(.text*)
*(.compel.exit)
*(.compel.init)
diff --git a/compel/arch/x86/scripts/compel-pack.lds.S b/compel/arch/x86/scripts/compel-pack.lds.S
index cd6584f..0c936f8 100644
--- a/compel/arch/x86/scripts/compel-pack.lds.S
+++ b/compel/arch/x86/scripts/compel-pack.lds.S
@@ -1,9 +1,13 @@
OUTPUT_ARCH(i386:x86-64)
TARGET(elf64-x86-64)
+EXTERN(__export_parasite_head_start)
+
SECTIONS
{
.text : {
*(.head.text)
+ ASSERT(DEFINED(__export_parasite_head_start),
+ "Symbol __export_parasite_head_start is missing");
*(.text*)
*(.compel.exit)
*(.compel.init)
diff --git a/compel/plugins/Makefile b/compel/plugins/Makefile
index e834a05..7127425 100644
--- a/compel/plugins/Makefile
+++ b/compel/plugins/Makefile
@@ -34,30 +34,30 @@ ldflags-y += -z noexecstack
#
# Shmem plugin
target += shmem
-shmem-obj-y += shmem/shmem.o
+shmem-lib-y += shmem/shmem.o
#
# STD plugin
target += std
-std-obj-y += std/std.o
-std-obj-y += std/fds.o
-std-obj-y += std/log.o
-std-obj-y += std/string.o
-std-obj-y += std/infect.o
-std-obj-y += ./$(PLUGIN_ARCH_DIR)/std/parasite-head.o
+std-lib-y += std/std.o
+std-lib-y += std/fds.o
+std-lib-y += std/log.o
+std-lib-y += std/string.o
+std-lib-y += std/infect.o
+std-lib-y += ./$(PLUGIN_ARCH_DIR)/std/parasite-head.o
#
# FDS plugin
target += fds
-fds-obj-y += fds/fds.o
+fds-lib-y += fds/fds.o
ifeq ($(SRCARCH),x86)
- std-obj-y += ./$(PLUGIN_ARCH_DIR)/std/memcpy.o
+ std-lib-y += ./$(PLUGIN_ARCH_DIR)/std/memcpy.o
endif
ifeq ($(SRCARCH),ppc64)
- std-obj-y += ./$(PLUGIN_ARCH_DIR)/std/memcpy.o
- std-obj-y += ./$(PLUGIN_ARCH_DIR)/std/memcmp.o
+ std-lib-y += ./$(PLUGIN_ARCH_DIR)/std/memcpy.o
+ std-lib-y += ./$(PLUGIN_ARCH_DIR)/std/memcmp.o
endif
include ./$(PLUGIN_ARCH_DIR)/std/syscalls/Makefile.syscalls
@@ -73,15 +73,15 @@ endef
# Almost all plugins depen on syscall headers
# and definitions so we have to order their
# generation manually.
-$(foreach t,$(target),$(eval $(call syscall-priority,$(t)-obj-y,std-headers-deps)))
+$(foreach t,$(target),$(eval $(call syscall-priority,$(t)-lib-y,std-headers-deps)))
#
# FIXME syscall-types.h should be setup earlier
#
-install: compel/plugins/std.built-in.o
+install: compel/plugins/std.lib.a compel/plugins/fds.lib.a
$(E) " INSTALL " compel plugins
$(Q) mkdir -p $(DESTDIR)$(LIBEXECDIR)/compel/
- $(Q) install -m 0644 compel/plugins/std.built-in.o $(DESTDIR)$(LIBEXECDIR)/compel/
+ $(Q) install -m 0644 $^ $(DESTDIR)$(LIBEXECDIR)/compel/
$(Q) mkdir -p $(DESTDIR)$(LIBEXECDIR)/compel/scripts
$(Q) install -m 0644 compel/arch/$(ARCH)/scripts/compel-pack.lds.S $(DESTDIR)$(LIBEXECDIR)/compel/scripts
$(E) " INSTALL " compel plugins uapi
@@ -91,7 +91,7 @@ install: compel/plugins/std.built-in.o
uninstall:
$(E) " UNINSTALL" compel plugins
- $(Q) $(RM) $(addprefix $(DESTDIR)$(LIBEXECDIR)/compel/,std.built-in.o)
+ $(Q) $(RM) $(addprefix $(DESTDIR)$(LIBEXECDIR)/compel/,*.lib.a)
$(Q) $(RM) $(addprefix $(DESTDIR)$(LIBEXECDIR)/compel/scripts/,compel-pack.lds.S)
$(E) " UNINSTALL" compel and plugins uapi
$(Q) $(RM) -rf $(addprefix $(DESTDIR)$(INCLUDEDIR)/,compel/plugins)
diff --git a/compel/src/main.c b/compel/src/main.c
index ea3da89..e0dcb09 100644
--- a/compel/src/main.c
+++ b/compel/src/main.c
@@ -186,12 +186,14 @@ static void print_ldflags(bool compat)
static void print_plugins(const char *list[])
{
+ const char suffix[] = ".lib.a";
+
while (*list != NULL) {
if (uninst_root)
- printf("%s/plugins/%s.built-in.o\n",
- uninst_root, *list);
+ printf("%s/plugins/%s%s\n",
+ uninst_root, *list, suffix);
else
- printf("%s/compel/%s.built-in.o\n", LIBEXECDIR, *list);
+ printf("%s/compel/%s%s\n", LIBEXECDIR, *list, suffix);
list++;
}
}
--
2.9.3
More information about the CRIU
mailing list