Index: bolt/lib/Core/BinaryContext.cpp =================================================================== --- bolt/lib/Core/BinaryContext.cpp +++ bolt/lib/Core/BinaryContext.cpp @@ -41,6 +41,7 @@ #include #include #include +#include using namespace llvm; @@ -1873,12 +1874,14 @@ BinaryContext::getBaseAddressForMapping(uint64_t MMapAddress, uint64_t FileOffset) const { // Find a segment with a matching file offset. + size_t PgSize = getpagesize(); for (auto &KV : SegmentMapInfo) { const SegmentInfo &SegInfo = KV.second; - if (alignDown(SegInfo.FileOffset, SegInfo.Alignment) == FileOffset) { + if (alignDown(SegInfo.FileOffset, PgSize) == FileOffset) { // Use segment's aligned memory offset to calculate the base address. - const uint64_t MemOffset = alignDown(SegInfo.Address, SegInfo.Alignment); - return MMapAddress - MemOffset; + const uint64_t MMapAddressTruncated = alignDown(MMapAddress, PgSize); + const uint64_t MemOffset = alignDown(SegInfo.Address, PgSize); + return MMapAddressTruncated - MemOffset; } }