Skip to content

Commit 5d45950

Browse files
committed
kbuild: move vmlinux.o link to scripts/Makefile.vmlinux_o
This is a preparation for moving the objtool rule in the next commit. Signed-off-by: Masahiro Yamada <[email protected]> Tested-by: Sedat Dilek <[email protected]> # LLVM-14 (x86-64)
1 parent b0d6207 commit 5d45950

File tree

2 files changed

+62
-40
lines changed

2 files changed

+62
-40
lines changed

scripts/Makefile.vmlinux_o

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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)

scripts/link-vmlinux.sh

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -45,45 +45,6 @@ info()
4545
printf " %-7s %s\n" "${1}" "${2}"
4646
}
4747

48-
# Generate a linker script to ensure correct ordering of initcalls.
49-
gen_initcalls()
50-
{
51-
info GEN .tmp_initcalls.lds
52-
53-
${PYTHON3} ${srctree}/scripts/jobserver-exec \
54-
${PERL} ${srctree}/scripts/generate_initcall_order.pl \
55-
${KBUILD_VMLINUX_OBJS} ${KBUILD_VMLINUX_LIBS} \
56-
> .tmp_initcalls.lds
57-
}
58-
59-
# Link of vmlinux.o used for section mismatch analysis
60-
# ${1} output file
61-
modpost_link()
62-
{
63-
local objects
64-
local lds=""
65-
66-
objects="--whole-archive \
67-
${KBUILD_VMLINUX_OBJS} \
68-
--no-whole-archive \
69-
--start-group \
70-
${KBUILD_VMLINUX_LIBS} \
71-
--end-group"
72-
73-
if is_enabled CONFIG_LTO_CLANG; then
74-
gen_initcalls
75-
lds="-T .tmp_initcalls.lds"
76-
77-
# This might take a while, so indicate that we're doing
78-
# an LTO link
79-
info LTO ${1}
80-
else
81-
info LD ${1}
82-
fi
83-
84-
${LD} ${KBUILD_LDFLAGS} -r -o ${1} ${lds} ${objects}
85-
}
86-
8748
objtool_link()
8849
{
8950
local objtoolcmd;
@@ -336,7 +297,7 @@ fi;
336297
${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init need-builtin=1
337298

338299
#link vmlinux.o
339-
modpost_link vmlinux.o
300+
${MAKE} -f "${srctree}/scripts/Makefile.vmlinux_o"
340301
objtool_link vmlinux.o
341302

342303
# Generate the list of in-tree objects in vmlinux

0 commit comments

Comments
 (0)