Skip to content

Commit 270ff77

Browse files
committed
Merge: objtool: resolve on-going cmdline arg conflicts
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/3974 JIRA: https://issues.redhat.com/browse/RHEL-2773 The goal of this MR is to bring upstream ("b42d23065024 kbuild: factor out the common objtool arguments") into CS-9 as it's absence has led to on-going conflicts in other backports, specifically whenever a objtool command line argument is add/deprecated. Finally resolve the problem by undoing the RHEL-specific avoidances and backporting the commit and its dependencies. Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com> Approved-by: Chris von Recklinghausen <crecklin@redhat.com> Approved-by: Waiman Long <longman@redhat.com> Approved-by: Prarit Bhargava <prarit@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Lucas Zampieri <lzampier@redhat.com>
2 parents d0d8f9c + b206f54 commit 270ff77

File tree

5 files changed

+129
-194
lines changed

5 files changed

+129
-194
lines changed

scripts/Kbuild.include

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ kecho := $($(quiet)kecho)
7878
# - If the content differ the new file is used
7979
# - If they are equal no change, and no timestamp update
8080
define filechk
81+
$(check-FORCE)
8182
$(Q)set -e; \
8283
mkdir -p $(dir $@); \
8384
trap "rm -f $(dot-target).tmp" EXIT; \
@@ -151,13 +152,21 @@ make-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1))))
151152
# PHONY targets skipped in both cases.
152153
newer-prereqs = $(filter-out $(PHONY),$?)
153154

155+
# It is a typical mistake to forget the FORCE prerequisite. Check it here so
156+
# no more breakage will slip in.
157+
check-FORCE = $(if $(filter FORCE, $^),,$(warning FORCE prerequisite is missing))
158+
159+
if-changed-cond = $(newer-prereqs)$(cmd-check)$(check-FORCE)
160+
154161
# Execute command if command has changed or prerequisite(s) are updated.
155-
if_changed = $(if $(newer-prereqs)$(cmd-check), \
162+
if_changed = $(if $(if-changed-cond),$(cmd_and_savecmd),@:)
163+
164+
cmd_and_savecmd = \
156165
$(cmd); \
157-
printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)
166+
printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd
158167

159168
# Execute the command and also postprocess generated .d dependencies file.
160-
if_changed_dep = $(if $(newer-prereqs)$(cmd-check),$(cmd_and_fixdep),@:)
169+
if_changed_dep = $(if $(if-changed-cond),$(cmd_and_fixdep),@:)
161170

162171
cmd_and_fixdep = \
163172
$(cmd); \
@@ -167,7 +176,7 @@ cmd_and_fixdep = \
167176
# Usage: $(call if_changed_rule,foo)
168177
# Will check if $(cmd_foo) or any of the prerequisites changed,
169178
# and if so will execute $(rule_foo).
170-
if_changed_rule = $(if $(newer-prereqs)$(cmd-check),$(rule_$(1)),@:)
179+
if_changed_rule = $(if $(if-changed-cond),$(rule_$(1)),@:)
171180

172181
###
173182
# why - tell why a target got built

scripts/Makefile.build

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -225,34 +225,6 @@ cmd_record_mcount = $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)),
225225
$(sub_cmd_record_mcount))
226226
endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
227227

