From: Ian Rogers <irogers@google.com>
To: Namhyung Kim <namhyung@kernel.org>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Alireza Haghdoost <haghdoost@uber.com>,
Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>, Jiri Olsa <jolsa@kernel.org>,
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 v11 1/5] perf symbol: Fix symbols__fixup_end() for equal-start zero-sized aliases
Date: Mon, 30 Nov 2026 14:04:32 -0800 [thread overview]
Message-ID: <20261130220437.4099852-2-irogers@google.com> (raw)
In-Reply-To: <20261130220437.4099852-1-irogers@google.com>
When multiple zero-sized symbols share the same start address (such as
STB_GLOBAL and STB_WEAK aliases in /proc/kallsyms), symbols__fixup_end()
previously skipped earlier entries in the equal-start group and only
updated end on the final entry before the next distinct address.
Because __dso__load_kallsyms() and ELF loaders call symbols__fixup_end()
before symbols__fixup_duplicate(), inflating only the last entry gave it
a non-zero length while leaving earlier aliases at the same address with
zero length. In choose_best_symbol(), the initial "Prefer a symbol with
non zero length" check then unconditionally selected whichever alias
happened to appear last, bypassing the STT_NOTYPE, STB_WEAK, STB_GLOBAL,
underscore-count, and arch__choose_best_symbol() heuristics (for example
dropping a global symbol when followed by a weak alias at the same
address).
Track group_start across each equal-start group in symbols__fixup_end():
when no symbol at that start address already has a non-zero size
(!addr_has_sized), synthesize end for every symbol in the group so
subsequent deduplication compares equal-length aliases using binding and
name heuristics (and so allow_aliases callers do not retain zero-length
earlier aliases). When any symbol at that address already has an
explicit non-zero size (addr_has_sized), leave zero-sized aliases at
zero as before so choose_best_symbol() continues to prefer explicitly
sized symbols.
Fixes: 432746f8e0b6 ("perf symbols: Fixup symbol sizes before picking best ones")
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/symbol.c | 74 +++++++++++++++++++++++-----------------
1 file changed, 42 insertions(+), 32 deletions(-)
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index d6a841dadcad..a6f667e9dedc 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -540,7 +540,7 @@ void symbols__fixup_duplicate(struct symbols *symbols)
/* Update zero-sized symbols using the address of the next symbol */
void symbols__fixup_end(struct symbols *symbols, bool is_kallsyms)
{
- struct symbol *curr, *prev;
+ unsigned int group_start = 0;
bool addr_has_sized;
down_write(&symbols->lock);
@@ -551,14 +551,12 @@ void symbols__fixup_end(struct symbols *symbols, bool is_kallsyms)
return;
}
- curr = symbols->symbols[0];
- addr_has_sized = curr->end > curr->start;
+ addr_has_sized = symbols->symbols[0]->end > symbols->symbols[0]->start;
for (unsigned int i = 1; i < symbols->cnt; i++) {
- prev = curr;
- curr = symbols->symbols[i];
+ struct symbol *curr = symbols->symbols[i];
- if (curr->start == prev->start) {
+ if (curr->start == symbols->symbols[group_start]->start) {
if (curr->end > curr->start)
addr_has_sized = true;
continue;
@@ -580,40 +578,52 @@ void symbols__fixup_end(struct symbols *symbols, bool is_kallsyms)
* like in:
* ffffffffc1937000 T hdmi_driver_init [snd_hda_codec_hdmi]
*/
- if (!addr_has_sized && prev->end == prev->start) {
- const char *prev_mod;
- const char *curr_mod;
+ if (!addr_has_sized) {
+ const char *curr_mod = is_kallsyms ? strchr(curr->name, '[') : NULL;
- if (!is_kallsyms) {
- prev->end = curr->start;
- } else {
- prev_mod = strchr(prev->name, '[');
- curr_mod = strchr(curr->name, '[');
-
- /* Last kernel/module symbol mapped to end of page */
- if (!prev_mod != !curr_mod) {
- prev->end = roundup(prev->end + 4096, 4096);
- /* Last symbol in the previous module */
- } else if (prev_mod && strcmp(prev_mod, curr_mod)) {
- prev->end = roundup(prev->end + 4096, 4096);
- } else {
- prev->end = curr->start;
- }
+ for (unsigned int j = group_start; j < i; j++) {
+ struct symbol *prev = symbols->symbols[j];
- /* The next module can start within that page */
- if (prev->end > curr->start)
- prev->end = curr->start;
+ if (prev->end != prev->start)
+ continue;
- pr_debug4("%s sym:%s end:%#" PRIx64 "\n",
- __func__, prev->name, prev->end);
+ if (!is_kallsyms) {
+ prev->end = curr->start;
+ } else {
+ const char *prev_mod = strchr(prev->name, '[');
+
+ /* Last kernel/module symbol mapped to end of page */
+ if (!prev_mod != !curr_mod) {
+ prev->end = roundup(prev->end + 4096, 4096);
+ /* Last symbol in the previous module */
+ } else if (prev_mod && strcmp(prev_mod, curr_mod)) {
+ prev->end = roundup(prev->end + 4096, 4096);
+ } else {
+ prev->end = curr->start;
+ }
+
+ /* The next module can start within that page */
+ if (prev->end > curr->start)
+ prev->end = curr->start;
+
+ pr_debug4("%s sym:%s end:%#" PRIx64 "\n",
+ __func__, prev->name, prev->end);
+ }
}
}
+ group_start = i;
addr_has_sized = curr->end > curr->start;
}
- /* Last entry */
- if (!addr_has_sized && curr->end == curr->start)
- curr->end = roundup(curr->start, 4096) + 4096;
+ /* Last equal-start group */
+ if (!addr_has_sized) {
+ for (unsigned int j = group_start; j < symbols->cnt; j++) {
+ struct symbol *curr = symbols->symbols[j];
+
+ if (curr->end == curr->start)
+ curr->end = roundup(curr->start, 4096) + 4096;
+ }
+ }
up_write(&symbols->lock);
}
--
2.56.1.839.g22a8290db9-goog
next prev parent reply other threads:[~2026-11-30 22:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 22:04 [PATCH v11 0/5] perf symbol: Fix alias end fixup and optimize sorted array Ian Rogers
2026-11-30 22:04 ` Ian Rogers [this message]
2026-11-30 22:04 ` [PATCH v11 2/5] perf symbol: Drop num_by_name and sorted_by_name from struct symbols Ian Rogers
2026-11-30 22:04 ` [PATCH v11 3/5] perf symbol: Replace sorted boolean with sorted_cnt prefix length Ian Rogers
2026-11-30 22:04 ` [PATCH v11 4/5] perf symbol: Add secondary sorted run for dso__insert_symbol() Ian Rogers
2026-11-30 22:04 ` [PATCH v11 5/5] perf test symbols: Add sorted insertion and equal-start alias tests Ian Rogers
2026-11-30 22:11 ` [PATCH v11 0/5] perf symbol: Fix alias end fixup and optimize sorted array sashiko-bot
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=20261130220437.4099852-2-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=haghdoost@uber.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.