[llvm] Implement reserveAllocationSpace for SectionMemoryManager (PR #71968)

Graham Markall via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 16 09:53:57 PST 2023


https://github.com/gmarkall requested changes to this pull request.

I've tested a fairly similar change (based off these changes) in numba/llvmlite#1009 and the only issue I came across was that the alignment for the code segment requested during reserving the allocation can be smaller than the alignment requested when allocating the code segment - this is because the alignment for the code segment at allocation time takes into account the alignment of the stub (from [here](https://github.com/llvm/llvm-project/blob/main/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp#L851)).

The ultimate effect of this is that sometimes the preallocation can be too small for the later allocation if the code size is right up close to a boundary (a page size boundary?) - for example I saw a preallocation request for 16380 bytes with alignment 4 resulting in an actual preallocation of 16384 bytes, then a later code allocation for 16379 bytes with alignment 8, which ended up trying to use 16392 bytes, slightly larger than the preallocation, and failing. 

I hacked around this by by increasing the code alignment to 8 if it was less than 8 (simply because that seems to be the biggest stub alignment potentially used across all targets) and that seemed to resolve the issue. Ideally I would have queried the stub alignment, but I don't think there's an easy way to do that from within an `RTDyldMemoryManager`.

Perhaps the most correct fix is for `RuntimeDyldImpl::computeTotalAllocSize()` to take the stub alignment into consideration when computing the code segment alignment?

https://github.com/llvm/llvm-project/pull/71968


More information about the llvm-commits mailing list