228-
ifdef CONFIG_OBJTOOL
229-
230-
objtool := $(objtree)/tools/objtool/objtool
231-
232-
objtool_args = \
233-
$(if $(CONFIG_HAVE_JUMP_LABEL_HACK), --hacks=jump_label) \
234-
$(if $(CONFIG_HAVE_NOINSTR_HACK), --hacks=noinstr) \
235-
$(if $(CONFIG_CALL_DEPTH_TRACKING), --hacks=skylake) \
236-
$(if $(CONFIG_X86_KERNEL_IBT), --ibt) \
237-
$(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \
238-
$(if $(CONFIG_UNWINDER_ORC), --orc) \
239-
$(if $(CONFIG_RETPOLINE), --retpoline) \
240-
$(if $(CONFIG_RETHUNK), --rethunk) \
241-
$(if $(CONFIG_SLS), --sls) \
242-
$(if $(CONFIG_STACK_VALIDATION), --stackval) \
243-
$(if $(CONFIG_HAVE_STATIC_CALL_INLINE), --static-call) \
244-
$(if $(CONFIG_HAVE_UACCESS_VALIDATION), --uaccess) \
245-
$(if $(linked-object), --link) \
246-
$(if $(part-of-module), --module) \
247-
$(if $(CONFIG_GCOV_KERNEL), --no-unreachable) \
248-
$(if $(CONFIG_PREFIX_SYMBOLS), --prefix=$(CONFIG_FUNCTION_PADDING_BYTES)) \
249-
$(if $(CONFIG_FINEIBT), --cfi)
250-
251-
cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@)
252-
cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
253-
254-
endif # CONFIG_OBJTOOL
255-
256228
ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),)
257229

258230
# Skip objtool for LLVM bitcode

scripts/Makefile.lib

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,34 @@ ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),)
246246
mod-prelink-ext := .prelink
247247
endif
248248

249+
ifdef CONFIG_OBJTOOL
250+
251+
objtool := $(objtree)/tools/objtool/objtool
252+
253+
objtool_args = \
254+
$(if $(CONFIG_HAVE_JUMP_LABEL_HACK), --hacks=jump_label) \
255+
$(if $(CONFIG_HAVE_NOINSTR_HACK), --hacks=noinstr) \
256+
$(if $(CONFIG_CALL_DEPTH_TRACKING), --hacks=skylake) \
257+
$(if $(CONFIG_X86_KERNEL_IBT), --ibt) \
258+
$(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \
259+
$(if $(CONFIG_UNWINDER_ORC), --orc) \
260+
$(if $(CONFIG_RETPOLINE), --retpoline) \
261+
$(if $(CONFIG_RETHUNK), --rethunk) \
262+
$(if $(CONFIG_SLS), --sls) \
263+
$(if $(CONFIG_STACK_VALIDATION), --stackval) \
264+
$(if $(CONFIG_HAVE_STATIC_CALL_INLINE), --static-call) \
265+
$(if $(CONFIG_HAVE_UACCESS_VALIDATION), --uaccess) \
266+
$(if $(linked-object), --link) \
267+
$(if $(part-of-module), --module) \
268+
$(if $(CONFIG_GCOV_KERNEL), --no-unreachable) \
269+
$(if $(CONFIG_PREFIX_SYMBOLS), --prefix=$(CONFIG_FUNCTION_PADDING_BYTES)) \
270+
$(if $(CONFIG_FINEIBT), --cfi)
271+
272+
cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@)
273+
cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
274+
275+
endif # CONFIG_OBJTOOL
276+
249277
# Useful for describing the dependency of composite objects
250278
# Usage:
251279
# $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add)

