xref: /openbmc/linux/scripts/Makefile.vmlinux_o (revision a2cab953)
1# SPDX-License-Identifier: GPL-2.0-only
2
3PHONY := __default
4__default: vmlinux.o modules.builtin.modinfo modules.builtin
5
6include include/config/auto.conf
7include $(srctree)/scripts/Kbuild.include
8
9# for objtool
10include $(srctree)/scripts/Makefile.lib
11
12# 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 \
21		vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE
22	$(call if_changed,gen_initcalls_lds)
23
24targets := .tmp_initcalls.lds
25
26ifdef CONFIG_LTO_CLANG
27initcalls-lds := .tmp_initcalls.lds
28endif
29
30# 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
38vmlinux-objtool-args-$(delay-objtool)			+= $(objtool-args-y)
39vmlinux-objtool-args-$(CONFIG_GCOV_KERNEL)		+= --no-unreachable
40vmlinux-objtool-args-$(CONFIG_NOINSTR_VALIDATION)	+= --noinstr $(if $(CONFIG_CPU_UNRET_ENTRY), --unret)
41
42objtool-args = $(vmlinux-objtool-args-y) --link
43
44# Link of vmlinux.o used for section mismatch analysis
45# ---------------------------------------------------------------------------
46
47quiet_cmd_ld_vmlinux.o = LD      $@
48      cmd_ld_vmlinux.o = \
49	$(LD) ${KBUILD_LDFLAGS} -r -o $@ \
50	$(addprefix -T , $(initcalls-lds)) \
51	--whole-archive vmlinux.a --no-whole-archive \
52	--start-group $(KBUILD_VMLINUX_LIBS) --end-group \
53	$(cmd_objtool)
54
55define rule_ld_vmlinux.o
56	$(call cmd_and_savecmd,ld_vmlinux.o)
57	$(call cmd,gen_objtooldep)
58endef
59
60vmlinux.o: $(initcalls-lds) vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE
61	$(call if_changed_rule,ld_vmlinux.o)
62
63targets += vmlinux.o
64
65# module.builtin.modinfo
66# ---------------------------------------------------------------------------
67
68OBJCOPYFLAGS_modules.builtin.modinfo := -j .modinfo -O binary
69
70targets += modules.builtin.modinfo
71modules.builtin.modinfo: vmlinux.o FORCE
72	$(call if_changed,objcopy)
73
74# module.builtin
75# ---------------------------------------------------------------------------
76
77# The second line aids cases where multiple modules share the same object.
78
79quiet_cmd_modules_builtin = GEN     $@
80      cmd_modules_builtin = \
81	tr '\0' '\n' < $< | \
82	sed -n 's/^[[:alnum:]:_]*\.file=//p' | \
83	tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$$/.ko/' > $@
84
85targets += modules.builtin
86modules.builtin: modules.builtin.modinfo FORCE
87	$(call if_changed,modules_builtin)
88
89# Add FORCE to the prequisites of a target to force it to be always rebuilt.
90# ---------------------------------------------------------------------------
91
92PHONY += FORCE
93FORCE:
94
95# Read all saved command lines and dependencies for the $(targets) we
96# may be building above, using $(if_changed{,_dep}). As an
97# optimization, we don't need to read them if the target does not
98# exist, we will rebuild anyway in that case.
99
100existing-targets := $(wildcard $(sort $(targets)))
101
102-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
103
104.PHONY: $(PHONY)
105