[PATCH v1 3/7] perf dso: Handle trailing zeros symmetrically in dso__build_id_equal()
From: Ian Rogers
Date: Sun Oct 25 2026 - 18:05:25 EST
dso__build_id_equal() allows a 20-byte dso_bid with trailing zeros to
match a shorter bid (such as an 8-byte or 16-byte build ID), but did not
handle the symmetric case where the lookup bid is 20 bytes padded with
trailing zeros (e.g. from BPF/perf kernel build ID extraction) and
dso_bid has the exact shorter size. Handle both directions symmetrically.
Fixes: f4e3381648be ("perf tools: Minimal DEFERRED_CALLCHAIN support")
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/util/dso.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index ce98613868e7..e46cd614eb21 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -1949,7 +1949,8 @@ bool dso__build_id_equal(const struct dso *dso, const struct build_id *bid)
{
const struct build_id *dso_bid = dso__bid(dso);
- if (dso_bid->size > bid->size && dso_bid->size == BUILD_ID_SIZE) {
+ if (dso_bid->size > bid->size && bid->size > 0 &&
+ dso_bid->size == BUILD_ID_SIZE) {
/*
* For the backward compatibility, it allows a build-id has
* trailing zeros.
@@ -1959,6 +1960,13 @@ bool dso__build_id_equal(const struct dso *dso, const struct build_id *bid)
dso_bid->size - bid->size);
}
+ if (bid->size > dso_bid->size && dso_bid->size > 0 &&
+ bid->size == BUILD_ID_SIZE) {
+ return !memcmp(dso_bid->data, bid->data, dso_bid->size) &&
+ !memchr_inv(&bid->data[dso_bid->size], 0,
+ bid->size - dso_bid->size);
+ }
+
return dso_bid->size == bid->size &&
memcmp(dso_bid->data, bid->data, dso_bid->size) == 0;
}
--
2.56.0.307.g5fe7bd680c-goog