Skip to content

Commit b206f54

Browse files
committed
kbuild: factor out the common objtool arguments
JIRA: https://issues.redhat.com/browse/RHEL-2773 Conflicts: scripts/Makefile.build scripts/Makefile.lib scripts/link-vmlinux.sh - Undo previous RHEL-only conflict workarounds in these files from cs-9 commits that avoided this backport: - 69cd8c6 ("x86: Add prefix symbols for function padding") - 2354000 ("objtool: Add entry UNRET validation") - 73afd5e ("objtool: Add --hacks=skylake") - 21de65c ("x86/ibt: Implement FineIBT") - af8931b ("kbuild: Fixup the IBT kbuild changes") - eeb9f34 ("x86/srso: Fix unret validation dependencies") scripts/Makefile.vmlinux_o - cs-9 is doesn't have 9ec6ab6 ("kbuild: use objtool-args-y to clean up objtool arguments"), add CONFIG_CPU_SRSO check to objtool_args and not vmlinux-objtool-args commit b42d230 Author: Masahiro Yamada <masahiroy@kernel.org> Date: Sun May 29 00:47:04 2022 +0900 kbuild: factor out the common objtool arguments scripts/Makefile.build and scripts/link-vmlinux.sh have similar setups for the objtool arguments. It was difficult to factor out them because all the vmlinux build rules were written in a shell script. It is somewhat tedious to touch the two files every time a new objtool option is supported. To reduce the code duplication, move the objtool for vmlinux.o into scripts/Makefile.vmlinux_o. Then, move the common macros to Makefile.lib so they are shared between Makefile.build and Makefile.vmlinux_o. 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 05c520e commit b206f54

File tree

4 files changed

+54
-129
lines changed

4 files changed

+54
-129
lines changed

scripts/Makefile.build

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

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

262234
# 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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ __default: vmlinux.o
66
include include/config/auto.conf
77
include $(srctree)/scripts/Kbuild.include
88

9+
# for objtool
10+
include $(srctree)/scripts/Makefile.lib
11+
912
# Generate a linker script to ensure correct ordering of initcalls for Clang LTO
1013
# ---------------------------------------------------------------------------
1114

@@ -24,6 +27,27 @@ ifdef CONFIG_LTO_CLANG
2427
initcalls-lds := .tmp_initcalls.lds
2528
endif
2629

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+
2751
# Link of vmlinux.o used for section mismatch analysis
2852
# ---------------------------------------------------------------------------
2953

@@ -33,9 +57,11 @@ quiet_cmd_ld_vmlinux.o = LD $@
3357
$(addprefix -T , $(initcalls-lds)) \
3458
--whole-archive $(KBUILD_VMLINUX_OBJS) --no-whole-archive \
3559
--start-group $(KBUILD_VMLINUX_LIBS) --end-group \
60+
$(cmd_objtool)
3661

3762
define rule_ld_vmlinux.o
3863
$(call cmd_and_savecmd,ld_vmlinux.o)
64+
$(call cmd,gen_objtooldep)
3965
endef
4066

4167
vmlinux.o: $(initcalls-lds) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS) FORCE

scripts/link-vmlinux.sh

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -52,106 +52,6 @@ info()
5252
printf " %-7s %s\n" "${1}" "${2}"
5353
}
5454

