Skip to content

Commit 69cd8c6

Browse files
committed
x86: Add prefix symbols for function padding
JIRA: https://issues.redhat.com/browse/RHEL-255 Conflicts: scripts/Makefile.lib - cs-9 doesn't have b42d230 ("kbuild: factor out the common objtool arguments") or 9ec6ab6 ("kbuild: use objtool-args-y to clean up objtool arguments"), which moved moved objtool_args from scripts/Makefile.build and objtooltopt from scripts/link-vmlinux.sh to scripts/Makefile.lib. Add the --prefix option to both of former files instead. At the same time, provide scripts/link-vmlinux.sh workarounds to read the CONFIG_FUNCTION_PADDING_BYTES value and only enable objtool for vmlinux.o given the same configuration conditions in b42d230. commit b341b20 Author: Peter Zijlstra <peterz@infradead.org> Date: Fri Oct 28 21:08:19 2022 +0200 x86: Add prefix symbols for function padding When code is compiled with: -fpatchable-function-entry=${PADDING_BYTES},${PADDING_BYTES} functions will have PADDING_BYTES of NOP in front of them. Unwinders and other things that symbolize code locations will typically attribute these bytes to the preceding function. Given that these bytes nominally belong to the following symbol this mis-attribution is confusing. Inspired by the fact that CFI_CLANG emits __cfi_##name symbols to claim these bytes, use objtool to emit __pfx_##name symbols to do the same when CFI_CLANG is not used. This then shows the callthunk for symbol 'name' as: __pfx_##name+0x6/0x10 Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Tested-by: Yujie Liu <yujie.liu@intel.com> Link: https://lkml.kernel.org/r/20221028194453.592512209@infradead.org Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
1 parent 6541539 commit 69cd8c6

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

arch/x86/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,6 +2484,10 @@ config CALL_THUNKS
24842484
def_bool n
24852485
select FUNCTION_ALIGNMENT_16B
24862486

2487+
config PREFIX_SYMBOLS
2488+
def_bool y
2489+
depends on CALL_THUNKS && !CFI_CLANG
2490+
24872491
menuconfig SPECULATION_MITIGATIONS
24882492
bool "Mitigations for speculative execution vulnerabilities"
24892493
default y

scripts/Makefile.build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ objtool_args = \
247247
$(if $(CONFIG_X86_SMAP), --uaccess) \
248248
$(if $(linked-object), --link) \
249249
$(if $(part-of-module), --module) \
250-
$(if $(CONFIG_GCOV_KERNEL), --no-unreachable)
250+
$(if $(CONFIG_GCOV_KERNEL), --no-unreachable) \
251+
$(if $(CONFIG_PREFIX_SYMBOLS), --prefix=$(CONFIG_FUNCTION_PADDING_BYTES))
251252

252253
cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@)
253254
cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)

scripts/link-vmlinux.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ is_enabled() {
3838
grep -q "^$1=y" include/config/auto.conf
3939
}
4040

41+
# RHEL-only workaround for missing upstream b42d23065024
42+
# ("kbuild: factor out the common objtool arguments"), provide a means
43+
# to read configuration values for a key like CONFIG_FUNCTION_PADDING_BYTES
44+
config_value() {
45+
gawk -vkey="$1" -F= '$1==key{ print $NF }' include/config/auto.conf 2>/dev/null
46+
}
47+
4148
# Nice output in kbuild format
4249
# Will be supressed by "make -s"
4350
info()
@@ -112,6 +119,19 @@ objtool_link()
112119
return;
113120
fi
114121

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+
115135
if is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IBT; then
116136

117137
# For LTO and IBT, objtool doesn't run on individual
@@ -165,6 +185,10 @@ objtool_link()
165185
fi
166186
fi
167187

188+
if is_enabled CONFIG_PREFIX_SYMBOLS; then
189+
objtoolopt="${objtoolopt} --prefix=$(config_value "CONFIG_FUNCTION_PADDING_BYTES")"
190+
fi
191+
168192
if [ -n "${objtoolopt}" ]; then
169193

170194
if is_enabled CONFIG_GCOV_KERNEL; then

0 commit comments

Comments
 (0)