[PATCH] D146181: [memprof] Support symbolization of PIE binaries.

Snehasish Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 21 11:37:39 PDT 2023


snehasish added a comment.

PTAL, thanks!



================
Comment at: llvm/lib/ProfileData/RawMemProfReader.cpp:283
+  // Assume 4K pagesize for the machine from which the profile has been
+  // collected. This should be fine for now, in case we want to support other
+  // pagesizes it can be recorded in the raw profile during collection.
----------------
tejohnson wrote:
> Is this limitation going to affect us?
No, the systems we care about default to 4K. Notable exceptions include newer versions of Darwin which use 16K. See a similar assumption made in llvm-profgen [1].

https://github.com/llvm/llvm-project/blob/main/llvm/tools/llvm-profgen/ProfiledBinary.cpp#L316


================
Comment at: llvm/lib/ProfileData/RawMemProfReader.cpp:291
+        // Segment will always be loaded at a page boundary.
+        PreferredTextSegmentAddress = Phdr.p_vaddr & ~(PageSize - 1U);
+        NumExecutableSegments++;
----------------
tejohnson wrote:
> Is it expected that p_vaddr will not be page boundary aligned already?
It most likely will be page (or 2M hugepage aligned) already. The default is to align by 4K [1] and this should almost always be a no-op since even 2M aligned is also 4K aligned.


[1] https://github.com/llvm/llvm-project/blob/main/lld/ELF/Target.h#L112


================
Comment at: llvm/lib/ProfileData/RawMemProfReader.cpp:576
+    const uint64_t AdjustedAddress =
+        VirtualAddress + PreferredTextSegmentAddress - ProfiledTextSegmentStart;
+    return object::SectionedAddress{AdjustedAddress};
----------------
tejohnson wrote:
> I'm a little confused on the difference between PreferredTextSegmentAddress and ProfiledTextSegmentStart, and the arithmetic being done here. Can you clarify?
For non-PIE binaries:
PreferredTextSegmentAddress is non-zero, e.g 0x200000 or 0x400000. In this case the loader will put the segment at the virtual address requested by the binary and the ProfiledTextSegmentStart will be the same as PreferredTextSegmentAddress. Thus this arithmetic is a no-op.

For PIE binaries:
PreferredTextSegmentAddress is zero. The loader is free to place the segment at any address (respecting alignment specified by the header). Then the instruction offset in the binary is computed as the virtual address minus the start address of the ProfiledTextSegment. This assumes p_offset = 0 for the executable segment (added an assertion).

Added comments to the code to clarify.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146181/new/

https://reviews.llvm.org/D146181



More information about the llvm-commits mailing list