[PATCH] Initialize memory groups once any is initialized.

Dana Koch via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 29 13:20:06 PDT 2020


JITted code may include relocations between sections, and the
relocations often chosen to do this are 32-bit PC-relative relocation
types. Thus, consideration must be made to ensure sections are allocated
sufficiently close to one another.

The SectionMemoryManager provides three memory groups, one for Code
data, one for ROData, and one for RWdata. Sections are allocated with
mmap (via allocateMappedMemory) which allows the caller to provide a
hint to the system to suggest where to position mmap'ped memory. A
memory group has a Near block which lets successive allocations to that
memory group be positioned near other mappings in that group via the
mmap hint. Initially, this Near block is empty, that is, its address is
nullptr. When mmap is passed a nullptr hint, the system may choose any
location to position the mapping.

This means, prior to this commit, the first Code section mapping, ROData
section mapping, and RWData section mapping will all be placed at a
location of the system's choosing, and the system may choose distant
enough locations in memory such that a 32-bit PC-relative relocation
would overflow.

Therefore, once allocateMappedMemory allocates the first mapping, copy
that Near block hint to the other memory groups. This ensures that
sections are allocated close to another so relative relocations are less
likely to overflow.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Initialize-memory-groups-once-any-is-initialized.patch
Type: text/x-patch
Size: 2491 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200629/801adef2/attachment.bin>


More information about the llvm-commits mailing list