<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61475>61475</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[llvm-as] strange 'addend too big for relocation' error on aarch64
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
didoudiaz
</td>
</tr>
</table>
<pre>
### Original Problem with a local symbol prefixed by L defined far away
I encounter a problem on MacOS/M1 with a native code compiler producing large assembly files. I have reduced the problem to the following file `bug.s` file (so don't expect any logic, only raw asm instructions). The problem comes when loadind the address of a local symbol prefixed by an `L` (here `Lbar`) which is defined far away. Here is the file `bug.s`:
```
.global foo
foo:
adrp x0, Lbar@PAGE
add x0, x0, Lbar@PAGEOFF
.space 0x800000
Lbar:
ret
```
Here is the output:
```
$ uname -a
Darwin MacBook-Pro-M1.local 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 arm64
$ as --version
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
$ as -o bug.o bug.s
bug.s:3:2: error: addend too big for relocation
adrp x0, Lbar@PAGE
^
bug.s:4:2: error: addend too big for relocation
add x0, x0, Lbar@PAGEOFF
^
bug.s:4:2: error: fixup value out of range
add x0, x0, Lbar@PAGEOFF
^
```
The error occurs on the `adrp` instruction. To be precise `.space 0x7FFFF8` is enough to trigger the error (due to the presence of the `add`instruction after `adrp`).
### No problem when reducing the space between adrp and symbol definition
If I reduce the amount in `.space ` there is no problem:
```
.global foo
foo:
adrp x0, Lbar@PAGE
add x0, x0, Lbar@PAGEOFF
.space 0x7FFFF4
Lbar:
ret
```
Giving:
```
$ as -o bug.o bug.s
$ nm bug.o
0000000000000000 T foo
0000000000000000 t ltmp0
```
As expected, with the `L`prefix, the symbol `Lbar` does not appear in the symbol table.
### No problem when removing the leading L (even with a large space)
Coming back to the original version with, if I remove the `L` prefix, even with the large `.space` the errors disappear (but the `bar` symbol is in the table).
```
.global foo
foo:
adrp x0, bar@PAGE
add x0, x0, bar@PAGEOFF
.space 0x800000
bar:
ret
```
The result:
```
$ as -o bug.o bug.s
$ nm bug.o
0000000000800008 t bar
0000000000000000 T foo
0000000000000000 t ltmp0
```
Any idea ?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEV01v2zgT_jX0ZWCBpmTZOvjgNlHfvptsgzbYa0GJY4lbihRIyo73sL99QUr-aNN206LACobicIZ85vMZmjsnG424IctXZHkz44Nvjd0IKcwgJP9rVhlx3BCWjh94Z2UjNVfwYE2lsIOD9C1wUKbmCtyxq4yC3uJOPqGA6gh3IHAnNQrYcQv8wI-E3hC6Hd9vAXVtBu3RAod-OtNouOf1uw-ElfeLE4LmXu4RaiPCq-ulQht2iKGWugHFbYPAncOuUkfYSYUugbfQ8j2CRTHUKMC3eAbxJv67M0qZQzghbAGS02poEkdyOi2wtTMgjCZs5QGfeqw9cH0EZRpZE_YajFZHsPwA3HUgtfN2qL002hFWJPB4BVmbDh0cWtSgDBdSjxZxISw6B2b3vUByHYy7C4YRtm7RRmPvKm5JTgkr4NDKugXpngU8gf8FbelGh79wk6Tb64yElfEzLRZJo0zFFeyMGdfCl8umggvbE1o80RCMaE9GH7Zvbq8UxFn-TOtdWY6KEKBcz2sE-rSm4YFRErWvAC16QouvmnvtqBl8P_h_cY9lMGjeIcz5uHLD7UHG-ntlzKf5gzXz-0UyZoWxJE0oTCq_odWo4A-0Tho9CUm6hXuj4f9cQ0qBhYV0HV4rePjwCIyylKSvwBoTTHvSw3y9KliyXiTp34yw8v3t3e32w-3H7fv7PPv4mIcwcNvl2WdesAy4g_l8P4KPq9u-Vwi14rqBSQCLLKFJrJi4Pl9klCY0YUXCKCNsiuJjaJ5gzwg15-GkuYh-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