[llvm] [llvm-profgen] Handle perf mmaps with page sizes larger than 4 KiB (PR #217887)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 26 22:20:53 PDT 2026
================
@@ -594,30 +594,48 @@ void PerfScriptReader::updateBinaryAddress(const MMapEvent &Event) {
if (PIDFilter && Event.PID != *PIDFilter)
return;
- // Drop the event if its image is loaded at the same address
- if (Event.Address == Binary->getBaseAddress()) {
+ auto MMapContainsFileOffset = [&](uint64_t FileOffset) {
+ return Event.Offset == FileOffset ||
+ (Event.MemProtectionFlag.contains("x") &&
+ Event.Offset < FileOffset &&
+ FileOffset - Event.Offset < Event.Size);
+ };
+ const bool MMapContainsTextSegment =
+ MMapContainsFileOffset(Binary->getTextSegmentOffset());
+
+ // For user-space ELF, subtract the mmap file offset to get the runtime
+ // address corresponding to file offset zero. Kernel and COFF retain their
+ // existing mmap address semantics.
+ const uint64_t RuntimeBaseAddress = IsKernel || Binary->isCOFF()
+ ? Event.Address
+ : Event.Address - Event.Offset;
+
+ // Drop the event if its image has the same base address.
+ if ((IsKernel || MMapContainsTextSegment) &&
----------------
HighW4y2H3ll wrote:
why is checking `IsKernel` and `MMapContainsTextSegment` necessary? shouldn't `RuntimeBaseAddress == Binary->getBaseAddress()` strict enough? This seems to be a bit redundent just to skip the `Binary->setBaseAddress(RuntimeBaseAddress);`
https://github.com/llvm/llvm-project/pull/217887
More information about the llvm-commits
mailing list