mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: James Clark <james.clark@linaro.org>
To: Michael Liang <mliang@purestorage.com>
Cc: Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>
Subject: Re: [PATCH 1/1] perf libdw: Fix outer-frame name resolution and spurious "(inlined)" tag
Date: Wed, 29 Jul 2026 11:21:02 +0100	[thread overview]
Message-ID: <7d980402-84d0-4cef-9bc2-af8fd5e13224@linaro.org> (raw)
In-Reply-To: <20260728204215.327318-2-mliang@purestorage.com>



On 28/07/2026 9:42 pm, Michael Liang wrote:
> 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: 88c51002d06f9a68 ("perf addr2line: Add a libdw implementation")
> Signed-off-by: Michael Liang <mliang@purestorage.com>

Reviewed-by: James Clark <james.clark@linaro.org>

> ---
>   tools/perf/util/libdw.c | 34 ++++++++++++++++++++++++++++++----
>   1 file changed, 30 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/perf/util/libdw.c b/tools/perf/util/libdw.c
> index d5d2958902c0..4ca7e7e4fbe9 100644
> --- a/tools/perf/util/libdw.c
> +++ b/tools/perf/util/libdw.c
> @@ -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;
> -
> -	if (!inline_sym)
> -		goto abort_enomem;
> +	struct symbol *inline_sym;
> +
> +	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)


  reply	other threads:[~2026-07-29 10:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-28 20:42 [PATCH 0/1] perf libdw: fix outer-frame name " 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 message]
2026-08-02  5:46   ` Namhyung Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7d980402-84d0-4cef-9bc2-af8fd5e13224@linaro.org \
    --to=james.clark@linaro.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=mliang@purestorage.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®