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
This commit is contained in:
Norman Feske 2024-03-21 11:00:23 +01:00 committed by Christian Helmuth
parent bc44104522
commit 1866520d6c
2 changed files with 15 additions and 4 deletions

View File

@ -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)) SRC = $(sort $(SRC_C) $(SRC_CC) $(SRC_ADB) $(SRC_ADS) $(SRC_RS) $(SRC_S) $(SRC_O) $(SRC_GO))
OBJECTS = $(addsuffix .o,$(basename $(SRC))) 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 # Create sub directories for objects files corresponding to the sub directories
# of their respective source files # of their respective source files

View File

@ -259,16 +259,16 @@ endef
# 'module_init' calls should only be in C-sources # '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 # 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" |\ grep "__initptr" |\
awk '{print $$3}')) 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)$@ $(MSG_CONFIG)$@
@$(call print_file_header,$(shell date +"%F"),$@) @$(call print_file_header,$(shell date +"%F"),$@)
@$(foreach sym,$(INITCALLS),$(call print_declaration,$(sym),$@)) @$(foreach sym,$(INITCALLS),$(call print_declaration,$(sym),$@))