| Issue |
244732
|
| Summary |
[fuzzer-found] [ARM] [MC] `bl sym` to an absolute symbol uses its value as a PC-relative offset
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
mu-mu-mu
|
On ARM, a branch to an absolute symbol is encoded as a PC-relative displacement
equal to the symbol's value, and no relocation is emitted. As a result, the
branch goes to the wrong address after linking.
### Reproducer
```asm
.set rom_func, 0x1000
bl rom_func
```
```console
$ clang --target=armv7a-linux-gnueabihf -c arm-bl-absolute-symbol.s
```
### Actual behavior
Trunk (c0005dfe81fe) with assertions:
```console
$ clang --version
clang version 24.0.0git
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/llvm/bin
Build config: +assertions
$ clang --target=armv7a-linux-gnueabihf -c arm-bl-absolute-symbol.s
$ llvm-objdump -dr arm-bl-absolute-symbol.o
00000000 <.text>:
0: eb000400 bl 0x1008 <.text+0x1008> @ imm = #0x1000
$ ld.lld -Ttext=0x20000 arm-bl-absolute-symbol.o && llvm-objdump -d a.out
00020000 <.text>:
20000: eb000400 bl 0x21008 <.text+0x1008> @ imm = #0x1000
```
### Expected behavior
The branch goes to `0x1000` after linking. For reference, GNU as (2.47.50.20261116) emits a relocation against the absolute symbol:
```console
$ arm-linux-gnueabihf-as arm-bl-absolute-symbol.s -o g.o && llvm-objdump -dr g.o
0: ebfffffe bl 0x0 <.text> @ imm = #-0x8
00000000: R_ARM_CALL *ABS*0x1000
```
Found by fuzzing/automated testing: https://discourse.llvm.org/t/assembler-and-inline-assembly-bugs-found-by-fuzzing-and-automated-testing/92917
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs