<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/125529>125529</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Inconsistent section-alignment values in RuntimeDyld
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
JohnReppy
</td>
</tr>
</table>
<pre>
## 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:
```console
# 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 Mach).
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVE2P2zYQ_TX0ZbCCTMmKfNDByWKBLbJdIBu0x2BEjiS2_BD4YUf99QUle3eRtjkUMCxgQM578-Y9YghqtEQdO3xkh_sdpjg53_3iJvuF5nnZ9U4uHeMV4xW8JGPQL6w8sfL0dSJArUZryEY4o04UYFRnsjA4D4FEVM4GwADox5RPBYgOWFN--Xq_aPlExvnlCS2O5Fl1YtXJUyB_ppPWTmC-_jKjINaUgJ4gGNSaPMQJLcSJbqAhzbNWJOEykQWBWis7_hQHNwC6x4gvG1HWlAXA10kFUFY4G1SIZMUChtCGjBlXTDQu2QhugCtZCSGTBI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