Description
Summary
The alignment values given for sections as arguments to RTDyldMemoryManager::reserveAllocationSpace
are smaller than the values supplied when calling RTDyldMemoryManager::allocateDataSection
. This inconsistency means that the amount of reserved space may not be sufficient for the later allocations.
Details
This bug is in LLVM 18.1.8. I am cross compiling from x86_64 to aarch64 on macOS (so the object-file format is MachO). Our version of LLVM is slightly modified to support a specialized calling convention, but is otherwise a stock installation.
I added debug output to RuntimeDyld.cpp
where these functions are called and get the following output:
# RuntimeDyldImpl::loadObjectImpl: CodeAlign = 4; RODataAlign = 1; RWDataAlign = 1
# RuntimeDyldImpl::emitSection: Name = __text; Alignment = 8
# RuntimeDyldImpl::emitSection: Name = __const; Alignment = 8
I believe that the issue is related to the fact that different algorithms are used to compute the alignment in the two situations. Specifically, the allocateDataSection
method bumps up the alignment by the stub alignment (which is always 8 bytes for MachO).