Skip to content

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

Michael Liang linux-perf-users lkml 1 version Applied

Status from this message: Applied to perf-tools-next, thanks!

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest1 patch 2 repliesApplied

Patches in v1 Applied

#Subject and filesSizeRepliesApplied
1/1perf libdw: Fix outer-frame name resolution and spurious "(inlined)" tagtools/perf/util/libdw.c+30 -42 replies

Reviews trailers per patch

The patch has a Reviewed-by or Acked-by.

PatchJames Clark
1/1R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/1] perf libdw: fix outer-frame name and spurious "(inlined)" tag

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