scripts/Makefile.vmlinux_o

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
# for objtool
10+
include $(srctree)/scripts/Makefile.lib
11+
12+
# Generate a linker script to ensure correct ordering of initcalls for Clang LTO
13+
# ---------------------------------------------------------------------------
14+
15+
quiet_cmd_gen_initcalls_lds = GEN $@
16+
cmd_gen_initcalls_lds = \
17+
$(PYTHON3) $(srctree)/scripts/jobserver-exec \
18+
$(PERL) $(real-prereqs) > $@
19+
20+
.tmp_initcalls.lds: $(srctree)/scripts/generate_initcall_order.pl \
21+
$(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS) FORCE
22+
$(call if_changed,gen_initcalls_lds)
23+
24+
targets := .tmp_initcalls.lds
25+
26+
ifdef CONFIG_LTO_CLANG
27+
initcalls-lds := .tmp_initcalls.lds
28+
endif
29+
30+
# objtool for vmlinux.o
31+
# ---------------------------------------------------------------------------
32+
#
33+
# For LTO and IBT, objtool doesn't run on individual translation units.
34+
# Run everything on vmlinux instead.
35+
36+
objtool-enabled := $(or $(delay-objtool),$(CONFIG_NOINSTR_VALIDATION))
37+
38+
# Reuse objtool_args defined in scripts/Makefile.lib if LTO or IBT is enabled.
39+
#
40+
# Add some more flags as needed.
41+
# --no-unreachable and --link might be added twice, but it is fine.
42+
#
43+
# Expand objtool_args to a simple variable to avoid circular reference.
44+
45+
objtool_args := \
46+
$(if $(delay-objtool),$(objtool_args)) \
47+
$(if $(CONFIG_NOINSTR_VALIDATION), --noinstr $(if $(or $(CONFIG_CPU_UNRET_ENTRY),$(CONFIG_CPU_SRSO)), --unret)) \
48+
$(if $(CONFIG_GCOV_KERNEL), --no-unreachable) \
49+
--link
50+
51+
# Link of vmlinux.o used for section mismatch analysis
52+
# ---------------------------------------------------------------------------
53+
54+
quiet_cmd_ld_vmlinux.o = LD $@
55+
cmd_ld_vmlinux.o = \
56+
$(LD) ${KBUILD_LDFLAGS} -r -o $@ \
57+
$(addprefix -T , $(initcalls-lds)) \
58+
--whole-archive $(KBUILD_VMLINUX_OBJS) --no-whole-archive \
59+
--start-group $(KBUILD_VMLINUX_LIBS) --end-group \
60+
$(cmd_objtool)
61+
62+
define rule_ld_vmlinux.o
63+
$(call cmd_and_savecmd,ld_vmlinux.o)
64+
$(call cmd,gen_objtooldep)
65+
endef
66+
67+
vmlinux.o: $(initcalls-lds) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS) FORCE
68+
$(call if_changed_rule,ld_vmlinux.o)
69+
70+
targets += vmlinux.o
71+
72+
# Add FORCE to the prequisites of a target to force it to be always rebuilt.
73+
# ---------------------------------------------------------------------------
74+
75+
PHONY += FORCE
76+
FORCE:
77+
78+
# Read all saved command lines and dependencies for the $(targets) we
79+
# may be building above, using $(if_changed{,_dep}). As an
80+
# optimization, we don't need to read them if the target does not
81+
# exist, we will rebuild anyway in that case.
82+
83+
existing-targets := $(wildcard $(sort $(targets)))
84+
85+
-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
86+
87+
.PHONY: $(PHONY)

scripts/link-vmlinux.sh

