[tip: objtool/core] objtool/klp: Add test for selective special section extraction
"tip-bot2 for Puranjay Mohan" <[email protected]>
| Newsgroups | gmane.linux.kernel |
|---|---|
| Message-ID | <178972655318.1720534.16052466813249231193.tip-bot2@tip-bot2> |
The following commit has been merged into the objtool/core branch of tip: Commit-ID: 2b77d5104c9b201709a07a58a31a2944dc325da2 Gitweb: https://git.kernel.org/tip/2b77d5104c9b201709a07a58a31a2944dc325da2 Author: Puranjay Mohan <[email protected]> AuthorDate: Wed, 16 Sep 2026 11:43:11 -07:00 Committer: Josh Poimboeuf <[email protected]> CommitterDate: Wed, 16 Sep 2026 17:13:27 -07:00 objtool/klp: Add test for selective special section extraction Two functions contribute entries to one special section but only one is patched. Cloning the neighbouring entry drags in whatever it points at, which is how a livepatch ends up holding relocations against unrelated code. Signed-off-by: Puranjay Mohan <[email protected]> Assisted-by: Claude:claude-opus-5 Signed-off-by: Song Liu <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Josh Poimboeuf <[email protected]> --- tools/objtool/tests/generic/fixtures/special_section_shared.c | 31 +++++++- tools/objtool/tests/generic/test-special-section-shared.sh | 26 ++++++- 2 files changed, 57 insertions(+) create mode 100644 tools/objtool/tests/generic/fixtures/special_section_shared.c create mode 100755 tools/objtool/tests/generic/test-special-section-shared.sh diff --git a/tools/objtool/tests/generic/fixtures/special_section_shared.c b/tools/objtool/tests/generic/fixtures/special_section_shared.c new file mode 100644 index 0000000..f54e24f --- /dev/null +++ b/tools/objtool/tests/generic/fixtures/special_section_shared.c @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Two functions contribute to one special section; only one is patched. */ + +static const char __modinfo[] + __attribute__((section(".modinfo"), used, aligned(1))) = "\0name=vmlinux"; + +int other(int x) +{ + asm volatile( + "2:\n\t" + ".pushsection .kcfi_traps, \"a\"\n\t" + ".balign 4\n\t" + ".long 2b - .\n\t" + ".popsection\n\t"); + return x * 5; +} + +int target(int x) +{ + asm volatile( + "1:\n\t" + ".pushsection .kcfi_traps, \"a\"\n\t" + ".balign 4\n\t" + ".long 1b - .\n\t" + ".popsection\n\t"); +#ifdef PATCHED + return x + 2; +#else + return x + 1; +#endif +} diff --git a/tools/objtool/tests/generic/test-special-section-shared.sh b/tools/objtool/tests/generic/test-special-section-shared.sh new file mode 100755 index 0000000..05c6110 --- /dev/null +++ b/tools/objtool/tests/generic/test-special-section-shared.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Only the patched function's special section entry may be extracted. + +. "$(dirname "$0")/../lib.sh" + +setup +build_pair special_section_shared.c + +has_input_section orig.o .kcfi_traps || + probe_skip "fixture produced no .kcfi_traps on this arch" + +run_diff + +assert_patched target +assert_not_patched other +assert_section ".kcfi_traps" + +entries="$(out_relocs | awk '/rela\.kcfi_traps/,/^$/' | grep -c 'target')" +[ "$entries" = 1 ] || fail "expected one .kcfi_traps entry, found $entries" + +out_relocs | awk '/rela\.kcfi_traps/,/^$/' | grep -q 'other' && + fail "the untouched function's entry was dragged in" + +pass "only the patched function's entry extracted"