Issue 61475
Summary [llvm-as] strange 'addend too big for relocation' error on aarch64
Labels new issue
Assignees
Reporter didoudiaz
    ### 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 ?

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to