From: Michal Pluta <michalpl2003@gmail.com>
To: acme@kernel.org, namhyung@kernel.org
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
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>,
James Clark <james.clark@linaro.org>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 5/5] perf symbol: Move Rust demangling into its own function
Date: Mon, 28 Sep 2026 02:02:27 +0100 [thread overview]
Message-ID: <20260928010227.1903673-6-michalpl2003@gmail.com> (raw)
In-Reply-To: <20260928010227.1903673-1-michalpl2003@gmail.com>
dso__demangle_sym() is the only place that implements demangling logic
inline. The other three are one call each to a helper. Move the Rust
parsing and buffer growth into rust_demangle_sym(), with the same
signature as the other three.
A Rust name that fails to demangle now falls through to the other
demanglers, matching how the other demanglers chain into each other.
A v0 name can't be misread by any of them, since none accepts its "_R"
prefix. A legacy name can only fail here on allocation failure or
hitting the output bound, neither of which is language-specific.
Assisted-by: LLM
Signed-off-by: Michal Pluta <michalpl2003@gmail.com>
---
tools/perf/util/symbol.c | 61 +++++++++++++++++++++++-----------------
1 file changed, 35 insertions(+), 26 deletions(-)
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 858a14a91f79..89db9a670833 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -2740,47 +2740,56 @@ char *cxx_demangle_sym(const char *str __maybe_unused, bool params __maybe_unuse
/* Buffer limit for a demangled Rust symbol name. */
#define RUST_DEMANGLE_MAX_LEN (1024 * 1024)
-char *dso__demangle_sym(struct dso *dso, int kmodule, const char *elf_name)
+static char *rust_demangle_sym(const char *elf_name)
{
struct demangle rust_demangle = {
.style = DemangleStyleUnknown,
};
char *demangled = NULL;
size_t buf_len;
+ rust_demangle_demangle(elf_name, &rust_demangle);
+ if (!rust_demangle_is_known(&rust_demangle))
+ return NULL;
+
+ if (rust_demangle.mangled_len == 0)
+ return NULL;
+
+ for (buf_len = min_t(size_t, roundup_pow_of_two(rust_demangle.mangled_len * 2),
+ RUST_DEMANGLE_MAX_LEN);
+ buf_len <= RUST_DEMANGLE_MAX_LEN;
+ buf_len *= 2) {
+ char *tmp = realloc(demangled, buf_len);
+
+ if (!tmp)
+ break;
+ demangled = tmp;
+ if (rust_demangle_display_demangle(&rust_demangle, demangled, buf_len,
+ /*alternate=*/true) == OverflowOk) {
+ tmp = realloc(demangled, strlen(demangled) + 1);
+ return tmp ?: demangled;
+ }
+ }
+ /* Failure to grow output buffer or buffer exceeded sensible bounds. */
+ free(demangled);
+ return NULL;
+}
+
+char *dso__demangle_sym(struct dso *dso, int kmodule, const char *elf_name)
+{
+ char *demangled = NULL;
+
/*
* We need to figure out if the object was created from C++ sources
* DWARF DW_compile_unit has this, but we don't always have access
* to it...
*/
if (!want_demangle((dso && dso__kernel(dso)) || kmodule))
return demangled;
- rust_demangle_demangle(elf_name, &rust_demangle);
- if (rust_demangle_is_known(&rust_demangle)) {
- /* A rust mangled name. */
- if (rust_demangle.mangled_len == 0)
- return demangled;
-
- for (buf_len = min_t(size_t, roundup_pow_of_two(rust_demangle.mangled_len * 2),
- RUST_DEMANGLE_MAX_LEN);
- buf_len <= RUST_DEMANGLE_MAX_LEN;
- buf_len *= 2) {
- char *tmp = realloc(demangled, buf_len);
-
- if (!tmp)
- break;
- demangled = tmp;
- if (rust_demangle_display_demangle(&rust_demangle, demangled, buf_len,
- /*alternate=*/true) == OverflowOk) {
- tmp = realloc(demangled, strlen(demangled) + 1);
- return tmp ?: demangled;
- }
- }
- /* Failure to grow output buffer or buffer exceeded sensible bounds. */
- free(demangled);
- return NULL;
- }
+ demangled = rust_demangle_sym(elf_name);
+ if (demangled)
+ return demangled;
demangled = cxx_demangle_sym(elf_name, verbose > 0, verbose > 0);
if (demangled)
--
2.43.0
prev parent reply other threads:[~2026-09-28 1:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 1:02 [PATCH 0/5] perf symbol: Speed up demangling of long Rust symbols Michal Pluta
2026-09-28 1:02 ` [PATCH 1/5] perf test demangle: Fail when demangling fails Michal Pluta
2026-09-28 1:02 ` [PATCH 2/5] perf symbol: Don't return an unterminated Rust demangle buffer Michal Pluta
2026-09-28 1:02 ` [PATCH 3/5] perf symbol: Grow the Rust demangle buffer geometrically Michal Pluta
2026-09-28 1:02 ` [PATCH 4/5] perf symbol: Shrink the demangled Rust buffer to fit Michal Pluta
2026-09-28 1:02 ` Michal Pluta [this message]
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=20260928010227.1903673-6-michalpl2003@gmail.com \
--to=michalpl2003@gmail.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--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=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®