1# SPDX-License-Identifier: GPL-2.0-only 2# =========================================================================== 3# Module final link 4# =========================================================================== 5 6PHONY := __modfinal 7__modfinal: 8 9include $(objtree)/include/config/auto.conf 10include $(srctree)/scripts/Kbuild.include 11 12# for c_flags and mod-prelink-ext 13include $(srctree)/scripts/Makefile.lib 14 15# find all modules listed in modules.order 16modules := $(sort $(shell cat $(MODORDER))) 17 18__modfinal: $(modules) 19 @: 20 21# modname and part-of-module are set to make c_flags define proper module flags 22modname = $(notdir $(@:.mod.o=)) 23part-of-module = y 24 25quiet_cmd_cc_o_c = CC [M] $@ 26 cmd_cc_o_c = \ 27 $(CC) $(filter-out $(CC_FLAGS_CFI) $(CC_FLAGS_FTRACE), \ 28 $(c_flags)) -c -o $@ $< 29 30%.mod.o: %.mod.c FORCE 31 $(call if_changed_dep,cc_o_c) 32 33ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) 34 35quiet_cmd_ld_ko_o = LD [M] $@ 36 cmd_ld_ko_o += \ 37 $(LD) -r $(KBUILD_LDFLAGS) \ 38 $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ 39 -T scripts/module.lds -o $@ $(filter %.o, $^); \ 40 $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) 41 42ifdef CONFIG_CFI_CLANG 43# LLVM can drops jump table symbols from the final binary. Add them 44# back to make stack traces and other symbol output readable. 45cmd_ld_ko_o += ; \ 46 $(srctree)/scripts/generate_cfi_kallsyms.pl --module \ 47 $@ > $(@:.ko=.lds); \ 48 if [ -s $(@:.ko=.lds) ]; then \ 49 $(LD) -r $(KBUILD_LDFLAGS) \ 50 $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ 51 -T $(@:.ko=.lds) \ 52 -o $(@:.ko=.tmp.ko) $@; \ 53 mv -f $(@:.ko=.tmp.ko) $@; \ 54 else \ 55 rm -f $(@:.ko=.lds); \ 56 fi 57endif 58 59$(modules): %.ko: %$(mod-prelink-ext).o %.mod.o scripts/module.lds FORCE 60 +$(call if_changed,ld_ko_o) 61 62targets += $(modules) $(modules:.ko=.mod.o) 63 64# Add FORCE to the prequisites of a target to force it to be always rebuilt. 65# --------------------------------------------------------------------------- 66 67PHONY += FORCE 68FORCE: 69 70# Read all saved command lines and dependencies for the $(targets) we 71# may be building above, using $(if_changed{,_dep}). As an 72# optimization, we don't need to read them if the target does not 73# exist, we will rebuild anyway in that case. 74 75existing-targets := $(wildcard $(sort $(targets))) 76 77-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) 78 79.PHONY: $(PHONY) 80