Linux Perf Users
 help / color / mirror / Atom feed
* [PATCH 0/1] perf libdw: fix outer-frame name and spurious "(inlined)" tag
@ 2026-07-28 20:42 Michael Liang
  2026-07-28 20:42 ` [PATCH 1/1] perf libdw: Fix outer-frame name resolution " Michael Liang
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Liang @ 2026-07-28 20:42 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Peter Zijlstra,
	Ingo Molnar
  Cc: Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers,
	Adrian Hunter, James Clark, linux-perf-users, linux-kernel,
	Michael Liang

When perf is built with libdw support, addr2line uses libdw and
cu_walk_functions_at() walks the containing DW_TAG_subprogram DIE
plus every DW_TAG_inlined_subroutine DIE at the sample address. The
libdw_a2l_cb() callback treated the outer subprogram DIE the same
way as inlined subroutines, causing two bugs on the outer frame:

  1. C++ frames lost their namespace/class qualification, because
     die_name() returns the unqualified DW_AT_name -- so
     ns::Class::method rendered as method.

  2. Any DWARF-vs-ELF name mismatch on the outer frame tripped
     new_inline_sym()'s fallback path, which fabricates a fake
     symbol tagged "(inlined)". This hit C++ (die_name()'s
     unqualified string never matched the demangled ELF symbol)
     *and* it hit C functions renamed by GCC IPA-clone (foo vs
     foo.isra.0 / .constprop / .part / .cold), since
     DW_AT_linkage_name doesn't reflect those renames either.

The patch does two things:

  * 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 the outer DW_TAG_subprogram DIE, use base_sym directly --
    the DIE tag already tells us it is the outer function, so we
    skip the name comparison entirely for both C++ qualification
    and IPA-clone renames.

Testing
=======

Reproduced with a small C++ program that exercises both a
non-inline namespaced class method (which GCC also IPA-SRA-clones
into a .isra.0 symbol) and an always_inline helper:

    namespace demo {
    static volatile std::uint64_t sink;

    class Worker {
    public:
        __attribute__((noinline))
        void run_one_io_task(std::uint64_t seed) {
            std::uint64_t x = seed;
            for (int i = 0; i < 400000; ++i)
                x = x * 2862933555777941757ULL + 3037000493ULL;
            sink = x;
        }

        __attribute__((always_inline))
        inline void spin(std::uint64_t seed) {
            std::uint64_t x = seed;
            for (int i = 0; i < 300000; ++i)
                x = x * 3935559000370003845ULL + 2691343689449507681ULL;
            sink = x;
        }
    };
    } // namespace demo

    int main() {
        demo::Worker w;
        for (int i = 0; i < 400; ++i) {
            w.run_one_io_task(i);
            w.spin(i ^ 0xa5a5a5a5a5a5a5a5ULL);
        }
    }

Build:
    g++ -O2 -g -fno-omit-frame-pointer demo.cpp -o demo

Then:
    perf record -g -F 999 -- ./demo
    perf script | head

On unpatched perf, every C++ frame comes out unqualified and tagged
"(inlined)" -- including the outer IPA-cloned frame:

    run_one_io_task+0x24  (inlined)     [WRONG: unqualified, not inlined]
    spin+0x40             (inlined)     [WRONG: unqualified]

With this patch:

    demo::Worker::run_one_io_task(unsigned long) [clone .isra.0]+0x24
    demo::Worker::spin(unsigned long)+0x40  (inlined)   [true inline]

The outer frame is fully qualified and no longer carries a spurious
"(inlined)" tag; the truly-inlined helper stays correctly tagged.
The same mis-tagging behavior is reproducible in pure C by taking
any function GCC IPA-clones (e.g. a static helper that gets .isra
/ .constprop applied) -- unpatched perf tags the outer frame
"(inlined)"; with the patch it renders as the base symbol.

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

 tools/perf/util/libdw.c | 34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)

--
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-07-29 10:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-28 20:42 [PATCH 0/1] perf libdw: fix outer-frame name and spurious "(inlined)" tag Michael Liang
2026-07-28 20:42 ` [PATCH 1/1] perf libdw: Fix outer-frame name resolution " Michael Liang
2026-07-29 10:21   ` James Clark

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox