From 37904cc91a712f27a739319fd9bb99a8fcc819d7 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 24 Mar 2017 15:07:42 -0700 Subject: [PATCH] criu/pie/Makefile: simplify and fix 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. Acked-by: Cyrill Gorcunov Signed-off-by: Kir Kolyshkin Signed-off-by: Andrei Vagin --- Makefile.compel | 2 +- criu/pie/Makefile | 81 ++++++++++++++++++++--------------------------- 2 files changed, 35 insertions(+), 48 deletions(-) diff --git a/Makefile.compel b/Makefile.compel index ab479f79d..50124351d 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 711d83a60..6a4fba9c1 100644 --- a/criu/pie/Makefile +++ b/criu/pie/Makefile @@ -1,7 +1,25 @@ -target += parasite restorer +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) + LDFLAGS += $(shell $(COMPEL_BIN) ldflags) + compel_plugins := $(shell $(COMPEL_BIN) plugins) +endif + +ifeq ($(SRCARCH),arm) + ccflags-y += -marm +endif + +asflags-y += -D__ASSEMBLY__ + +LDS := compel/arch/$(SRCARCH)/scripts/compel-pack.lds.S -parasite-obj-y += parasite.o -restorer-obj-y += restorer.o restorer-obj-y += ./$(ARCH_DIR)/restorer.o ifeq ($(ARCH),x86) @@ -11,51 +29,20 @@ ifeq ($(ARCH),x86) 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)) +define gen-pie-rules +$(1)-obj-y += $(1).o +$(1)-obj-e += pie.lib.a +$(1)-obj-e += $$(compel_plugins) -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 +# Dependency on compel linker script, to relink if it has changed +$$(obj)/$(1).built-in.o: $$(LDS) -ifneq ($(filter-out clean mrproper,$(MAKECMDGOALS)),) - CFLAGS += $(shell $(COMPEL_BIN) cflags) - compel_std := $(shell $(COMPEL_BIN) plugins) -endif +$$(obj)/$(1)-blob.h: $$(obj)/$(1).built-in.o + $$(call msg-gen, $$@) + $$(Q) $$(COMPEL_BIN) hgen -f $$< -o $$@ -ifeq ($(SRCARCH),arm) - ccflags-y += -marm -endif +all-y += $$(obj)/$(1)-blob.h +cleanup-y += $$(obj)/$(1)-blob.h +endef -asflags-y += -D__ASSEMBLY__ - -BLOBS += $(obj)/restorer-blob.h $(obj)/parasite-blob.h -LDS := compel/arch/$(SRCARCH)/scripts/compel-pack.lds.S - -.SECONDARY: - -target-name = $(patsubst criu/pie/%-blob.h,%,$(1)) - -$(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)/%-blob.h: $(obj)/%.built-in.bin.o - $(call msg-gen, $@) - $(Q) $(COMPEL_BIN) hgen -f $< -o $@ - -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))))