[PATCH v11 1/5] perf symbol: Fix symbols__fixup_end() for equal-start zero-sized aliases
From: Ian Rogers
Date: Mon Nov 30 2026 - 17:04:48 EST
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@xxxxxxxxxx>
---
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