Commit 37904cc9 authored by Kir Kolyshkin's avatar Kir Kolyshkin Committed by Pavel Emelyanov

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: '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 9cf884f0
COMPEL_BIN := compel/compel-host COMPEL_BIN := ./compel/compel-host
export COMPEL_BIN export COMPEL_BIN
COMPEL_VERSION_HEADER := compel/include/version.h COMPEL_VERSION_HEADER := compel/include/version.h
......
target += parasite restorer 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))
CFLAGS := $(filter-out -pg $(CFLAGS-GCOV) $(CFLAGS-ASAN),$(CFLAGS))
ccflags-y += $(COMPEL_UAPI_INCLUDES) ccflags-y += $(COMPEL_UAPI_INCLUDES)
ccflags-y += -DCR_NOGLIBC ccflags-y += -DCR_NOGLIBC
ccflags-y += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 ccflags-y += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
ccflags-y += -Wp,-U_FORTIFY_SOURCE -Wp,-D_FORTIFY_SOURCE=0 ccflags-y += -Wp,-U_FORTIFY_SOURCE -Wp,-D_FORTIFY_SOURCE=0
ifneq ($(filter-out clean mrproper,$(MAKECMDGOALS)),) ifneq ($(filter-out clean mrproper,$(MAKECMDGOALS)),)
CFLAGS += $(shell $(COMPEL_BIN) cflags) CFLAGS += $(shell $(COMPEL_BIN) cflags)
compel_std := $(shell $(COMPEL_BIN) plugins) LDFLAGS += $(shell $(COMPEL_BIN) ldflags)
compel_plugins := $(shell $(COMPEL_BIN) plugins)
endif endif
ifeq ($(SRCARCH),arm) ifeq ($(SRCARCH),arm)
ccflags-y += -marm ccflags-y += -marm
endif endif
asflags-y += -D__ASSEMBLY__ asflags-y += -D__ASSEMBLY__
BLOBS += $(obj)/restorer-blob.h $(obj)/parasite-blob.h
LDS := compel/arch/$(SRCARCH)/scripts/compel-pack.lds.S 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)/$(1)-blob.h: $$(obj)/$(1).built-in.o
$(obj)/%.built-in.bin.o: $(obj)/%.built-in.o $(obj)/pie.lib.a $(compel_std) $$(call msg-gen, $$@)
$(call msg-gen, $@) $$(Q) $$(COMPEL_BIN) hgen -f $$< -o $$@
$(Q) $(LD) $(shell $(COMPEL_BIN) ldflags) -o $@ $^
$(obj)/%-blob.h: $(obj)/%.built-in.bin.o all-y += $$(obj)/$(1)-blob.h
$(call msg-gen, $@) cleanup-y += $$(obj)/$(1)-blob.h
$(Q) $(COMPEL_BIN) hgen -f $< -o $@ endef
all-y += $(BLOBS) $(foreach t,$(target),$(eval $(call gen-pie-rules,$(t))))
# 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
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