Bug 31228 - ld (aarch64): undefined reference to `no symbol' for adrp with constant value
Summary: ld (aarch64): undefined reference to `no symbol' for adrp with constant value
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.39
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-01-10 11:44 UTC by Pete Moore
Modified: 2024-01-10 13:23 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pete Moore 2024-01-10 11:44:31 UTC
Consider the following assembly:

```
$ cat adrp.s 
.global _start
_start: adrp x0, 0x8000
```

After assembling and linking:

```
$ aarch64-none-elf-as -o adrp.o adrp.s 
$ aarch64-none-elf-ld -Ttext=0x0 -o adrp.elf adrp.o
aarch64-none-elf-ld: adrp.o: in function `_start':
(.text+0x0): undefined reference to `no symbol'
```

Note, the following trick works (if e.g. _start is known to be 0):

```
$ cat adrp.s 
.global _start
_start: adrp x0, 0x8000 + _start
```

which assembles as desired:

```
$ aarch64-none-elf-objdump -d adrp.elf

adrp.elf:     file format elf64-littleaarch64


Disassembly of section .text:

0000000000000000 <_start>:
   0:	90000040 	adrp	x0, 8000 <_start+0x8000>
```

However, this only works if _start is fixed and known. Being able to specify an absolute (rather than relative) value for the immediate of the adrp instruction is useful for e.g. referencing peripherals at fixed locations which are known to be in the +/- 4GB range of the current address. My particular use case is referencing Raspberry Pi peripheral base addresses when the MMU is not enabled.

Originally reported in bug 27217 comment 30.

```
$ aarch64-none-elf-ld --version
GNU ld (GNU Binutils) 2.39
```
Comment 1 Nick Clifton 2024-01-10 12:18:53 UTC
Hi Pete,

  This bug is fixed in the 2.41 release:

   $ as adrp.s -o adrp.o
   $ ld -Ttext=0 adrp.o 

Cheers
  Nick
Comment 2 Pete Moore 2024-01-10 13:23:10 UTC
Many thanks Nick for quick response! Sorry for not testing on 2.41 before, I should have done that.

On that note, I just went to test this on 2.41 and hit the issue described in bug 30703 comment 16...

Thanks,
Pete