diff --git a/compel/Makefile b/compel/Makefile index 1d2230c26..670654e0e 100644 --- a/compel/Makefile +++ b/compel/Makefile @@ -3,6 +3,7 @@ include $(SRC_DIR)/Makefile.versions COMPEL_SO_VERSION := $(COMPEL_SO_VERSION_MAJOR)$(if $(COMPEL_SO_VERSION_MINOR),.$(COMPEL_SO_VERSION_MINOR))$(if $(COMPEL_SO_VERSION_SUBLEVEL),.$(COMPEL_SO_VERSION_SUBLEVEL)) COMPEL_SO_VERSION_CODE := $(shell expr $(COMPEL_SO_VERSION_MAJOR) \* 65536 \+ $(COMPEL_SO_VERSION_MINOR) \* 256 \+ $(COMPEL_SO_VERSION_SUBLEVEL)) ccflags-y += -DINCLUDEDIR=\"$(INCLUDEDIR)\" +ccflags-y += -DLIBEXECDIR=\"$(LIBEXECDIR)\" ccflags-y += -iquote compel/arch/$(ARCH)/src/lib/include ccflags-y += -iquote compel/include ccflags-y += -fno-strict-aliasing diff --git a/compel/src/main.c b/compel/src/main.c index f91fe2729..cd4753c1c 100644 --- a/compel/src/main.c +++ b/compel/src/main.c @@ -25,22 +25,27 @@ #define COMPEL_CFLAGS_PIE CFLAGS_DEFAULT_SET "-fpie" #define COMPEL_CFLAGS_NOPIC CFLAGS_DEFAULT_SET "-fno-pic" -#define COMPEL_LDFLAGS_DEFAULT "-r -z noexecstack" +#define COMPEL_LDFLAGS_COMMON "-r -z noexecstack -T " typedef struct { + const char *arch; // dir name under arch/ const char *cflags; const char *cflags_compat; } flags_t; static const flags_t flags = { #if defined CONFIG_X86_64 + .arch = "x86", .cflags = COMPEL_CFLAGS_PIE, .cflags_compat = COMPEL_CFLAGS_NOPIC, #elif defined CONFIG_AARCH64 + .arch = "aarch64", .cflags = COMPEL_CFLAGS_PIE, #elif defined(CONFIG_ARMV6) || defined(CONFIG_ARMV7) + .arch = "arm", .cflags = COMPEL_CFLAGS_PIE, #elif defined CONFIG_PPC64 + .arch = "ppc64", .cflags = COMPEL_CFLAGS_PIE, #else #error "CONFIG_ not defined, or unsupported ARCH" @@ -160,6 +165,23 @@ static void print_cflags(bool compat) print_includes(); } +static void print_ldflags(bool compat) +{ + const char *compat_str = (compat) ? "-compat" : ""; + + printf("%s", COMPEL_LDFLAGS_COMMON); + + if (uninst_root) { + printf("%s/arch/%s/scripts/compel-pack%s.lds.S\n", + uninst_root, flags.arch, compat_str); + } + else { + printf("%s/compel/scripts/compel-pack%s.lds.S\n", + LIBEXECDIR, compat_str); + + } +} + int main(int argc, char *argv[]) { int log_level = DEFAULT_LOGLEVEL; @@ -234,7 +256,7 @@ int main(int argc, char *argv[]) } if (!strcmp(action, "ldflags")) { - printf("%s", COMPEL_LDFLAGS_DEFAULT); + print_ldflags(compat); return 0; } diff --git a/compel/test/infect/Makefile b/compel/test/infect/Makefile index 8d35c2967..e08fa7941 100644 --- a/compel/test/infect/Makefile +++ b/compel/test/infect/Makefile @@ -1,9 +1,7 @@ CC := gcc CFLAGS ?= -O2 -g -Wall -Werror -ARCH ?= x86 COMPEL := ../../../compel/compel-host -COMPEL_PACK_LDS := ../../../compel/arch/$(ARCH)/scripts/compel-pack.lds.S COMPEL_PLUGINS := ../../../compel/plugins COMPEL_LIBRARY := ../../../compel/libcompel.a @@ -28,7 +26,7 @@ parasite.h: parasite.po -o $@ parasite.po: parasite.o $(COMPEL_PLUGINS)/std.built-in.o - ld -r -T $(COMPEL_PACK_LDS) -o $@ $^ + ld $(shell $(COMPEL) ldflags) -o $@ $^ parasite.o: parasite.c $(CC) $(CFLAGS) -c $(shell $(COMPEL) cflags) -o $@ $^ diff --git a/criu/pie/Makefile b/criu/pie/Makefile index f75d166fa..b5a08de5f 100644 --- a/criu/pie/Makefile +++ b/criu/pie/Makefile @@ -1,6 +1,5 @@ target += parasite restorer -compel_lds := $(SRC_DIR)/compel/arch/$(ARCH)/scripts/compel-pack.lds.S compel_std := $(SRC_DIR)/compel/plugins/std.built-in.o parasite-obj-e += ./compel/plugins/std.built-in.o restorer-obj-e += ./compel/plugins/std.built-in.o @@ -57,9 +56,9 @@ endif $(obj)/restorer.built-in.o: $(compel_std) $(obj)/parasite.built-in.o: $(compel_std) -$(obj)/%.built-in.bin.o: $(obj)/%.built-in.o $(obj)/pie.lib.a $(compel_lds) +$(obj)/%.built-in.bin.o: $(obj)/%.built-in.o $(obj)/pie.lib.a $(call msg-gen, $@) - $(Q) $(LD) -r -T $(compel_lds) -o $@ $< $(obj)/pie.lib.a + $(Q) $(LD) $(shell $(COMPEL_BIN) ldflags) -o $@ $< $(obj)/pie.lib.a $(obj)/%-blob.h: $(obj)/%.built-in.bin.o $(SRC_DIR)/compel/compel-host-bin $(call msg-gen, $@)