Skip to content

Commit ff020d9

Browse files
[BOLT] Fix heatmaps on large BOLTE'd binaries.
Large binaries get two text segments mapped when loaded in memory, ie: ``` 2f7200000-2fabca000 r--p 00000000 bolted-binary <- 1st text segment 2fabd9000-2fe47c000 r-xp 039c9000 bolted-binary 2fe48b000-2fe61d000 r--p 0727b000 bolted-binary 2fe62c000-2fe660000 rw-p 0740c000 bolted-binary 2fe660000-2fea4c000 rw-p 00000000 2fec00000-303dad000 r-xp 07a00000 bolted-binary <- 2nd. only on bolted binary ``` BOLT processes only the first, which is not having a correct BaseAddress, causing a wrong computation of a BinaryMMapInfo's size. Consequently, BOLT wrongly thinks that many of the samples fall outside the binary and ignores them. As a result, the computed heatmap is incomplete, and the section hotness statistics are wrong. This bug is present in both the AArch64 and x86 backends.
1 parent d782119 commit ff020d9

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,9 +2009,6 @@ std::error_code DataAggregator::parseMMapEvents() {
20092009
return MI.second.PID == FileMMapInfo.second.PID;
20102010
});
20112011

2012-
if (PIDExists)
2013-
continue;
2014-
20152012
GlobalMMapInfo.insert(FileMMapInfo);
20162013
}
20172014

@@ -2067,7 +2064,21 @@ std::error_code DataAggregator::parseMMapEvents() {
20672064
}
20682065
}
20692066

2070-
BinaryMMapInfo.insert(std::make_pair(MMapInfo.PID, MMapInfo));
2067+
// In some larger binaries, the loaded binary gets a a second text segment
2068+
// memory mapped, right after its read-write segments. Below, we encounter
2069+
// and process such text segments, and recompute the size of the binary.
2070+
// When this happens, the correctly computed size comes from this second
2071+
// memory mapping, as the one processed earlier has an incorrect
2072+
// BaseAddress.
2073+
if (!BinaryMMapInfo.insert(std::make_pair(MMapInfo.PID, MMapInfo)).second) {
2074+
auto EndAddress = MMapInfo.MMapAddress + MMapInfo.Size;
2075+
auto Size = EndAddress - BinaryMMapInfo[MMapInfo.PID].BaseAddress;
2076+
if (Size != BinaryMMapInfo[MMapInfo.PID].Size) {
2077+
LLVM_DEBUG(outs() << "MMap size fixed: " << Twine::utohexstr(Size)
2078+
<< " \n");
2079+
BinaryMMapInfo[MMapInfo.PID].Size = Size;
2080+
}
2081+
}
20712082
}
20722083

20732084
if (BinaryMMapInfo.empty()) {

0 commit comments

Comments
 (0)