|
| 1 | +# SPDX-License-Identifier: GPL-2.0-only |
| 2 | + |
| 3 | +PHONY := __default |
| 4 | +__default: vmlinux.o |
| 5 | + |
| 6 | +include include/config/auto.conf |
| 7 | +include $(srctree)/scripts/Kbuild.include |
| 8 | + |
| 9 | +# Generate a linker script to ensure correct ordering of initcalls for Clang LTO |
| 10 | +# --------------------------------------------------------------------------- |
| 11 | + |
| 12 | +quiet_cmd_gen_initcalls_lds = GEN $@ |
| 13 | + cmd_gen_initcalls_lds = \ |
| 14 | + $(PYTHON3) $(srctree)/scripts/jobserver-exec \ |
| 15 | + $(PERL) $(real-prereqs) > $@ |
| 16 | + |
| 17 | +.tmp_initcalls.lds: $(srctree)/scripts/generate_initcall_order.pl \ |
| 18 | + $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS) FORCE |
| 19 | + $(call if_changed,gen_initcalls_lds) |
| 20 | + |
| 21 | +targets := .tmp_initcalls.lds |
| 22 | + |
| 23 | +ifdef CONFIG_LTO_CLANG |
| 24 | +initcalls-lds := .tmp_initcalls.lds |
| 25 | +endif |
| 26 | + |
| 27 | +# Link of vmlinux.o used for section mismatch analysis |
| 28 | +# --------------------------------------------------------------------------- |
| 29 | + |
| 30 | +quiet_cmd_ld_vmlinux.o = LD $@ |
| 31 | + cmd_ld_vmlinux.o = \ |
| 32 | + $(LD) ${KBUILD_LDFLAGS} -r -o $@ \ |
| 33 | + $(addprefix -T , $(initcalls-lds)) \ |
| 34 | + --whole-archive $(KBUILD_VMLINUX_OBJS) --no-whole-archive \ |
| 35 | + --start-group $(KBUILD_VMLINUX_LIBS) --end-group \ |
| 36 | + |
| 37 | +define rule_ld_vmlinux.o |
| 38 | + $(call cmd_and_savecmd,ld_vmlinux.o) |
| 39 | +endef |
| 40 | + |
| 41 | +vmlinux.o: $(initcalls-lds) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS) FORCE |
| 42 | + $(call if_changed_rule,ld_vmlinux.o) |
| 43 | + |
| 44 | +targets += vmlinux.o |
| 45 | + |
| 46 | +# Add FORCE to the prequisites of a target to force it to be always rebuilt. |
| 47 | +# --------------------------------------------------------------------------- |
| 48 | + |
| 49 | +PHONY += FORCE |
| 50 | +FORCE: |
| 51 | + |
| 52 | +# Read all saved command lines and dependencies for the $(targets) we |
| 53 | +# may be building above, using $(if_changed{,_dep}). As an |
| 54 | +# optimization, we don't need to read them if the target does not |
| 55 | +# exist, we will rebuild anyway in that case. |
| 56 | + |
| 57 | +existing-targets := $(wildcard $(sort $(targets))) |
| 58 | + |
| 59 | +-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) |
| 60 | + |
| 61 | +.PHONY: $(PHONY) |
0 commit comments