$ mold --version
mold 2.41.0 (45970e661d462fd664e7249a4bfc20ca4d0c6f39; compatible with GNU ld)
For the following assembly:
.section .text
.globl _start
_start:
.reloc ., R_LARCH_RELAX
pcalau12i $t0, %pc_hi20(sym)
.reloc ., R_LARCH_RELAX
addi.d $t0, $t0, %pc_lo12(sym)
.reloc ., R_LARCH_RELAX
pcalau12i $t1, %pc_hi20(sym)
.reloc ., R_LARCH_RELAX
addi.d $t1, $t1, %pc_lo12(sym)
# exit(0)
li.d $a7, 93
li.d $a0, 0
syscall 0
.section .rodata
sym:
.dword 0
... linking the resulting object file with mold produces the following result:
$ clang --target=loongarch64-unknown-linux-gnu -c repro.s -o repro.o
$ clang -nostdlib -static -fuse-ld=mold -Wl,--emit-relocs -o repro repro.o
$ objdump --disassemble --reloc repro
repro: file format elf64-loongarch
Disassembly of section .text:
0000000000210278 <_start>:
210278: 19f7ffcc pcaddi $t0, -16386
210278: R_LARCH_PCALA_HI20 sym
210278: R_LARCH_RELAX *ABS*
21027c: 19f7ffad pcaddi $t1, -16387
21027c: R_LARCH_PCALA_LO12 sym
21027c: R_LARCH_RELAX *ABS*
210280: 0381740b li.w $a7, 0x5d
210280: R_LARCH_PCALA_HI20 sym
210280: R_LARCH_RELAX *ABS*
210284: 03800004 li.w $a0, 0x0
210284: R_LARCH_PCALA_LO12 sym
210284: R_LARCH_RELAX *ABS*
210288: 002b0000 syscall 0x0
The relocations R_LARCH_PCALA_HI20 and R_LARCH_PCALA_LO12 are copied from the object file, but after linker relaxation, they no longer apply and are attached to the wrong instructions.
LLVM once had a similar issue for RISC-V before at 1.
The script above and a Makefile can be found at https://github.com/CSharperMantle/mold-issue-1584.
For the following assembly:
... linking the resulting object file with mold produces the following result:
The relocations
R_LARCH_PCALA_HI20andR_LARCH_PCALA_LO12are copied from the object file, but after linker relaxation, they no longer apply and are attached to the wrong instructions.LLVM once had a similar issue for RISC-V before at 1.
The script above and a Makefile can be found at https://github.com/CSharperMantle/mold-issue-1584.
Footnotes
https://reviews.llvm.org/D159082 ↩