[CRIU] [PATCH 5/9] criu/pie/Makefile: simplify and fix
Kir Kolyshkin
kir at openvz.org
Fri Mar 24 15:07:42 PDT 2017
The way criu/pie/Makefile is currently written, ld is run twice:
1. link $(NAME-obj-y) objects to NAME.built-in.o
2. link NAME.built-in.o, pie.lib.a, and compel plugins
to NAME.built-in.bin.o (with compel ldflags and linker script)
There is absolutely no need for such two-stage linking, but it was OK.
It is not OK now, as "compel ldflags" for ARM doesn't need -r, and we
can't run the first stage with -r and the second stage without it.
So, let's simplify linking using a single ld invocation. This is my
third attempt in doing it, I think I nailed it this time -- it is now
clean and (relatively) simple.
While at it:
- fix compel linker script dependency (it was not working);
- rearrange the Makefile so variables goes first, then rules;
- remove a comment about mount implementation in restorer.
NOTE that compel is called with ./ prefix so the file paths it prints
are also prefixed with ./, which is needed for objectify macro to ignore
those.
Signed-off-by: Kir Kolyshkin <kir at openvz.org>
---
Makefile.compel | 2 +-
criu/pie/Makefile | 69 ++++++++++++++++++++++---------------------------------
2 files changed, 29 insertions(+), 42 deletions(-)
diff --git a/Makefile.compel b/Makefile.compel
index ab479f7..5012435 100644
--- a/Makefile.compel
+++ b/Makefile.compel
@@ -1,4 +1,4 @@
-COMPEL_BIN := compel/compel-host
+COMPEL_BIN := ./compel/compel-host
export COMPEL_BIN
COMPEL_VERSION_HEADER := compel/include/version.h
diff --git a/criu/pie/Makefile b/criu/pie/Makefile
index 711d83a..6a4fba9 100644
--- a/criu/pie/Makefile
+++ b/criu/pie/Makefile
@@ -1,61 +1,48 @@
-target += parasite restorer
-
-parasite-obj-y += parasite.o
-restorer-obj-y += restorer.o
-restorer-obj-y += ./$(ARCH_DIR)/restorer.o
-
-ifeq ($(ARCH),x86)
- ifeq ($(CONFIG_COMPAT),y)
- restorer-obj-y += ./$(ARCH_DIR)/call32.o
- restorer-obj-y += ./$(ARCH_DIR)/sigaction_compat_pie.o
- endif
-endif
-
-#
-# We can't provide proper mount implementation
-# in parasite code -- it requires run-time rellocation
-# applications, which is not the target of the
-# project.
-#
-CFLAGS := $(filter-out -pg $(CFLAGS-GCOV),$(CFLAGS))
-CFLAGS := $(filter-out $(CFLAGS-ASAN),$(CFLAGS))
+target := parasite restorer
+CFLAGS := $(filter-out -pg $(CFLAGS-GCOV) $(CFLAGS-ASAN),$(CFLAGS))
ccflags-y += $(COMPEL_UAPI_INCLUDES)
ccflags-y += -DCR_NOGLIBC
ccflags-y += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
ccflags-y += -Wp,-U_FORTIFY_SOURCE -Wp,-D_FORTIFY_SOURCE=0
ifneq ($(filter-out clean mrproper,$(MAKECMDGOALS)),)
- CFLAGS += $(shell $(COMPEL_BIN) cflags)
- compel_std := $(shell $(COMPEL_BIN) plugins)
+ CFLAGS += $(shell $(COMPEL_BIN) cflags)
+ LDFLAGS += $(shell $(COMPEL_BIN) ldflags)
+ compel_plugins := $(shell $(COMPEL_BIN) plugins)
endif
ifeq ($(SRCARCH),arm)
- ccflags-y += -marm
+ ccflags-y += -marm
endif
asflags-y += -D__ASSEMBLY__
-BLOBS += $(obj)/restorer-blob.h $(obj)/parasite-blob.h
LDS := compel/arch/$(SRCARCH)/scripts/compel-pack.lds.S
-.SECONDARY:
+restorer-obj-y += ./$(ARCH_DIR)/restorer.o
+
+ifeq ($(ARCH),x86)
+ ifeq ($(CONFIG_COMPAT),y)
+ restorer-obj-y += ./$(ARCH_DIR)/call32.o
+ restorer-obj-y += ./$(ARCH_DIR)/sigaction_compat_pie.o
+ endif
+endif
+
+define gen-pie-rules
+$(1)-obj-y += $(1).o
+$(1)-obj-e += pie.lib.a
+$(1)-obj-e += $$(compel_plugins)
-target-name = $(patsubst criu/pie/%-blob.h,%,$(1))
+# Dependency on compel linker script, to relink if it has changed
+$$(obj)/$(1).built-in.o: $$(LDS)
-$(obj)/%.build-in.bin.o: $(LDS)
-$(obj)/%.built-in.bin.o: $(obj)/%.built-in.o $(obj)/pie.lib.a $(compel_std)
- $(call msg-gen, $@)
- $(Q) $(LD) $(shell $(COMPEL_BIN) ldflags) -o $@ $^
+$$(obj)/$(1)-blob.h: $$(obj)/$(1).built-in.o
+ $$(call msg-gen, $$@)
+ $$(Q) $$(COMPEL_BIN) hgen -f $$< -o $$@
-$(obj)/%-blob.h: $(obj)/%.built-in.bin.o
- $(call msg-gen, $@)
- $(Q) $(COMPEL_BIN) hgen -f $< -o $@
+all-y += $$(obj)/$(1)-blob.h
+cleanup-y += $$(obj)/$(1)-blob.h
+endef
-all-y += $(BLOBS)
-# blobs and pields are in cleanup, rather than in mrproper because
-# we want them to be re-generated after `make clean && make`
-cleanup-y += $(BLOBS)
-cleanup-y += $(obj)/*.bin
-cleanup-y += $(obj)/*.built-in.bin.o
-cleanup-y += $(obj)/*.built-in.bin
+$(foreach t,$(target),$(eval $(call gen-pie-rules,$(t))))
--
2.9.3
More information about the CRIU
mailing list