[llvm] [llvm-profgen] Handle perf mmaps with page sizes larger than 4 KiB (PR #217887)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 30 16:18:59 PDT 2026
================
@@ -594,30 +594,42 @@ 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()) {
- Binary->setIsLoadedByMMap(true);
- return;
- }
+ // Check if the target file offset is covered by the mmap event.
+ auto MMapContainsFileOffset = [&](uint64_t FileOffset) {
+ return Event.Offset == FileOffset ||
+ (Event.MemProtectionFlag.contains("x") &&
+ Event.Offset < FileOffset &&
+ FileOffset - Event.Offset < Event.Size);
+ };
+
+ // For ELF, subtract the file offset to get the runtime address corresponding
+ // to file offset zero. Kernel mmap events report the text address as
+ // Event.Offset, so use the text segment offset from the ELF instead.
+ const uint64_t RuntimeBaseAddress =
+ Binary->isCOFF()
+ ? Event.Address
+ : Event.Address -
+ (IsKernel ? Binary->getTextSegmentOffset() : Event.Offset);
- if (IsKernel || Event.Offset == Binary->getTextSegmentOffset()) {
+ if (IsKernel || MMapContainsFileOffset(Binary->getTextSegmentOffset())) {
// A binary image could be unloaded and then reloaded at different
// place, so update binary load address.
// Only update for the first executable segment and assume all other
// segments are loaded at consecutive memory addresses, which is the case on
// X64.
- Binary->setBaseAddress(Event.Address);
+ Binary->setBaseAddress(RuntimeBaseAddress);
----------------
HighW4y2H3ll wrote:
`RuntimeBaseAddress` is only used here. Can we move its calculation under this branch?
https://github.com/llvm/llvm-project/pull/217887
More information about the llvm-commits
mailing list