[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
Fri Aug 28 01:38:39 PDT 2026
Jinjie-Huang wrote:
For example (The complete end-to-end translation from runtime address to file offset on a 64KB-page system):
1. Static ELF Parsing
Suppose our ELF binary has a .text segment parsed from the program headers with:
```
Phdr.p_vaddr = 0x411000
Phdr.p_offset = 0x11000
```
We can get `PreferredBaseAddress` = 0x411000 - 0x11000 = 0x400000.
2. OS Runtime Mapping
At runtime, the OS loads this binary with an actual image base of 0x500000. Because ARM64 uses 64KB (0x10000) pages, the OS aligns the mapping down to the nearest page boundary.
The perf mmap event reports this aligned region as:
```
Event.Address = 0x510000
Event.Offset = 0x10000 (Notice this is 0x1000 bytes earlier than the exact 0x11000 offset).
```
We can get `RuntimeBaseAddress` = 0x510000 - 0x10000 = 0x500000.
3. Canonicalization & File Offset Translation
Now, suppose the CPU samples an instruction at runtime address 0x511123. We can trace it back to the exact byte in the binary file:
- Map the runtime address back to the static ELF virtual address space.
```
LoadBias = RuntimeBaseAddress - PreferredBaseAddress = 0x100000
CanonicalAddress = SampleAddress - LoadBias
CanonicalAddress = 0x511123 - 0x100000 = 0x411123
```
- Map the canonical address to the physical file offset.
```
FileOffset = CanonicalAddress - PreferredBaseAddress
FileOffset = 0x411123 - 0x400000 = 0x11123
```
https://github.com/llvm/llvm-project/pull/217887
More information about the llvm-commits
mailing list