diff options
| author | Puranjay Mohan <puranjay@kernel.org> | 2026-09-16 11:43:17 -0700 |
|---|---|---|
| committer | Ingo Molnar <mingo@kernel.org> | 2026-09-21 11:05:27 +0200 |
| commit | 7fd24723f1601340ee09bca93989bd1fb4515783 (patch) | |
| tree | fc2324548ed71393ab89f98a8897ca4ae67a4045 /tools/objtool/tests/generic/fixtures/thinlto_local.c | |
| parent | d6f2548ec3508fac9ad0f2a7d6f4783f9f9cd119 (diff) | |
| download | linux-next-7fd24723f1601340ee09bca93989bd1fb4515783.tar.gz linux-next-7fd24723f1601340ee09bca93989bd1fb4515783.zip | |
objtool/klp: Add test for correlation across ThinLTO name mangling
ThinLTO promotes the file-local symbols an imported function touches,
renaming them name.llvm.<hash>. The hash is content derived, so it changes
whenever the module does:
original: counter.llvm.13663304415433785070
patched: counter.llvm.10543383937958011340
Correlating the two objects therefore requires demangling the suffix;
matching raw names would see two unrelated symbols and treat the variable
as new.
The resulting klp relocation also has to name the original symbol, since
that is the one in the running kernel's kallsyms. Naming the patched
build's symbol produces a relocation which can never be resolved.
ThinLTO is a clang feature, so the test declares itself clang-only. It
also needs an lld from the same LLVM release as $CC; a mismatched pair
fails with "Invalid summary version", which reads like a broken test rather
than a broken environment, so probe for a working lld and skip if there is
none.
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-25-song@kernel.org
Diffstat (limited to 'tools/objtool/tests/generic/fixtures/thinlto_local.c')
| -rw-r--r-- | tools/objtool/tests/generic/fixtures/thinlto_local.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tools/objtool/tests/generic/fixtures/thinlto_local.c b/tools/objtool/tests/generic/fixtures/thinlto_local.c new file mode 100644 index 000000000000..fe9f9e6bf44f --- /dev/null +++ b/tools/objtool/tests/generic/fixtures/thinlto_local.c @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Two translation units (TU_B selects the second) linked with ThinLTO. + * Importing bump() promotes the file-local counter, renaming it + * counter.llvm.<hash>. The hash is content derived, so it differs between the + * original and patched builds. + */ + +#ifdef TU_B + +extern int bump(void); + +int other_entry(void) +{ + return bump() + bump(); +} + +#else + +static const char __modinfo[] + __attribute__((section(".modinfo"), used, aligned(1))) = "\0name=vmlinux"; + +static int counter; + +int bump(void) +{ + return ++counter; +} + +int target(void) +{ +#ifdef PATCHED + return counter + 1; +#else + return counter; +#endif +} + +#endif |
