2022-05-28 18:47:03 +03:00
# SPDX-License-Identifier: GPL-2.0-only
PHONY := __default
__default : vmlinux .o
i n c l u d e i n c l u d e / c o n f i g / a u t o . c o n f
i n c l u d e $( srctree ) / s c r i p t s / K b u i l d . i n c l u d e
2022-05-28 18:47:04 +03:00
# for objtool
i n c l u d e $( srctree ) / s c r i p t s / M a k e f i l e . l i b
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 \
$( KBUILD_VMLINUX_OBJS) $( KBUILD_VMLINUX_LIBS) FORCE
$( call if_changed,gen_initcalls_lds)
targets := .tmp_initcalls.lds
i f d e f C O N F I G _ L T O _ C L A N G
initcalls-lds := .tmp_initcalls.lds
e n d i f
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) )
# Reuse objtool_args defined in scripts/Makefile.lib if LTO or IBT is enabled.
#
# Add some more flags as needed.
# --no-unreachable and --link might be added twice, but it is fine.
#
# Expand objtool_args to a simple variable to avoid circular reference.
objtool_args := \
$( if $( delay-objtool) ,$( objtool_args) ) \
$( if $( CONFIG_NOINSTR_VALIDATION) , --noinstr) \
$( if $( CONFIG_GCOV_KERNEL) , --no-unreachable) \
--link
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) ) \
--whole-archive $( KBUILD_VMLINUX_OBJS) --no-whole-archive \
--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
d e f i n e r u l e _ l d _ v m l i n u x . 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
e n d e f
vmlinux.o : $( initcalls -lds ) $( KBUILD_VMLINUX_OBJS ) $( 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) ) )
- i n c l u d e $( foreach f ,$ ( existing -targets ) ,$ ( dir $ ( f ) ) .$ ( notdir $ ( f ) ) .cmd )
.PHONY : $( PHONY )