Lines changed: 1 addition & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -52,164 +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-
113-
objtool_link()
114-
{
115-
local objtoolcmd;
116-
local objtoolopt;
117-
118-
if ! is_enabled CONFIG_OBJTOOL; then
119-
return;
120-
fi
121-
122-
# RHEL-only workaround for missing upstream b42d23065024
123-
# ("kbuild: factor out the common objtool arguments"), objtool
124-
# is only enabled for vmlinux.o under the following conditions:
125-
#
126-
# scripts/Makefile.lib
127-
# delay-objtool := $(or $(CONFIG_LTO_CLANG),$(CONFIG_X86_KERNEL_IBT))
128-
#
129-
# scripts/Makefile.vmlinux_o
130-
# objtool-enabled := $(or $(delay-objtool),$(CONFIG_NOINSTR_VALIDATION))
131-
if ! (is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IBT || is_enabled CONFIG_NOINSTR_VALIDATION); then
132-
return
133-
fi
134-
135-
if is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IBT; then
136-
137-
# For LTO and IBT, objtool doesn't run on individual
138-
# translation units. Run everything on vmlinux instead.
139-
140-
if is_enabled CONFIG_HAVE_JUMP_LABEL_HACK; then
141-
objtoolopt="${objtoolopt} --hacks=jump_label"
142-
fi
143-
144-
if is_enabled CONFIG_HAVE_NOINSTR_HACK; then
145-
objtoolopt="${objtoolopt} --hacks=noinstr"
146-
fi
147-
148-
if is_enabled CONFIG_CALL_DEPTH_TRACKING; then
149-
objtoolopt="${objtoolopt} --hacks=skylake"
150-
fi
151-
152-
if is_enabled CONFIG_X86_KERNEL_IBT; then
153-
objtoolopt="${objtoolopt} --ibt"
154-
fi
155-
156-
if is_enabled CONFIG_FTRACE_MCOUNT_USE_OBJTOOL; then
157-
objtoolopt="${objtoolopt} --mcount"
158-
fi
159-
160-
if is_enabled CONFIG_FTRACE_MCOUNT_USE_OBJTOOL; then
161-
objtoolopt="${objtoolopt} --mnop"
162-
fi
163-
164-
if is_enabled CONFIG_UNWINDER_ORC; then
165-
objtoolopt="${objtoolopt} --orc"
166-
fi
167-
168-
if is_enabled CONFIG_RETPOLINE; then
169-
objtoolopt="${objtoolopt} --retpoline"
170-
fi
171-
172-
if is_enabled CONFIG_SLS; then
173-
objtoolopt="${objtoolopt} --sls"
174-
fi
175-
176-
if is_enabled CONFIG_STACK_VALIDATION; then
177-
objtoolopt="${objtoolopt} --stackval"
178-
fi
179-
180-
if is_enabled CONFIG_HAVE_STATIC_CALL_INLINE; then
181-
objtoolopt="${objtoolopt} --static-call"
182-
fi
183-
184-
if is_enabled CONFIG_HAVE_UACCESS_VALIDATION; then
185-
objtoolopt="${objtoolopt} --uaccess"
186-
fi
187-
fi
188-
189-
if is_enabled CONFIG_NOINSTR_VALIDATION; then
190-
objtoolopt="${objtoolopt} --noinstr"
191-
if is_enabled CONFIG_CPU_UNRET_ENTRY || is_enabled CONFIG_CPU_SRSO; then
192-
objtoolopt="${objtoolopt} --unret"
193-
fi
194-
fi
195-
196-
if is_enabled CONFIG_PREFIX_SYMBOLS; then
197-
objtoolopt="${objtoolopt} --prefix=$(config_value "CONFIG_FUNCTION_PADDING_BYTES")"
198-
fi
199-
200-
if [ -n "${objtoolopt}" ]; then
201-
202-
if is_enabled CONFIG_GCOV_KERNEL; then
203-
objtoolopt="${objtoolopt} --no-unreachable"
204-
fi
205-
206-
objtoolopt="${objtoolopt} --link"
207-
208-
info OBJTOOL ${1}
209-
tools/objtool/objtool ${objtoolopt} ${1}
210-
fi
211-
}
212-
21355
# Link of vmlinux
21456
# ${1} - output file
21557
# ${2}, ${3}, ... - optional extra .o files
@@ -371,8 +213,6 @@ cleanup()
371213
rm -f System.map
372214
rm -f vmlinux
373215
rm -f vmlinux.map
374-
rm -f vmlinux.o
375-
rm -f .vmlinux.d
376216
}
377217

378218
# Use "make V=1" to debug this script
@@ -401,8 +241,7 @@ fi;
401241
${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init need-builtin=1
402242

403243
#link vmlinux.o
404-
modpost_link vmlinux.o
405-
objtool_link vmlinux.o
244+
${MAKE} -f "${srctree}/scripts/Makefile.vmlinux_o"
406245

407246
# modpost vmlinux.o to check for section mismatches
408247
${MAKE} -f "${srctree}/scripts/Makefile.modpost" MODPOST_VMLINUX=1

0 commit comments

Comments
 (0)