[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
Tue Aug 25 20:46:02 PDT 2026
================
@@ -362,25 +362,20 @@ template <class ELFT>
void ProfiledBinary::setPreferredTextSegmentAddresses(const ELFFile<ELFT> &Obj,
StringRef FileName) {
const auto &PhdrRange = unwrapOrError(Obj.program_headers(), FileName);
- // FIXME: This should be the page size of the system running profiling.
- // However such info isn't available at post-processing time, assuming
- // 4K page now. Note that we don't use EXEC_PAGESIZE from <linux/param.h>
- // because we may build the tools on non-linux.
- uint64_t PageSize = 0x1000;
bool SeenFirstLoadableSegment = false;
for (const typename ELFT::Phdr &Phdr : PhdrRange) {
if (Phdr.p_type == ELF::PT_INTERP)
HasInterp = true;
if (Phdr.p_type == ELF::PT_LOAD) {
if (!SeenFirstLoadableSegment) {
- FirstLoadableAddress = Phdr.p_vaddr & ~(PageSize - 1U);
+ // Derive the preferred address corresponding to file offset zero
+ // without assuming a page size.
+ FirstLoadableAddress = Phdr.p_vaddr - Phdr.p_offset;
SeenFirstLoadableSegment = true;
}
if (Phdr.p_flags & ELF::PF_X) {
- // Segments will always be loaded at a page boundary.
- PreferredTextSegmentAddresses.push_back(Phdr.p_vaddr &
- ~(PageSize - 1U));
- TextSegmentOffsets.push_back(Phdr.p_offset & ~(PageSize - 1U));
+ PreferredTextSegmentAddresses.push_back(Phdr.p_vaddr);
----------------
Jinjie-Huang wrote:
`PreferredTextSegmentAddresses` and `TextSegmentOffsets` are no longer stored as 'mmap start addresses'. Instead, they are now stored as the exact segment starts from the ELF. Therefore, we just need to verify that the difference `PreferredTextSegmentAddress - TextSegmentOffset` remains consistent, and there is no need to align them with a specific pagesize.
https://github.com/llvm/llvm-project/pull/217887
More information about the llvm-commits
mailing list