objtool/klp: Add test for special section extraction

create_fake_symbols() gives each special section entry a symbol so entries
can be extracted individually.  Entries with ANNOTATE_DATA_SPECIAL are
handled first; the rest have their boundaries derived from the entry or
relocation size.

The second pass has to key off whether the first one created symbols, not
off whether the section already has something at offset 0.  Clang puts an
assembler-local label at the start of .kcfi_traps, and treating that as
already handled means nothing is extracted: klp diff still reports the
changed function and succeeds, but the special section is missing from the
module.

The fixture reproduces the shape without needing CFI or x86.

Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
Signed-off-by: Song Liu <song@kernel.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Assisted-by: Claude:claude-opus-5
Link: https://patch.msgid.link/20260916184351.2720310-18-song@kernel.org
This commit is contained in:
Puranjay Mohan 2026-09-16 11:43:10 -07:00 committed by Ingo Molnar
parent 76e7630d90
commit 996edd14fb
2 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,24 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Special section entry with no ANNOTATE_DATA_SPECIAL annotation and a local
* label at offset 0, the shape Clang produces for .kcfi_traps.
*/
static const char __modinfo[]
__attribute__((section(".modinfo"), used, aligned(1))) = "\0name=vmlinux";
int target(int x)
{
asm volatile(
"1:\n\t"
".pushsection .kcfi_traps, \"a\"\n\t"
".balign 4\n\t"
"trap_marker:\n\t"
".long 1b - .\n\t"
".popsection\n\t");
#ifdef PATCHED
return x + 2;
#else
return x + 1;
#endif
}

View File

@ -0,0 +1,20 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# A .kcfi_traps entry belonging to a patched function must be extracted even
# without ANNOTATE_DATA_SPECIAL and with a local label already at offset 0.
. "$(dirname "$0")/../lib.sh"
setup
build_pair special_section.c
in_symbols orig.o | grep -q 'trap_marker' ||
probe_skip "fixture produced no .kcfi_traps on this arch"
run_diff
assert_patched target
assert_section ".kcfi_traps"
pass ".kcfi_traps extracted despite a local label at offset 0"