• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
13include $(srctree)/scripts/Makefile.lib
14
15mixed-build-prefix = $(if $(KBUILD_MIXED_TREE),$(KBUILD_MIXED_TREE)/)
16
17# find all modules listed in modules.order
18modules := $(call read-file, $(MODORDER))
19
20__modfinal: $(modules:%.o=%.ko)
21	@:
22
23# modname and part-of-module are set to make c_flags define proper module flags
24modname = $(notdir $(@:.mod.o=))
25part-of-module = y
26GCOV_PROFILE := n
27KCSAN_SANITIZE := n
28
29quiet_cmd_cc_o_c = CC [M]  $@
30      cmd_cc_o_c = $(CC) $(filter-out $(CC_FLAGS_CFI), $(c_flags)) -c -o $@ $<
31
32%.mod.o: %.mod.c FORCE
33	$(call if_changed_dep,cc_o_c)
34
35$(extmod_prefix).module-common.o: $(srctree)/scripts/module-common.c FORCE
36	$(call if_changed_dep,cc_o_c)
37
38ifdef CONFIG_CRYPTO_FIPS140_MOD
39ARCH_POSTLINK := $(srctree)/arch/$(SRCARCH)/Makefile.postlink
40endif
41
42quiet_cmd_ld_ko_o = LD [M]  $@
43      cmd_ld_ko_o =							\
44	$(LD) -r $(KBUILD_LDFLAGS)					\
45		$(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE)		\
46		-T $(objtree)/scripts/module.lds -o $@ $(filter %.o, $^);		\
47	$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
48
49quiet_cmd_btf_ko = BTF [M] $@
50      cmd_btf_ko = 							\
51	if [ ! -f $(mixed-build-prefix)vmlinux ]; then					\
52		printf "Skipping BTF generation for %s due to unavailability of $(mixed-build-prefix)vmlinux\n" $@ 1>&2; \
53	else								\
54		LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) $(MODULE_PAHOLE_FLAGS) --btf_base $(mixed-build-prefix)vmlinux $@; \
55		$(RESOLVE_BTFIDS) -b $(mixed-build-prefix)vmlinux $@; 			\
56	fi;
57
58# Same as newer-prereqs, but allows to exclude specified extra dependencies
59newer_prereqs_except = $(filter-out $(PHONY) $(1),$?)
60
61# Same as if_changed, but allows to exclude specified extra dependencies
62if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check),      \
63	$(cmd);                                                              \
64	printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)
65
66# Re-generate module BTFs if either module's .ko or vmlinux changed
67%.ko: %.o %.mod.o $(extmod_prefix).module-common.o $(objtree)/scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),$(mixed-build-prefix)vmlinux) FORCE
68	+$(call if_changed_except,ld_ko_o,$(mixed-build-prefix)vmlinux)
69ifdef CONFIG_DEBUG_INFO_BTF_MODULES
70	+$(if $(newer-prereqs),$(call cmd,btf_ko))
71endif
72
73targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o) $(extmod_prefix).module-common.o
74
75# Add FORCE to the prerequisites of a target to force it to be always rebuilt.
76# ---------------------------------------------------------------------------
77
78PHONY += FORCE
79FORCE:
80
81# Read all saved command lines and dependencies for the $(targets) we
82# may be building above, using $(if_changed{,_dep}). As an
83# optimization, we don't need to read them if the target does not
84# exist, we will rebuild anyway in that case.
85
86existing-targets := $(wildcard $(sort $(targets)))
87
88-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
89
90.PHONY: $(PHONY)
91