perf libdw: Fix outer-frame name resolution and spurious "(inlined)" tag

cu_walk_functions_at() calls libdw_a2l_cb() with the containing
DW_TAG_subprogram DIE first, then each DW_TAG_inlined_subroutine
nested inside.  The callback treated both the same way, causing two
bugs:

  1) die_name() returns the unqualified DW_AT_name, so every C++
     frame lost its namespace/class prefix (ns::Class::method
     collapsed to method).

  2) new_inline_sym() re-uses base_sym only when funcname matches
     base_sym->name exactly; otherwise it fabricates a fake symbol
     tagged "(inlined)".  Any mismatch between the DWARF name and
     the ELF symbol name mis-tags an outer, non-inline frame as
     inlined.  This hits C++ (die_name()'s unqualified output never
     matches the demangled ELF symbol) and it also hits C functions
     that GCC IPA-cloned (foo vs foo.isra.0 / .constprop / .part /
     .cold), since DW_AT_linkage_name doesn't reflect those renames.

Fix both:

  * Prefer die_get_linkage_name() (mangled, fully qualified),
    falling back to die_name() when absent (C, extern "C").
    new_inline_sym() already demangles via dso__demangle_sym().

  * For DW_TAG_subprogram DIEs, use base_sym directly -- the DIE
    tag already tells us it is the outer function, sidestepping
    the name comparison entirely for both C++ qualification and
    GCC IPA-clone renames.

Fixes: 88c51002d0 ("perf addr2line: Add a libdw implementation")
Signed-off-by: Michael Liang <mliang@purestorage.com>
Reviewed-by: James Clark <james.clark@linaro.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
This commit is contained in:
Michael Liang
2026-07-28 14:42:15 -06:00
committed by Namhyung Kim
parent f2effca1ef
commit 022bcb6ba2

View File

@@ -82,13 +82,39 @@ struct libdw_a2l_cb_args {
static int libdw_a2l_cb(Dwarf_Die *die, void *_args)
{
struct libdw_a2l_cb_args *args = _args;
struct symbol *inline_sym = new_inline_sym(args->dso, args->sym, die_name(die));
const char *call_fname = die_get_call_file(die);
int call_lineno = die_get_call_lineno(die);
char *call_srcline = srcline__unknown;
struct symbol *inline_sym;
if (!inline_sym)
goto abort_enomem;
if (dwarf_tag(die) == DW_TAG_subprogram && args->sym) {
/*
* cu_walk_functions_at() opens the walk with the
* containing DW_TAG_subprogram DIE (the non-inlined outer
* function). That's just the base symbol -- use it
* directly. Avoids a fragile name-vs-name compare in
* new_inline_sym() that misfires when GCC IPA passes
* (.isra/.constprop/.part/.cold) rename the ELF symbol
* while DWARF keeps the pre-clone linkage name, which
* left the outer frame spuriously tagged "(inlined)".
*/
inline_sym = args->sym;
} else {
/*
* Prefer DW_AT_linkage_name so C++ inline frames keep
* their namespace/class qualification. new_inline_sym()
* runs the name through dso__demangle_sym(), so the
* mangled linkage name is turned back into
* "Namespace::Class::method". Fall back to DW_AT_name
* (unqualified) when no linkage name is present, e.g.
* for C code or extern "C" functions.
*/
const char *funcname = die_get_linkage_name(die) ?: die_name(die);
inline_sym = new_inline_sym(args->dso, args->sym, funcname);
if (!inline_sym)
goto abort_enomem;
}
/* Assign caller information to the parent. */
if (call_fname)