[llvm] [JITLink][LoongArch] Ignore R_LARCH_RELAX and check R_LARCH_ALIGN (PR #121097)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 30 21:12:00 PST 2024
zhaoqi5 wrote:
`R_LARCH_ALIGN` cannot be simply ignored. Although tests of `clang-repl` do not meet with error.
But error may occur. For example:
```
.text
.globl main
.type main, at function
main:
nop
ret
.globl br16
br16:
test_br16:
.p2align 4
la.pcrel $a0, br16
.skip (1 << 17 - 16)
beq $t1, $t2, %b16(br16)
```
- Without relax: `llvm-mc --triple=loongarch64 --filetype=obj t.s -o - | llvm-objdump -d -`, two nops should be inserted.
```
0000000000000000 <main>:
0: 00 00 40 03 nop
4: 20 00 00 4c ret
0000000000000008 <test_br16>:
8: 00 00 40 03 nop
c: 00 00 40 03 nop
10: 04 00 00 1a pcalau12i $a0, 0
14: 84 00 c0 02 addi.d $a0, $a0, 0
...
20008: ae 01 00 58 beq $t1, $t2, 0 <test_br16+0x20000>
```
- But with relax: `llvm-mc --triple=loongarch64 --filetype=obj -mattr=+relax t.s -o - | llvm-objdump -d -`, three nops are inserted. The linker is expected to remove one nop to align pcalau12i.
```
0000000000000000 <main>:
0: 00 00 40 03 nop
4: 20 00 00 4c ret
0000000000000008 <test_br16>:
8: 00 00 40 03 nop
c: 00 00 40 03 nop
10: 00 00 40 03 nop
14: 04 00 00 1a pcalau12i $a0, 0
18: 84 00 c0 02 addi.d $a0, $a0, 0
...
2000c: ae 01 00 58 beq $t1, $t2, 0 <test_br16+0x20004>
```
If we ignore `R_LARCH_ALIGN` in jitlink. Nops will not be removed and `beq` will be out of range while running `llvm-jitlink t.o`.
```
llvm-jitlink error: In graph t.o, section .text: relocation target "br16" at address 0x7fffa4000008 is out of range of Branch16PCRel fixup at 0x7fffa402000c (main, 0x7fffa4000000 + 0x2000c)
```
https://github.com/llvm/llvm-project/pull/121097
More information about the llvm-commits
mailing list