[CRIU] [PATCH 18/24] compel cli: add linker script to ldflags / use it
Kir Kolyshkin
kir at openvz.org
Sat Dec 17 03:22:11 PST 2016
This commit adds -T path/to/linker_script to the output
of "compel ldflags", so compel user does not have to specify
one manually.
This commit also makes use of this functionality in criu/pie
and compel/test.
NOTE this commit also drops the linker script dependency
in criu/pie/Makefile, meaning if it will be changed that
won't cause a rebuild. I hope it's not a big issue, and it is
sort of inevitable as compel is becoming a separate tool.
Signed-off-by: Kir Kolyshkin <kir at openvz.org>
---
compel/Makefile | 1 +
compel/src/main.c | 26 ++++++++++++++++++++++++--
compel/test/infect/Makefile | 4 +---
criu/pie/Makefile | 5 ++---
4 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/compel/Makefile b/compel/Makefile
index 1d2230c..670654e 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 764c794..c51d05b 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_<ARCH> 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 8d35c29..e08fa79 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 4dcc60a..96647c8 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
@@ -54,9 +53,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, $@)
--
2.7.4
More information about the CRIU
mailing list