2022-05-28 18:47:03 +03:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
|
|
|
PHONY := __default
|
2022-09-28 09:39:40 +03:00
|
|
|
__default: vmlinux.o modules.builtin.modinfo modules.builtin
|
2022-05-28 18:47:03 +03:00
|
|
|
|
|
|
|
include include/config/auto.conf
|
|
|
|
include $(srctree)/scripts/Kbuild.include
|
|
|
|
|
2022-05-28 18:47:04 +03:00
|
|
|
# for objtool
|
|
|
|
include $(srctree)/scripts/Makefile.lib
|
|
|
|
|
2022-05-28 18:47:03 +03:00
|
|
|
# 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 \
|
2022-09-24 21:19:14 +03:00
|
|
|
vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE
|
2022-05-28 18:47:03 +03:00
|
|
|
$(call if_changed,gen_initcalls_lds)
|
|
|
|
|
|
|
|
targets := .tmp_initcalls.lds
|
|
|
|
|
|
|
|
ifdef CONFIG_LTO_CLANG
|
|
|
|
initcalls-lds := .tmp_initcalls.lds
|
|
|
|
endif
|
|
|
|
|
2022-05-28 18:47:04 +03:00
|
|
|
# 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))
|
|
|
|
|
2022-09-06 21:49:35 +03:00
|
|
|
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)
|
2022-05-28 18:47:04 +03:00
|
|
|
|
2022-09-06 21:49:35 +03:00
|
|
|
objtool-args = $(vmlinux-objtool-args-y) --link
|
2022-05-28 18:47:04 +03:00
|
|
|
|
2022-05-28 18:47:03 +03:00
|
|
|
# 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)) \
|
2022-09-24 21:19:14 +03:00
|
|
|
--whole-archive vmlinux.a --no-whole-archive \
|
2022-05-28 18:47:03 +03:00
|
|
|
--start-group $(KBUILD_VMLINUX_LIBS) --end-group \
|
2022-05-28 18:47:04 +03:00
|
|
|
$(cmd_objtool)
|
2022-05-28 18:47:03 +03:00
|
|
|
|
|
|
|
define rule_ld_vmlinux.o
|
|
|
|
$(call cmd_and_savecmd,ld_vmlinux.o)
|
2022-05-28 18:47:04 +03:00
|
|
|
$(call cmd,gen_objtooldep)
|
2022-05-28 18:47:03 +03:00
|
|
|
endef
|
|
|
|
|
2022-09-24 21:19:14 +03:00
|
|
|
vmlinux.o: $(initcalls-lds) vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE
|
2022-05-28 18:47:03 +03:00
|
|
|
$(call if_changed_rule,ld_vmlinux.o)
|
|
|
|
|
|
|
|
targets += vmlinux.o
|
|
|
|
|
2022-09-28 09:39:40 +03:00
|
|
|
# module.builtin.modinfo
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
OBJCOPYFLAGS_modules.builtin.modinfo := -j .modinfo -O binary
|
|
|
|
|
|
|
|
targets += modules.builtin.modinfo
|
|
|
|
modules.builtin.modinfo: vmlinux.o FORCE
|
|
|
|
$(call if_changed,objcopy)
|
|
|
|
|
|
|
|
# module.builtin
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# The second line aids cases where multiple modules share the same object.
|
|
|
|
|
|
|
|
quiet_cmd_modules_builtin = GEN $@
|
|
|
|
cmd_modules_builtin = \
|
|
|
|
tr '\0' '\n' < $< | \
|
|
|
|
sed -n 's/^[[:alnum:]:_]*\.file=//p' | \
|
|
|
|
tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$$/.ko/' > $@
|
|
|
|
|
|
|
|
targets += modules.builtin
|
|
|
|
modules.builtin: modules.builtin.modinfo FORCE
|
|
|
|
$(call if_changed,modules_builtin)
|
|
|
|
|
2022-05-28 18:47:03 +03:00
|
|
|
# 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)
|