Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: GPL-2.0-only
0002 
0003 PHONY := __default
0004 __default: vmlinux.o
0005 
0006 include include/config/auto.conf
0007 include $(srctree)/scripts/Kbuild.include
0008 
0009 # for objtool
0010 include $(srctree)/scripts/Makefile.lib
0011 
0012 # Generate a linker script to ensure correct ordering of initcalls for Clang LTO
0013 # ---------------------------------------------------------------------------
0014 
0015 quiet_cmd_gen_initcalls_lds = GEN     $@
0016       cmd_gen_initcalls_lds = \
0017         $(PYTHON3) $(srctree)/scripts/jobserver-exec \
0018         $(PERL) $(real-prereqs) > $@
0019 
0020 .tmp_initcalls.lds: $(srctree)/scripts/generate_initcall_order.pl \
0021                 $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS) FORCE
0022         $(call if_changed,gen_initcalls_lds)
0023 
0024 targets := .tmp_initcalls.lds
0025 
0026 ifdef CONFIG_LTO_CLANG
0027 initcalls-lds := .tmp_initcalls.lds
0028 endif
0029 
0030 # objtool for vmlinux.o
0031 # ---------------------------------------------------------------------------
0032 #
0033 # For LTO and IBT, objtool doesn't run on individual translation units.
0034 # Run everything on vmlinux instead.
0035 
0036 objtool-enabled := $(or $(delay-objtool),$(CONFIG_NOINSTR_VALIDATION))
0037 
0038 # Reuse objtool_args defined in scripts/Makefile.lib if LTO or IBT is enabled.
0039 #
0040 # Add some more flags as needed.
0041 # --no-unreachable and --link might be added twice, but it is fine.
0042 #
0043 # Expand objtool_args to a simple variable to avoid circular reference.
0044 
0045 objtool_args := \
0046         $(if $(delay-objtool),$(objtool_args)) \
0047         $(if $(CONFIG_NOINSTR_VALIDATION), --noinstr $(if $(CONFIG_CPU_UNRET_ENTRY), --unret)) \
0048         $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) \
0049         --link
0050 
0051 # Link of vmlinux.o used for section mismatch analysis
0052 # ---------------------------------------------------------------------------
0053 
0054 quiet_cmd_ld_vmlinux.o = LD      $@
0055       cmd_ld_vmlinux.o = \
0056         $(LD) ${KBUILD_LDFLAGS} -r -o $@ \
0057         $(addprefix -T , $(initcalls-lds)) \
0058         --whole-archive $(KBUILD_VMLINUX_OBJS) --no-whole-archive \
0059         --start-group $(KBUILD_VMLINUX_LIBS) --end-group \
0060         $(cmd_objtool)
0061 
0062 define rule_ld_vmlinux.o
0063         $(call cmd_and_savecmd,ld_vmlinux.o)
0064         $(call cmd,gen_objtooldep)
0065 endef
0066 
0067 vmlinux.o: $(initcalls-lds) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS) FORCE
0068         $(call if_changed_rule,ld_vmlinux.o)
0069 
0070 targets += vmlinux.o
0071 
0072 # Add FORCE to the prequisites of a target to force it to be always rebuilt.
0073 # ---------------------------------------------------------------------------
0074 
0075 PHONY += FORCE
0076 FORCE:
0077 
0078 # Read all saved command lines and dependencies for the $(targets) we
0079 # may be building above, using $(if_changed{,_dep}). As an
0080 # optimization, we don't need to read them if the target does not
0081 # exist, we will rebuild anyway in that case.
0082 
0083 existing-targets := $(wildcard $(sort $(targets)))
0084 
0085 -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) 
0086 
0087 .PHONY: $(PHONY)