objtool/klp: Correlate locals to globals

Allow correlating original locals to patched globals, and vice versa.
This is needed when:

1. User adds/removes "static" for a function.
2. CONFIG_LTO_CLANG_THIN promotes local functions and objects to global
   and add .llvm.<hash> suffix.

Signed-off-by: Song Liu <song@kernel.org>
Link: https://patch.msgid.link/20260305231531.3847295-8-song@kernel.org
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
This commit is contained in:
Song Liu 2026-03-05 15:15:31 -08:00 committed by Josh Poimboeuf
parent cdea5cadb0
commit 4b57e97be2

View File

@ -517,6 +517,36 @@ static int correlate_symbols(struct elfs *e)
}
}
/* Correlate original locals with patched globals */
for_each_sym(e->orig, sym1) {
if (sym1->twin || dont_correlate(sym1) || !is_local_sym(sym1))
continue;
sym2 = find_global_symbol_by_name(e->patched, sym1->name);
if (!sym2 && find_global_symbol_by_demangled_name(e->patched, sym1, &sym2))
return -1;
if (sym2 && !sym2->twin) {
sym1->twin = sym2;
sym2->twin = sym1;
}
}
/* Correlate original globals with patched locals */
for_each_sym(e->patched, sym2) {
if (sym2->twin || dont_correlate(sym2) || !is_local_sym(sym2))
continue;
sym1 = find_global_symbol_by_name(e->orig, sym2->name);
if (!sym1 && find_global_symbol_by_demangled_name(e->orig, sym2, &sym1))
return -1;
if (sym1 && !sym1->twin) {
sym2->twin = sym1;
sym1->twin = sym2;
}
}
for_each_sym(e->orig, sym1) {
if (sym1->twin || dont_correlate(sym1))
continue;