[PATCH] objtool/klp: Build x86 test fixtures with -fcf-protection=none

From: Seke Kazuru

Date: Tue Dec 01 2026 - 10:17:49 EST


x86 kernels always choose -fcf-protection themselves: =branch with
CONFIG_X86_KERNEL_IBT, =none without (arch/x86/Makefile). The test
fixtures pass neither, so they get the compiler's default, and Ubuntu's
gcc defaults to =full. That puts an ENDBR at the start of a global
function but not of a static one, so a patch which only changes a
function's linkage changes its code.

test-local-to-global-flip makes exactly that change and fails with
Ubuntu's gcc 11 to 14: flipped_up gains an ENDBR, klp diff rightly
reports it as changed and clones it, and the test, which expects it to
be correlated, fails.

Build the fixtures for the kernel without IBT, as the kernel would. A
test about IBT can still override it.

Verified with Ubuntu gcc 11, 13 and 14, Debian gcc 16 and Clang 18 and
23: test-local-to-global-flip fails on the three Ubuntu compilers before
this change and passes after it, and no other test changes on any of
the six.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Seke Kazuru <kazuruuni@xxxxxxxxx>
---
tools/objtool/tests/lib.sh | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/tools/objtool/tests/lib.sh b/tools/objtool/tests/lib.sh
index 4da168d0dd..41048960f8 100644
--- a/tools/objtool/tests/lib.sh
+++ b/tools/objtool/tests/lib.sh
@@ -153,6 +153,15 @@ EOF
FIXTURE_CFLAGS="-O2 -ffunction-sections -fdata-sections -fno-common \
-fno-asynchronous-unwind-tables"

+# x86 kernels always choose -fcf-protection themselves (arch/x86/Makefile):
+# =branch with CONFIG_X86_KERNEL_IBT, =none without. A compiler's default never
+# reaches kernel code, and some distributions' gcc defaults to =full, which puts
+# an ENDBR at the start of a global function but not of a static one -- so a
+# patch which only changes a function's linkage would change its code. Stand
+# in for the kernel without IBT; a test about IBT overrides it.
+[ "$KLP_TEST_ARCH" != x86 ] ||
+ FIXTURE_CFLAGS="$FIXTURE_CFLAGS -fcf-protection=none"
+
test_name="$(basename "$0" .sh)"
workdir=

--
2.43.0