[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
Wed Aug 26 23:57:47 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()
----------------
Jinjie-Huang wrote:

Actually it's because that would cause the [coff-profile.test](https://github.com/llvm/llvm-project/blob/llvmorg-24-init/llvm/test/tools/llvm-profgen/X86/Inputs/coff-profile.perfscript) test case to fail(which feeds a PERF_RECORD_MMAP2-style record) without it. In the COFF implementation of [setPreferredTextSegmentAddresses()](https://www.google.com/search?q=https://github.com/llvm/llvm-project/blob/llvmorg-24-init/llvm/tools/llvm-profgen/ProfiledBinary.cpp%23L437), COFF TextSegmentOffsets are section RVAs rather than ELF file offsets, so applying Event.Address - Event.Offset would change the existing COFF behavior.

https://github.com/llvm/llvm-project/pull/217887


More information about the llvm-commits mailing list