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 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 delay-objtool (IBT or LTO), objtool doesn't run on individual translation 34# units. Instead it runs on vmlinux.o. 35# 36# For !delay-objtool + CONFIG_NOINSTR_VALIDATION, it runs on both translation 37# units and vmlinux.o, with the latter only used for noinstr/unret validation. 38 39objtool-enabled := $(or $(delay-objtool),$(CONFIG_NOINSTR_VALIDATION)) 40 41ifeq ($(delay-objtool),y) 42vmlinux-objtool-args-y += $(objtool-args-y) 43else 44vmlinux-objtool-args-$(CONFIG_OBJTOOL_WERROR) += --werror 45endif 46 47vmlinux-objtool-args-$(CONFIG_NOINSTR_VALIDATION) += --noinstr \ 48 $(if $(or $(CONFIG_MITIGATION_UNRET_ENTRY),$(CONFIG_MITIGATION_SRSO)), --unret) 49 50# Only used for builds initiated by klp-build 51vmlinux-objtool-args-$(if $(KLP_SYMIDS),y) += --klp-symids 52 53objtool-args = $(vmlinux-objtool-args-y) --link 54 55# Link of vmlinux.o used for section mismatch analysis 56# --------------------------------------------------------------------------- 57 58vmlinux-o-ld-args-$(CONFIG_BUILTIN_MODULE_RANGES) += -Map=$@.map 59 60quiet_cmd_ld_vmlinux.o = LD $@ 61 cmd_ld_vmlinux.o = \ 62 $(LD) ${KBUILD_LDFLAGS} -r -o $@ \ 63 $(vmlinux-o-ld-args-y) \ 64 $(addprefix -T , $(initcalls-lds)) \ 65 --whole-archive vmlinux.a --no-whole-archive \ 66 --start-group $(KBUILD_VMLINUX_LIBS) --end-group \ 67 $(cmd_objtool) 68 69cmd_check_function_names = $(srctree)/scripts/check-function-names.sh $@ 70 71define rule_ld_vmlinux.o 72 $(call cmd_and_savecmd,ld_vmlinux.o) 73 $(call cmd,gen_objtooldep) 74 $(call cmd,check_function_names) 75endef 76 77 78vmlinux.o: $(initcalls-lds) vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE 79 $(call if_changed_rule,ld_vmlinux.o) 80 81targets += vmlinux.o 82 83# Add FORCE to the prerequisites of a target to force it to be always rebuilt. 84# --------------------------------------------------------------------------- 85 86PHONY += FORCE 87FORCE: 88 89# Read all saved command lines and dependencies for the $(targets) we 90# may be building above, using $(if_changed{,_dep}). As an 91# optimization, we don't need to read them if the target does not 92# exist, we will rebuild anyway in that case. 93 94existing-targets := $(wildcard $(sort $(targets))) 95 96-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) 97 98.PHONY: $(PHONY) 99