[llvm] [llvm-profgen] Handle perf mmaps with page sizes larger than 4 KiB (PR #217887)
Jinjie Huang via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 27 05:36:19 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) &&
----------------
Jinjie-Huang wrote:
Good point. It's really not worth adding a complicated check just to avoid one setBaseAddress call... The reason that extra condition was there is that `RuntimeBaseAddress` represents the absolute load origin (Event.Address - Event.Offset). Because of this, all separate text segments share the same RuntimeBaseAddress. Without this check, it would bypass the baseline logic that verifies whether the segments are loaded consecutively.
https://github.com/llvm/llvm-project/pull/217887
More information about the llvm-commits
mailing list