Skip to content

Commit 05c520e

Browse files
committed
kbuild: move vmlinux.o link to scripts/Makefile.vmlinux_o
JIRA: https://issues.redhat.com/browse/RHEL-2773 Conflicts: scripts/link-vmlinux.sh - cs-9 is missing upstream commit 7375cbc ("kbuild: stop merging *.symversions") and related modpost enhancements. That said, cs-9 doesn't support CONFIG_LTO_CLANG, so it's only deadcode either way. Remove it from this file and push it off to a future merge conflict resolution should lto/clang become a requirement. commit 5d45950 Author: Masahiro Yamada <masahiroy@kernel.org> Date: Sun May 29 00:47:03 2022 +0900 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 <masahiroy@kernel.org> Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64) Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
1 parent e84b28f commit 05c520e

File tree

2 files changed

+62
-59
lines changed

2 files changed

+62
-59
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 & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -52,64 +52,6 @@ info()
5252
printf " %-7s %s\n" "${1}" "${2}"
5353
}
5454

55-
# Generate a linker script to ensure correct ordering of initcalls.
56-
gen_initcalls()
57-
{
58-
info GEN .tmp_initcalls.lds
59-
60-
${PYTHON3} ${srctree}/scripts/jobserver-exec \
61-
${PERL} ${srctree}/scripts/generate_initcall_order.pl \
62-
${KBUILD_VMLINUX_OBJS} ${KBUILD_VMLINUX_LIBS} \
63-
> .tmp_initcalls.lds
64-
}
65-
66-
# If CONFIG_LTO_CLANG is selected, collect generated symbol versions into
67-
# .tmp_symversions.lds
68-
gen_symversions()
69-
{
70-
info GEN .tmp_symversions.lds
71-
rm -f .tmp_symversions.lds
72-
73-
for o in ${KBUILD_VMLINUX_OBJS} ${KBUILD_VMLINUX_LIBS}; do
74-
if [ -f ${o}.symversions ]; then
75-
cat ${o}.symversions >> .tmp_symversions.lds
76-
fi
77-
done
78-
}
79-
80-
# Link of vmlinux.o used for section mismatch analysis
81-
# ${1} output file
82-
modpost_link()
83-
{
84-
local objects
85-
local lds=""
86-
87-
objects="--whole-archive \
88-
${KBUILD_VMLINUX_OBJS} \
89-
--no-whole-archive \
90-
--start-group \
91-
${KBUILD_VMLINUX_LIBS} \
92-
--end-group"
93-
94-
if is_enabled CONFIG_LTO_CLANG; then
95-
gen_initcalls
96-
lds="-T .tmp_initcalls.lds"
97-
98-
if is_enabled CONFIG_MODVERSIONS; then
99-
gen_symversions
100-
lds="${lds} -T .tmp_symversions.lds"
101-
fi
102-
103-
# This might take a while, so indicate that we're doing
104-
# an LTO link
105-
info LTO ${1}
106-
else
107-
info LD ${1}
108-
fi
109-
110-
${LD} ${KBUILD_LDFLAGS} -r -o ${1} ${lds} ${objects}
111-
}
112-
11355
objtool_link()
11456
{
11557
local objtoolcmd;
@@ -399,7 +341,7 @@ fi;
399341
${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init need-builtin=1
400342

401343
#link vmlinux.o
402-
modpost_link vmlinux.o
344+
${MAKE} -f "${srctree}/scripts/Makefile.vmlinux_o"
403345
objtool_link vmlinux.o
404346

405347
# modpost vmlinux.o to check for section mismatches

0 commit comments

Comments
 (0)