Commit 8b99809a authored by Kir Kolyshkin's avatar Kir Kolyshkin Committed by Pavel Emelyanov

compel: make plugins .a archives

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.
Acked-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarKir Kolyshkin <kir@openvz.org>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent af572b3c
......@@ -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)
......
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*)
......
......@@ -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
......
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*)
......
......@@ -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 " $@
......
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)
......
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
......
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)
......
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)
......
......@@ -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)
......
......@@ -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++;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment