[memprof] Report an error when buildid and profile do not match (#132504)

## Problem
When the build ids of the profile and binary do not match, the error
reported by llvm-profdata is `no entries in callstack map after
symbolization`, but the root cause of this problem is the **build id
mismatch**.
## Trigger scenario
For example, when performing `memprof` optimization on `clang`,
`rawprofile` is collected through `ninja clang`. In addition to running
clang, some other programs will also be executed, and these programs
will also generate rawprofile. When `no entries in callstack map after
symbolization` appears during `llvm-profdata merge`, users may
mistakenly think that the **instrumentation failed or other reasons**,
and will **not directly realize that the binary and profile do not
match**.

## Changed
Currently, when the build id does not match, an assert error is
triggered only in debug mode. Change it to directly return an error when
the build id does not match.
This commit is contained in:
zcfh 2025-04-04 03:48:27 +08:00 committed by GitHub
parent 7288f1bc32
commit 229ca7dbcb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -444,7 +444,11 @@ Error RawMemProfReader::setupForSymbolization() {
ProfiledTextSegmentEnd = Entry.End;
}
}
assert(NumMatched != 0 && "No matching executable segments in segment info.");
if (NumMatched == 0)
return make_error<StringError>(
Twine("No matching executable segments found in binary ") +
Binary.getBinary()->getFileName(),
inconvertibleErrorCode());
assert((PreferredTextSegmentAddress == 0 ||
(PreferredTextSegmentAddress == ProfiledTextSegmentStart)) &&
"Expect text segment address to be 0 or equal to profiled text "

View File

@ -14,3 +14,9 @@ CHECK: Build ID: [[ID:[[:xdigit:]]+]]
COM: Then match it with the profdata output.
CHECK-COUNT-1: BuildId: {{.*}}[[ID]]
Test error message when profile build id does not match build id in a different binary.
RUN: not llvm-profdata show --memory %p/Inputs/buildid.memprofraw --profiled-binary %p/Inputs/basic.memprofexe -o - 2>&1 | FileCheck %s -check-prefix=BUILDID-NOT-MATCH
RUN: not llvm-profdata merge %p/Inputs/buildid.memprofraw %p/Inputs/basic.memprofraw --profiled-binary %p/Inputs/basic.memprofexe -o %t4.prof 2>&1 | FileCheck %s -check-prefix=BUILDID-NOT-MATCH
BUILDID-NOT-MATCH: No matching executable segments found in binary