On Thu, Feb 19, 2026 at 02:22:37PM -0800, Song Liu wrote:
> correlate_symbols will always try to match full name first. If there is no
> match, try match only demangled_name.
In commit logs, please add "()" to function names, like
correlate_symbols().
> +++ b/tools/objtool/elf.c
> @@ -323,6 +323,19 @@ struct symbol *find_global_symbol_by_name(const struct
> elf *elf, const char *nam
> return NULL;
> }
>
> +void iterate_global_symbol_by_demangled_name(const struct elf *elf,
> + const char *demangled_name,
> + void (*process)(struct symbol
> *sym, void *data),
> + void *data)
> +{
> + struct symbol *sym;
> +
> + elf_hash_for_each_possible(symbol_name, sym, name_hash,
> str_hash(demangled_name)) {
> + if (!strcmp(sym->demangled_name, demangled_name) &&
> !is_local_sym(sym))
> + process(sym, data);
> + }
> +}
> +
I think a saner interface would be something like:
struct symbol *find_global_demangled_symbol(const struct elf *elf, const char
*demangled_name)
{
struct symbol *ret = NULL;
elf_hash_for_each_possible(symbol_name, sym, name_hash,
str_hash(demangled_name)) {
if (!is_local_sym(sym) && !strcmp(sym->demangled_name,
demangled_name)) {
if (ret)
return ERR_PTR(-EEXIST);
ret = sym;
}
}
return ret;
}
> @@ -453,8 +493,27 @@ static int correlate_symbols(struct elfs *e)
> continue;
>
> sym2 = find_global_symbol_by_name(e->patched, sym1->name);
> + if (sym2 && !sym2->twin) {
> + sym1->twin = sym2;
> + sym2->twin = sym1;
> + }
> + }
> +
> + /*
> + * Correlate globals with demangled_name.
> + * A separate loop is needed because we want to finish all the
> + * full name correlations first.
> + */
> + for_each_sym(e->orig, sym1) {
> + if (sym1->bind == STB_LOCAL || sym1->twin)
> + continue;
> +
> + if (find_global_symbol_by_demangled_name(e->patched, sym1,
> &sym2))
> + return -1;
>
> if (sym2 && !sym2->twin) {
> + WARN("correlate %s (original) to %s (patched)",
> + sym1->name, sym2->name);
Since there's not actually any ambiguity at this point, do we actually
need a warning?
--
Josh