55-
objtool_link()
56-
{
57-
local objtoolcmd;
58-
local objtoolopt;
59-
60-
if ! is_enabled CONFIG_OBJTOOL; then
61-
return;
62-
fi
63-
64-
# RHEL-only workaround for missing upstream b42d23065024
65-
# ("kbuild: factor out the common objtool arguments"), objtool
66-
# is only enabled for vmlinux.o under the following conditions:
67-
#
68-
# scripts/Makefile.lib
69-
# delay-objtool := $(or $(CONFIG_LTO_CLANG),$(CONFIG_X86_KERNEL_IBT))
70-
#
71-
# scripts/Makefile.vmlinux_o
72-
# objtool-enabled := $(or $(delay-objtool),$(CONFIG_NOINSTR_VALIDATION))
73-
if ! (is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IBT || is_enabled CONFIG_NOINSTR_VALIDATION); then
74-
return
75-
fi
76-
77-
if is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IBT; then
78-
79-
# For LTO and IBT, objtool doesn't run on individual
80-
# translation units. Run everything on vmlinux instead.
81-
82-
if is_enabled CONFIG_HAVE_JUMP_LABEL_HACK; then
83-
objtoolopt="${objtoolopt} --hacks=jump_label"
84-
fi
85-
86-
if is_enabled CONFIG_HAVE_NOINSTR_HACK; then
87-
objtoolopt="${objtoolopt} --hacks=noinstr"
88-
fi
89-
90-
if is_enabled CONFIG_CALL_DEPTH_TRACKING; then
91-
objtoolopt="${objtoolopt} --hacks=skylake"
92-
fi
93-
94-
if is_enabled CONFIG_X86_KERNEL_IBT; then
95-
objtoolopt="${objtoolopt} --ibt"
96-
fi
97-
98-
if is_enabled CONFIG_FTRACE_MCOUNT_USE_OBJTOOL; then
99-
objtoolopt="${objtoolopt} --mcount"
100-
fi
101-
102-
if is_enabled CONFIG_FTRACE_MCOUNT_USE_OBJTOOL; then
103-
objtoolopt="${objtoolopt} --mnop"
104-
fi
105-
106-
if is_enabled CONFIG_UNWINDER_ORC; then
107-
objtoolopt="${objtoolopt} --orc"
108-
fi
109-
110-
if is_enabled CONFIG_RETPOLINE; then
111-
objtoolopt="${objtoolopt} --retpoline"
112-
fi
113-
114-
if is_enabled CONFIG_SLS; then
115-
objtoolopt="${objtoolopt} --sls"
116-
fi
117-
118-
if is_enabled CONFIG_STACK_VALIDATION; then
119-
objtoolopt="${objtoolopt} --stackval"
120-
fi
121-
122-
if is_enabled CONFIG_HAVE_STATIC_CALL_INLINE; then
123-
objtoolopt="${objtoolopt} --static-call"
124-
fi
125-
126-
if is_enabled CONFIG_HAVE_UACCESS_VALIDATION; then
127-
objtoolopt="${objtoolopt} --uaccess"
128-
fi
129-
fi
130-
131-
if is_enabled CONFIG_NOINSTR_VALIDATION; then
132-
objtoolopt="${objtoolopt} --noinstr"
133-
if is_enabled CONFIG_CPU_UNRET_ENTRY || is_enabled CONFIG_CPU_SRSO; then
134-
objtoolopt="${objtoolopt} --unret"
135-
fi
136-
fi
137-
138-
if is_enabled CONFIG_PREFIX_SYMBOLS; then
139-
objtoolopt="${objtoolopt} --prefix=$(config_value "CONFIG_FUNCTION_PADDING_BYTES")"
140-
fi
141-
142-
if [ -n "${objtoolopt}" ]; then
143-
144-
if is_enabled CONFIG_GCOV_KERNEL; then
145-
objtoolopt="${objtoolopt} --no-unreachable"
146-
fi
147-
148-
objtoolopt="${objtoolopt} --link"
149-
150-
info OBJTOOL ${1}
151-
tools/objtool/objtool ${objtoolopt} ${1}
152-
fi
153-
}
154-
15555
# Link of vmlinux
15656
# ${1} - output file
15757
# ${2}, ${3}, ... - optional extra .o files
@@ -342,7 +242,6 @@ ${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init need-builtin=1
342242

343243
#link vmlinux.o
344244
${MAKE} -f "${srctree}/scripts/Makefile.vmlinux_o"
345-
objtool_link vmlinux.o
346245

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

0 commit comments

Comments
 (0)