From: Alireza Haghdoost Date: Tue, 24 Nov 2026 11:28:24 -0800 Subject: [PATCH v9 1/7] perf symbols: Split out name-independent duplicate symbol selection MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261124-perf-symbol-memory-send-v9-1-56f298185eae@uber.com> References: <20261124-perf-symbol-memory-send-v9-0-56f298185eae@uber.com> In-Reply-To: <20261124-perf-symbol-memory-send-v9-0-56f298185eae@uber.com> To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Alireza Haghdoost X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3028; i=haghdoost@uber.com; h=from:subject:message-id; bh=UqrMhQWdcnzp2DKimaobLxyHYzeN04T9j5HC1/5V6JI=; b=owEBiQJ2/ZANAwAIAVNlBDxl2ALYAcsmYgBrBeWEQCyb7BsUQ9ebI4IynMv9LLGJjODXVVulV kTyFiqg0JSJAk8EAAEIADkWIQS5+sFL3gX/8PrA0S1TZQQ8ZdgC2AUCawXlhBsUgAAAAAAEAA5t YW51MiwyLjUrMS4xMiwwLDMACgkQU2UEPGXYAtjjDQ/9ERnMqlEpX//dRSQy6XdQ2nj8jubWWsA QvQ/yTDZxB6OTqfuLj+6ubsnCQ1zh8xOKkhyZniufCKbk8WrQswyrfT9DaTyjA1rGQo+sM0Uk9P TZ0CwDATMyVhhjoXdZNT3+lSSLMoqX5llzsNykHxGiH1eSV6FQbJXxx4JgbSY5b9U38oxQN/wyP UsOz7/gqZWcqIGN8QG9M5ILgfv0SDMC0Z2G/0tg/VApLnhZyEAnoBQFTuwZdGbsOBMdddIbrs46 MJNz80tiiRgmOUa0nIlJCDrbAPo21c3TjnPNbBchalWv0ek8hr/JqZbDl8fyBojfpZVaDyUzTtR gT0LGHjVKND6cRiirUqzOPKwtXp29nsWGNAQGvjdXzA2UvhmkfKkPgKjjZm93LfHSUPrf+f2mab LMp1WaQTggeyPr11ADIPL3niyiZduAwhSxVjj5xnsoqiFQI8piRPwtAIHzZ0fk32ZKAROIAjOEO lAhkCHeHrB3QDbvJR/ldn4GRY77K3zckz6teoms67tZXw98unjnbeSx72DKSrAnzu/Y3ZCFZ9mG T2A/QPWV0aFkPiHKdz/E0/wtVGUxxlqVFzn+GXLikY3FA5/phf8L6m7MEIgknp02srxX9rboVGE G2UuQEIUfhbD9bV6SZHfHtWIC0kvGbzdFFd4QDG2mo+hDX41WhRs= X-Developer-Key: i=haghdoost@uber.com; a=openpgp; fpr=B9FAC14BDE05FFF0FAC0D12D5365043C65D802D8 X-Endpoint-Received: by B4 Relay for haghdoost@uber.com/default with auth_id=764 List-Id: B4 Relay Submissions This patch is a refactoring and does not change behavior. It moves the size, type and binding checks from choose_best_symbol() to choose_best_symbol_by_attrs(), and adds symbol__choice_needs_names() to tell whether choosing between two symbols needs their names. symbols__fixup_duplicate() keeps one of the symbols that share a start address. It compares size, type and binding first. If those are equal, it compares leading underscores, name lengths and the result of arch__choose_best_symbol(). An unresolved lazy symbol stores a file offset instead of a name pointer, so the lazy loader cannot call choose_best_symbol() before it has read both names. The new helper lets it leave the names unread when the attributes already pick one of the symbols. Reviewed-by: Ian Rogers Signed-off-by: Alireza Haghdoost --- tools/perf/util/symbol.c | 26 ++++++++++++++++++++++++-- tools/perf/util/symbol.h | 1 + 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 35b08c05a2fd..d9866916fe9a 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -157,11 +157,15 @@ int __weak arch__choose_best_symbol(struct symbol *syma, return SYMBOL_A; } -static int choose_best_symbol(struct symbol *syma, struct symbol *symb) +/* + * Choose between two symbols at the same address by size, type and binding. + * Returns SYMBOL_A or SYMBOL_B, or -1 if only their names can decide. + */ +static int choose_best_symbol_by_attrs(const struct symbol *syma, + const struct symbol *symb) { s64 a; s64 b; - size_t na, nb; /* Prefer a symbol with non zero length */ a = syma->end - syma->start; @@ -194,6 +198,24 @@ static int choose_best_symbol(struct symbol *syma, struct symbol *symb) if (b && !a) return SYMBOL_B; + return -1; +} + +bool symbol__choice_needs_names(const struct symbol *syma, const struct symbol *symb) +{ + return choose_best_symbol_by_attrs(syma, symb) < 0; +} + +static int choose_best_symbol(struct symbol *syma, struct symbol *symb) +{ + int ret = choose_best_symbol_by_attrs(syma, symb); + s64 a; + s64 b; + size_t na, nb; + + if (ret >= 0) + return ret; + /* Prefer a symbol with less underscores */ a = prefix_underscores_count(syma->name); b = prefix_underscores_count(symb->name); diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index 8b8ab7e1e148..41417bc85bb9 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -327,6 +327,7 @@ int arch__compare_symbol_names(const char *namea, const char *nameb); int arch__compare_symbol_names_n(const char *namea, const char *nameb, unsigned int n); int arch__choose_best_symbol(struct symbol *syma, struct symbol *symb); +bool symbol__choice_needs_names(const struct symbol *syma, const struct symbol *symb); enum symbol_tag_include { SYMBOL_TAG_INCLUDE__NONE = 0, -- Git-157)