Skip to content

Commit 537343d

Browse files
committed
Revert "[BOLT] DataAggregator support for binaries with multiple text segments (#92815)"
This caused test failures, see comment on the PR: Failed Tests (2): BOLT-Unit :: Core/./CoreTests/AArch64/MemoryMapsTester/MultipleSegmentsMismatchedBaseAddress/0 BOLT-Unit :: Core/./CoreTests/X86/MemoryMapsTester/MultipleSegmentsMismatchedBaseAddress/0 > When a binary has multiple text segments, the Size is computed as the > difference of the last address of these segments from the BaseAddress. > The base addresses of all text segments must be the same. > > Introduces flag 'perf-script-events' for testing. It allows passing perf events > without BOLT having to parse them using 'perf script'. The flag is used to > pass a mock perf profile that has two memory mappings for a mock binary > that has two text segments. The size of the mapping is updated as this > change `parseMMapEvents` processes all text segments. This reverts commit 4b71b37.
1 parent f4379db commit 537343d

File tree

5 files changed

+14
-183
lines changed

5 files changed

+14
-183
lines changed

bolt/include/bolt/Profile/DataAggregator.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,6 @@ class DataAggregator : public DataReader {
170170
std::string BuildIDBinaryName;
171171

172172
/// Memory map info for a single file as recorded in perf.data
173-
/// When a binary has multiple text segments, the Size is computed as the
174-
/// difference of the last address of these segments from the BaseAddress.
175-
/// The base addresses of all text segments must be the same.
176173
struct MMapInfo {
177174
uint64_t BaseAddress{0}; /// Base address of the mapped binary.
178175
uint64_t MMapAddress{0}; /// Address of the executable segment.
@@ -496,11 +493,6 @@ class DataAggregator : public DataReader {
496493
/// and return a file name matching a given \p FileBuildID.
497494
std::optional<StringRef> getFileNameForBuildID(StringRef FileBuildID);
498495

499-
/// Get a constant reference to the parsed binary mmap entries.
500-
const std::unordered_map<uint64_t, MMapInfo> &getBinaryMMapInfo() {
501-
return BinaryMMapInfo;
502-
}
503-
504496
friend class YAMLProfileWriter;
505497
};
506498
} // namespace bolt

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,6 @@ cl::opt<bool> ReadPreAggregated(
9595
"pa", cl::desc("skip perf and read data from a pre-aggregated file format"),
9696
cl::cat(AggregatorCategory));
9797

98-
cl::opt<std::string>
99-
ReadPerfEvents("perf-script-events",
100-
cl::desc("skip perf event collection by supplying a "
101-
"perf-script output in a textual format"),
102-
cl::ReallyHidden, cl::init(""), cl::cat(AggregatorCategory));
103-
10498
static cl::opt<bool>
10599
TimeAggregator("time-aggr",
106100
cl::desc("time BOLT aggregator"),
@@ -173,9 +167,8 @@ void DataAggregator::findPerfExecutable() {
173167
void DataAggregator::start() {
174168
outs() << "PERF2BOLT: Starting data aggregation job for " << Filename << "\n";
175169

176-
// Don't launch perf for pre-aggregated files or when perf input is specified
177-
// by the user.
178-
if (opts::ReadPreAggregated || !opts::ReadPerfEvents.empty())
170+
// Don't launch perf for pre-aggregated files
171+
if (opts::ReadPreAggregated)
179172
return;
180173

181174
findPerfExecutable();
@@ -471,13 +464,6 @@ void DataAggregator::filterBinaryMMapInfo() {
471464

472465
int DataAggregator::prepareToParse(StringRef Name, PerfProcessInfo &Process,
473466
PerfProcessErrorCallbackTy Callback) {
474-
if (!opts::ReadPerfEvents.empty()) {
475-
outs() << "PERF2BOLT: using pre-processed perf events for '" << Name
476-
<< "' (perf-script-events)\n";
477-
ParsingBuf = opts::ReadPerfEvents;
478-
return 0;
479-
}
480-
481467
std::string Error;
482468
outs() << "PERF2BOLT: waiting for perf " << Name
483469
<< " collection to finish...\n";
@@ -2070,6 +2056,15 @@ std::error_code DataAggregator::parseMMapEvents() {
20702056
if (FileMMapInfo.first == "(deleted)")
20712057
continue;
20722058

2059+
// Consider only the first mapping of the file for any given PID
2060+
auto Range = GlobalMMapInfo.equal_range(FileMMapInfo.first);
2061+
bool PIDExists = llvm::any_of(make_range(Range), [&](const auto &MI) {
2062+
return MI.second.PID == FileMMapInfo.second.PID;
2063+
});
2064+
2065+
if (PIDExists)
2066+
continue;
2067+
20732068
GlobalMMapInfo.insert(FileMMapInfo);
20742069
}
20752070

@@ -2121,22 +2116,12 @@ std::error_code DataAggregator::parseMMapEvents() {
21212116
<< " using file offset 0x" << Twine::utohexstr(MMapInfo.Offset)
21222117
<< ". Ignoring profile data for this mapping\n";
21232118
continue;
2119+
} else {
2120+
MMapInfo.BaseAddress = *BaseAddress;
21242121
}
2125-
MMapInfo.BaseAddress = *BaseAddress;
21262122
}
21272123

2128-
// Try to add MMapInfo to the map and update its size. Large binaries may
2129-
// span to multiple text segments, so the mapping is inserted only on the
2130-
// first occurrence.
2131-
if (!BinaryMMapInfo.insert(std::make_pair(MMapInfo.PID, MMapInfo)).second)
2132-
assert(MMapInfo.BaseAddress == BinaryMMapInfo[MMapInfo.PID].BaseAddress &&
2133-
"Base address on multiple segment mappings should match");
2134-
2135-
// Update mapping size.
2136-
const uint64_t EndAddress = MMapInfo.MMapAddress + MMapInfo.Size;
2137-
const uint64_t Size = EndAddress - BinaryMMapInfo[MMapInfo.PID].BaseAddress;
2138-
if (Size > BinaryMMapInfo[MMapInfo.PID].Size)
2139-
BinaryMMapInfo[MMapInfo.PID].Size = Size;
2124+
BinaryMMapInfo.insert(std::make_pair(MMapInfo.PID, MMapInfo));
21402125
}
21412126

21422127
if (BinaryMMapInfo.empty()) {

bolt/unittests/Core/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ set(LLVM_LINK_COMPONENTS
88
add_bolt_unittest(CoreTests
99
BinaryContext.cpp
1010
MCPlusBuilder.cpp
11-
MemoryMaps.cpp
1211
DynoStats.cpp
1312

1413
DISABLE_LLVM_LINK_LLVM_DYLIB
@@ -18,8 +17,6 @@ target_link_libraries(CoreTests
1817
PRIVATE
1918
LLVMBOLTCore
2019
LLVMBOLTRewrite
21-
LLVMBOLTProfile
22-
LLVMTestingSupport
2320
)
2421

2522
foreach (tgt ${BOLT_TARGETS_TO_BUILD})

bolt/unittests/Core/MemoryMaps.cpp

Lines changed: 0 additions & 142 deletions
This file was deleted.

llvm/utils/gn/secondary/bolt/unittests/Core/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ unittest("CoreTests") {
1515
"BinaryContext.cpp",
1616
"DynoStats.cpp",
1717
"MCPlusBuilder.cpp",
18-
"MemoryMaps.cpp",
1918
]
2019

2120
defines = []

0 commit comments

Comments
 (0)