blob: 25b3b587d37c00cd77415ef8d6533e9a18c4dcc9 [file] [log] [blame]
Masahiro Yamada5d459502022-05-29 00:47:03 +09001# SPDX-License-Identifier: GPL-2.0-only
2
3PHONY := __default
Masahiro Yamada7a342e62022-09-28 15:39:40 +09004__default: vmlinux.o modules.builtin.modinfo modules.builtin
Masahiro Yamada5d459502022-05-29 00:47:03 +09005
6include include/config/auto.conf
7include $(srctree)/scripts/Kbuild.include
8
Masahiro Yamadab42d2302022-05-29 00:47:04 +09009# for objtool
10include $(srctree)/scripts/Makefile.lib
11
Masahiro Yamada5d459502022-05-29 00:47:03 +090012# Generate a linker script to ensure correct ordering of initcalls for Clang LTO
13# ---------------------------------------------------------------------------
14
15quiet_cmd_gen_initcalls_lds = GEN $@
16 cmd_gen_initcalls_lds = \
17 $(PYTHON3) $(srctree)/scripts/jobserver-exec \
18 $(PERL) $(real-prereqs) > $@
19
20.tmp_initcalls.lds: $(srctree)/scripts/generate_initcall_order.pl \
Masahiro Yamada32164842022-09-25 03:19:14 +090021 vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE
Masahiro Yamada5d459502022-05-29 00:47:03 +090022 $(call if_changed,gen_initcalls_lds)
23
24targets := .tmp_initcalls.lds
25
26ifdef CONFIG_LTO_CLANG
27initcalls-lds := .tmp_initcalls.lds
28endif
29
Masahiro Yamadab42d2302022-05-29 00:47:04 +090030# objtool for vmlinux.o
31# ---------------------------------------------------------------------------
32#
33# For LTO and IBT, objtool doesn't run on individual translation units.
34# Run everything on vmlinux instead.
35
36objtool-enabled := $(or $(delay-objtool),$(CONFIG_NOINSTR_VALIDATION))
37
Masahiro Yamada9ec6ab62022-09-07 03:49:35 +090038vmlinux-objtool-args-$(delay-objtool) += $(objtool-args-y)
39vmlinux-objtool-args-$(CONFIG_GCOV_KERNEL) += --no-unreachable
Josh Poimboeuf626ea252023-09-04 22:04:53 -070040vmlinux-objtool-args-$(CONFIG_NOINSTR_VALIDATION) += --noinstr \
41 $(if $(or $(CONFIG_CPU_UNRET_ENTRY),$(CONFIG_CPU_SRSO)), --unret)
Masahiro Yamadab42d2302022-05-29 00:47:04 +090042
Masahiro Yamada9ec6ab62022-09-07 03:49:35 +090043objtool-args = $(vmlinux-objtool-args-y) --link
Masahiro Yamadab42d2302022-05-29 00:47:04 +090044
Masahiro Yamada5d459502022-05-29 00:47:03 +090045# Link of vmlinux.o used for section mismatch analysis
46# ---------------------------------------------------------------------------
47
48quiet_cmd_ld_vmlinux.o = LD $@
49 cmd_ld_vmlinux.o = \
50 $(LD) ${KBUILD_LDFLAGS} -r -o $@ \
51 $(addprefix -T , $(initcalls-lds)) \
Masahiro Yamada32164842022-09-25 03:19:14 +090052 --whole-archive vmlinux.a --no-whole-archive \
Masahiro Yamada5d459502022-05-29 00:47:03 +090053 --start-group $(KBUILD_VMLINUX_LIBS) --end-group \
Masahiro Yamadab42d2302022-05-29 00:47:04 +090054 $(cmd_objtool)
Masahiro Yamada5d459502022-05-29 00:47:03 +090055
56define rule_ld_vmlinux.o
57 $(call cmd_and_savecmd,ld_vmlinux.o)
Masahiro Yamadab42d2302022-05-29 00:47:04 +090058 $(call cmd,gen_objtooldep)
Masahiro Yamada5d459502022-05-29 00:47:03 +090059endef
60
Masahiro Yamada32164842022-09-25 03:19:14 +090061vmlinux.o: $(initcalls-lds) vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE
Masahiro Yamada5d459502022-05-29 00:47:03 +090062 $(call if_changed_rule,ld_vmlinux.o)
63
64targets += vmlinux.o
65
Masahiro Yamada7a342e62022-09-28 15:39:40 +090066# module.builtin.modinfo
67# ---------------------------------------------------------------------------
68
69OBJCOPYFLAGS_modules.builtin.modinfo := -j .modinfo -O binary
70
71targets += modules.builtin.modinfo
72modules.builtin.modinfo: vmlinux.o FORCE
73 $(call if_changed,objcopy)
74
75# module.builtin
76# ---------------------------------------------------------------------------
77
78# The second line aids cases where multiple modules share the same object.
79
80quiet_cmd_modules_builtin = GEN $@
81 cmd_modules_builtin = \
82 tr '\0' '\n' < $< | \
83 sed -n 's/^[[:alnum:]:_]*\.file=//p' | \
84 tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$$/.ko/' > $@
85
86targets += modules.builtin
87modules.builtin: modules.builtin.modinfo FORCE
88 $(call if_changed,modules_builtin)
89
Masahiro Yamada5d459502022-05-29 00:47:03 +090090# Add FORCE to the prequisites of a target to force it to be always rebuilt.
91# ---------------------------------------------------------------------------
92
93PHONY += FORCE
94FORCE:
95
96# Read all saved command lines and dependencies for the $(targets) we
97# may be building above, using $(if_changed{,_dep}). As an
98# optimization, we don't need to read them if the target does not
99# exist, we will rebuild anyway in that case.
100
101existing-targets := $(wildcard $(sort $(targets)))
102
103-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
104
105.PHONY: $(PHONY)