From 52391820757ecdd59d74e141fff360662affe68f Mon Sep 17 00:00:00 2001 From: Maksim Panchenko Date: Fri, 30 Apr 2021 15:02:29 -0700 Subject: [PATCH] [perf2bolt] Further relax segment matching Summary: Previously, we used p_align value of the code segment to predict the mapping of the segment at runtime. However, at times the reported value is not aligned and at other times the actual aligned value will be different because of the different page size used. All we know is that the page size used at runtime should not exceed p_align value. Adjust our segment address matching accordingly. (cherry picked from FBD28133066) --- bolt/src/DataAggregator.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/bolt/src/DataAggregator.cpp b/bolt/src/DataAggregator.cpp index 9d3659499122..974417fb8afa 100644 --- a/bolt/src/DataAggregator.cpp +++ b/bolt/src/DataAggregator.cpp @@ -2056,27 +2056,30 @@ std::error_code DataAggregator::parseMMapEvents() { auto Range = GlobalMMapInfo.equal_range(NameToUse); for (auto I = Range.first; I != Range.second; ++I) { - if (BC->HasFixedLoadAddress && I->second.BaseAddress) { + const MMapInfo &MMapInfo = I->second; + if (BC->HasFixedLoadAddress && MMapInfo.BaseAddress) { // Check that the binary mapping matches one of the segments. - bool MatchFound{false}; + bool MatchFound = false; for (auto &KV : BC->SegmentMapInfo) { SegmentInfo &SegInfo = KV.second; - const uint64_t MapAddress = - alignDown(SegInfo.Address, SegInfo.Alignment); - if (I->second.BaseAddress == MapAddress || - I->second.BaseAddress == SegInfo.Address) { + // The mapping is page-aligned and hence the BaseAddress could be + // different from the segment start address. We cannot know the page + // size of the mapping, but we know it should not exceed the segment + // alignment value. Hence we are performing an approximate check. + if (SegInfo.Address >= MMapInfo.BaseAddress && + SegInfo.Address - MMapInfo.BaseAddress < SegInfo.Alignment) { MatchFound = true; break; } } if (!MatchFound) { errs() << "PERF2BOLT-WARNING: ignoring mapping of " << NameToUse - << " at 0x" << Twine::utohexstr(I->second.BaseAddress) << '\n'; + << " at 0x" << Twine::utohexstr(MMapInfo.BaseAddress) << '\n'; continue; } } - BinaryMMapInfo.insert(std::make_pair(I->second.PID, I->second)); + BinaryMMapInfo.insert(std::make_pair(MMapInfo.PID, MMapInfo)); } if (BinaryMMapInfo.empty()) {