xref: /openbmc/linux/scripts/Makefile.vmlinux_o (revision d57cc3b9)
1# SPDX-License-Identifier: GPL-2.0-only
2
3PHONY := __default
4__default: vmlinux.o
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		$(KBUILD_VMLINUX_OBJS) $(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
38# Reuse objtool_args defined in scripts/Makefile.lib if LTO or IBT is enabled.
39#
40# Add some more flags as needed.
41# --no-unreachable and --link might be added twice, but it is fine.
42#
43# Expand objtool_args to a simple variable to avoid circular reference.
44
45objtool_args := \
46	$(if $(delay-objtool),$(objtool_args)) \
47	$(if $(CONFIG_NOINSTR_VALIDATION), --noinstr) \
48	$(if $(CONFIG_GCOV_KERNEL), --no-unreachable) \
49	--link
50
51# Link of vmlinux.o used for section mismatch analysis
52# ---------------------------------------------------------------------------
53
54quiet_cmd_ld_vmlinux.o = LD      $@
55      cmd_ld_vmlinux.o = \
56	$(LD) ${KBUILD_LDFLAGS} -r -o $@ \
57	$(addprefix -T , $(initcalls-lds)) \
58	--whole-archive $(KBUILD_VMLINUX_OBJS) --no-whole-archive \
59	--start-group $(KBUILD_VMLINUX_LIBS) --end-group \
60	$(cmd_objtool)
61
62define rule_ld_vmlinux.o
63	$(call cmd_and_savecmd,ld_vmlinux.o)
64	$(call cmd,gen_objtooldep)
65endef
66
67vmlinux.o: $(initcalls-lds) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS) FORCE
68	$(call if_changed_rule,ld_vmlinux.o)
69
70targets += vmlinux.o
71
72# Add FORCE to the prequisites of a target to force it to be always rebuilt.
73# ---------------------------------------------------------------------------
74
75PHONY += FORCE
76FORCE:
77
78# Read all saved command lines and dependencies for the $(targets) we
79# may be building above, using $(if_changed{,_dep}). As an
80# optimization, we don't need to read them if the target does not
81# exist, we will rebuild anyway in that case.
82
83existing-targets := $(wildcard $(sort $(targets)))
84
85-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
86
87.PHONY: $(PHONY)
88