<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/94478>94478</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[RuntimeDyld][ELF] Unwanted sign-extension when computing stub addresses.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
al45tair
</td>
</tr>
</table>
<pre>
The RuntimeDyldELF implementation tries to make a stub, it uses an expression like
```
reinterpret_cast<uint64_t>(Section.getAddressWithOffset(Section.getStubOffset()))
```
to get the address of the stub it's generating as a `uint64_t`.
Sadly, on 32-bit platforms where addresses are regarded as signed, because `getAddressWithOffset()` returns a `uint8_t *` pointer, this can cause unwanted sign-extension, so if (for instance) the code has been loaded at `0xf1a10000`, and the stub is at offset `4`, the resulting `uint64_t` will be `0xfffffffff1a10004` instead of the expected `0xf1a10004`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0U19v4ygQ_zT4ZdQIY5PED37oNs3TSidd73SP1diMbW4xWDDett_-BM32utJuhBIRht-_YTAlO3uiXugvQl8q3HkJsUfXakYbqyGYt_6vheDP3bNd6fLmzOPXK9h1c7SSZ2QbPHC0lIADrPiNACHxPgj1AJZhT5QAPdDrFimlXO3sNxLyIuS9OMrbKttI1jPFLRI_j5hYNA-79Xxsn1k0j0Kdn2jMfIeZ-N6YjPeP5eWPaUrEPx8_8T58_C9Ud1u_YuUAMzHwQoDvoBCmss02wLJQpwQzeYrI1s-ACRDEUX5oO8rDDbl8P6Fxb9l-8NCou8EybA55CnFN8LJQ_CDK0USCSDNGQyYjl36YfHugEfdEmek3frOjo4RIvEf_SdT5mUGo7BO2UCLNeLzYBCN6eIfd_Qt6JlMY7-iVyefu5MoUwE4g1HkKEaxPjH4koboSyhgMwYIJBiIPLmARzplbvk411lLKEq56APTmU5Apl4UiPle3t6JcECntroT7c67wYp2DgW7oPz7vLBmgyCM0P1pGrxuN2dVnObnwUJm-MV3TYUV9fapPuutkp6ul19iMrW70iQaUpp5k3RB1pjvJs9GnGivbK6laeZS6bnXd6IPE8Si1OTZn2RptOtFKWtG6g3Pf10OIc2VT2qnv2vZ0rhwO5FKZMKU8vUA5FErlgYt9vnM37HMSrXQ2cfofhS27Mpqfpk_oi9BfHr9ehb7A37_uYX5kHsawbnvJtMT_8eQO1R5dvzBvSTT3Ql2Fus6Wl304jGEV6pr5bz93Wwz_0shCXYvqJNT13dX3Xv0XAAD___aUXmI">