mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2024-12-29 17:22:07 +00:00
3216484550
The objects placed at the head of vmlinux need special treatments: - arch/$(SRCARCH)/Makefile adds them to head-y in order to place them before other archives in the linker command line. - arch/$(SRCARCH)/kernel/Makefile adds them to extra-y instead of obj-y to avoid them going into built-in.a. This commit gets rid of the latter. Create vmlinux.a to collect all the objects that are unconditionally linked to vmlinux. The objects listed in head-y are moved to the head of vmlinux.a by using 'ar m'. With this, arch/$(SRCARCH)/kernel/Makefile can consistently use obj-y for builtin objects. There is no *.o that is directly linked to vmlinux. Drop unneeded code in scripts/clang-tools/gen_compile_commands.py. $(AR) mPi needs 'T' to workaround the llvm-ar bug. The fix was suggested by Nathan Chancellor [1]. [1]: https://lore.kernel.org/llvm/YyjjT5gQ2hGMH0ni@dev-arch.thelio-3990X/ Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Tested-by: Nick Desaulniers <ndesaulniers@google.com> Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
81 lines
2.5 KiB
Makefile
81 lines
2.5 KiB
Makefile
# SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
PHONY := __default
|
|
__default: vmlinux.o
|
|
|
|
include include/config/auto.conf
|
|
include $(srctree)/scripts/Kbuild.include
|
|
|
|
# for objtool
|
|
include $(srctree)/scripts/Makefile.lib
|
|
|
|
# Generate a linker script to ensure correct ordering of initcalls for Clang LTO
|
|
# ---------------------------------------------------------------------------
|
|
|
|
quiet_cmd_gen_initcalls_lds = GEN $@
|
|
cmd_gen_initcalls_lds = \
|
|
$(PYTHON3) $(srctree)/scripts/jobserver-exec \
|
|
$(PERL) $(real-prereqs) > $@
|
|
|
|
.tmp_initcalls.lds: $(srctree)/scripts/generate_initcall_order.pl \
|
|
vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE
|
|
$(call if_changed,gen_initcalls_lds)
|
|
|
|
targets := .tmp_initcalls.lds
|
|
|
|
ifdef CONFIG_LTO_CLANG
|
|
initcalls-lds := .tmp_initcalls.lds
|
|
endif
|
|
|
|
# objtool for vmlinux.o
|
|
# ---------------------------------------------------------------------------
|
|
#
|
|
# For LTO and IBT, objtool doesn't run on individual translation units.
|
|
# Run everything on vmlinux instead.
|
|
|
|
objtool-enabled := $(or $(delay-objtool),$(CONFIG_NOINSTR_VALIDATION))
|
|
|
|
vmlinux-objtool-args-$(delay-objtool) += $(objtool-args-y)
|
|
vmlinux-objtool-args-$(CONFIG_GCOV_KERNEL) += --no-unreachable
|
|
vmlinux-objtool-args-$(CONFIG_NOINSTR_VALIDATION) += --noinstr $(if $(CONFIG_CPU_UNRET_ENTRY), --unret)
|
|
|
|
objtool-args = $(vmlinux-objtool-args-y) --link
|
|
|
|
# Link of vmlinux.o used for section mismatch analysis
|
|
# ---------------------------------------------------------------------------
|
|
|
|
quiet_cmd_ld_vmlinux.o = LD $@
|
|
cmd_ld_vmlinux.o = \
|
|
$(LD) ${KBUILD_LDFLAGS} -r -o $@ \
|
|
$(addprefix -T , $(initcalls-lds)) \
|
|
--whole-archive vmlinux.a --no-whole-archive \
|
|
--start-group $(KBUILD_VMLINUX_LIBS) --end-group \
|
|
$(cmd_objtool)
|
|
|
|
define rule_ld_vmlinux.o
|
|
$(call cmd_and_savecmd,ld_vmlinux.o)
|
|
$(call cmd,gen_objtooldep)
|
|
endef
|
|
|
|
vmlinux.o: $(initcalls-lds) vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE
|
|
$(call if_changed_rule,ld_vmlinux.o)
|
|
|
|
targets += vmlinux.o
|
|
|
|
# Add FORCE to the prequisites of a target to force it to be always rebuilt.
|
|
# ---------------------------------------------------------------------------
|
|
|
|
PHONY += FORCE
|
|
FORCE:
|
|
|
|
# Read all saved command lines and dependencies for the $(targets) we
|
|
# may be building above, using $(if_changed{,_dep}). As an
|
|
# optimization, we don't need to read them if the target does not
|
|
# exist, we will rebuild anyway in that case.
|
|
|
|
existing-targets := $(wildcard $(sort $(targets)))
|
|
|
|
-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
|
|
|
|
.PHONY: $(PHONY)
|