| # SPDX-License-Identifier: GPL-2.0-only |
| # =========================================================================== |
| # Module final link |
| # =========================================================================== |
| |
| PHONY := __modfinal |
| __modfinal: |
| |
| include scripts/Kbuild.include |
| |
| # for c_flags |
| include scripts/Makefile.lib |
| |
| # find all modules listed in modules.order |
| modules := $(sort $(shell cat $(MODORDER))) |
| modules-klp := $(sort $(shell cat $(MODULES_LIVEPATCH))) |
| modules-no-klp := $(filter-out $(modules-klp), $(modules)) |
| |
| __modfinal: $(modules) |
| @: |
| |
| # modname is set to make c_flags define KBUILD_MODNAME |
| modname = $(notdir $(@:.mod.o=)) |
| |
| quiet_cmd_cc_o_c = CC [M] $@ |
| cmd_cc_o_c = $(CC) $(c_flags) $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE) \ |
| -c -o $@ $< |
| |
| %.mod.o: %.mod.c FORCE |
| $(call if_changed_dep,cc_o_c) |
| |
| ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) |
| |
| quiet_cmd_ld_ko_o = LD [M] $@ |
| cmd_ld_ko_o = \ |
| $(LD) -r $(KBUILD_LDFLAGS) \ |
| $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ |
| $(addprefix -T , $(KBUILD_LDS_MODULE)) \ |
| -o $@ $(filter %.o, $^); \ |
| $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) |
| |
| $(modules-no-klp): %.ko: %.o %.mod.o $(KBUILD_LDS_MODULE) FORCE |
| +$(call if_changed,ld_ko_o) |
| |
| targets += $(modules) $(modules:.ko=.mod.o) |
| |
| # Live Patch |
| # --------------------------------------------------------------------------- |
| |
| $(modules-klp:.ko=.tmp.ko): %.tmp.ko: %.o %.mod.o Symbols.list FORCE |
| +$(call if_changed,ld_ko_o) |
| |
| quiet_cmd_klp_convert = KLP $@ |
| cmd_klp_convert = scripts/livepatch/klp-convert Symbols.list $< $@ |
| |
| $(modules-klp): %.ko: %.tmp.ko FORCE |
| $(call if_changed,klp_convert) |
| |
| targets += $(modules-klp:.ko=.tmp.ko) |
| |
| ifeq ($(KBUILD_EXTMOD),) |
| # Read out modules.{order,livepatch} instead of expanding $(modules-no-klp). |
| # Otherwise, allmodconfig would fail with "Argument list too long". |
| filechk_klp_map = \ |
| echo "klp-convert-symbol-data.0.1"; \ |
| echo "*vmlinux"; \ |
| $(NM) -f posix vmlinux | cut -d\ -f1; \ |
| sort $(MODORDER) $(MODULES_LIVEPATCH) | \ |
| uniq -u | \ |
| sed 's/\.ko$$//' | \ |
| while read o; \ |
| do \ |
| echo "*$$(basename $$o)"; \ |
| $(NM) -f posix $$o.o | cut -d\ -f1; \ |
| done |
| |
| Symbols.list: FORCE |
| $(call filechk,klp_map) |
| endif |
| |
| # Add FORCE to the prequisites of a target to force it to be always rebuilt. |
| # --------------------------------------------------------------------------- |
| |
| PHONY += FORCE |
| FORCE: |
| |
| # Read all saved command lines and dependencies for the $(targets) we |
| # may be building above, using $(if_changed{,_dep}). As an |
| # optimization, we don't need to read them if the target does not |
| # exist, we will rebuild anyway in that case. |
| |
| existing-targets := $(wildcard $(sort $(targets))) |
| |
| -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) |
| |
| .PHONY: $(PHONY) |