From 1866520d6cb0b79497a542beb2141e64fa79822c Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Thu, 21 Mar 2024 11:00:23 +0100 Subject: [PATCH] dde_linux: build initcall_table.c after objects The added hook 'OBJ_POSTPROC_SRC' gives us a way to post-process object files for generating supplemental code. By using this hook, the initcall_table.c generated by import-lx_emul_common.inc gets reliably executed after all object files are built. Fixes #5159 --- repos/base/mk/generic.mk | 11 +++++++++++ repos/dde_linux/lib/import/import-lx_emul_common.inc | 8 ++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/repos/base/mk/generic.mk b/repos/base/mk/generic.mk index d0a2836205..c8f3b19eb2 100644 --- a/repos/base/mk/generic.mk +++ b/repos/base/mk/generic.mk @@ -10,6 +10,17 @@ SRC_O += $(addprefix binary_,$(addsuffix .o,$(notdir $(SRC_BIN)))) SRC = $(sort $(SRC_C) $(SRC_CC) $(SRC_ADB) $(SRC_ADS) $(SRC_RS) $(SRC_S) $(SRC_O) $(SRC_GO)) OBJECTS = $(addsuffix .o,$(basename $(SRC))) +# +# Hook for incorporating source code generated by post-processing object +# files. The source code must be generated after building 'OBJECTS'. But +# the object file(s) resulting from the generated code must be linked. +# Hence, 'OBJECTS' is expanded after the dependency definition. +# +ifneq ($(OBJ_POSTPROC_SRC),) +$(OBJ_POSTPROC_SRC) : $(OBJECTS) +OBJECTS += $(addsuffix .o,$(basename $(OBJ_POSTPROC_SRC))) +endif + # # Create sub directories for objects files corresponding to the sub directories # of their respective source files diff --git a/repos/dde_linux/lib/import/import-lx_emul_common.inc b/repos/dde_linux/lib/import/import-lx_emul_common.inc index 8033e72677..78f2608f88 100644 --- a/repos/dde_linux/lib/import/import-lx_emul_common.inc +++ b/repos/dde_linux/lib/import/import-lx_emul_common.inc @@ -259,16 +259,16 @@ endef # 'module_init' calls should only be in C-sources -WAIT_FOR_OBJECTS = $(addsuffix .o,$(basename $(filter-out initcall_table.c,$(SRC_C)))) +INITCALL_OBJECTS = $(addsuffix .o,$(basename $(SRC_C))) # retrieve 'initptr_*' using nm from object files -INITCALLS = $(sort $(shell $(NM) --defined-only $(WAIT_FOR_OBJECTS) |\ +INITCALLS = $(sort $(shell $(NM) --defined-only $(INITCALL_OBJECTS) |\ grep "__initptr" |\ awk '{print $$3}')) -SRC_C += initcall_table.c +OBJ_POSTPROC_SRC += initcall_table.c -initcall_table.c: $(WAIT_FOR_OBJECTS) +initcall_table.c: $(MSG_CONFIG)$@ @$(call print_file_header,$(shell date +"%F"),$@) @$(foreach sym,$(INITCALLS),$(call print_declaration,$(sym),$@))