Skip to content

Commit 229ca7d

Browse files
authored
[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.
1 parent 7288f1b commit 229ca7d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

llvm/lib/ProfileData/MemProfReader.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,11 @@ Error RawMemProfReader::setupForSymbolization() {
444444
ProfiledTextSegmentEnd = Entry.End;
445445
}
446446
}
447-
assert(NumMatched != 0 && "No matching executable segments in segment info.");
447+
if (NumMatched == 0)
448+
return make_error<StringError>(
449+
Twine("No matching executable segments found in binary ") +
450+
Binary.getBinary()->getFileName(),
451+
inconvertibleErrorCode());
448452
assert((PreferredTextSegmentAddress == 0 ||
449453
(PreferredTextSegmentAddress == ProfiledTextSegmentStart)) &&
450454
"Expect text segment address to be 0 or equal to profiled text "

llvm/test/tools/llvm-profdata/memprof-buildid.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ CHECK: Build ID: [[ID:[[:xdigit:]]+]]
1414

1515
COM: Then match it with the profdata output.
1616
CHECK-COUNT-1: BuildId: {{.*}}[[ID]]
17+
18+
Test error message when profile build id does not match build id in a different binary.
19+
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
20+
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
21+
22+
BUILDID-NOT-MATCH: No matching executable segments found in binary

0 commit comments

Comments
 (0)