[lld] [lld][ELF] Account for `R_{RISCV,LARCH}_ALIGN` deltas when `--no-relax -emit-relocs` (PR #206321)
Jessica Clarke via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 28 05:55:31 PDT 2026
jrtc27 wrote:
--emit-relocs with RISC-V-style linker relaxation seems like a horrible composition. I mean, it's already somewhat meaningless for "traditional" linker relaxation where the code sequence changes, but at least then it still points to the new block of instructions. But what do you even do if you delete an instruction that a relocation is pointing at? Currently we seem to produce complete and utter nonsense, because (a) we replace relocations for relocations we're deleting with R_RISCV_RELAX (b) we replace relocations for instructions we're rewriting with INTERNAL_R_RISCV_FOO, and both leak into the output:
```
% echo '.globl _start; _start: lui a0, %hi(firstpage); addi a0, a0, %lo(firstpage)' | build/bin/clang -target riscv64 -x assembler - -o - -nostdlib -fuse-ld=lld -Wl,--emit-relocs,--defsym,firstpage=0x123 | pee 'build/bin/llvm-readelf -Wr -' 'build/bin/llvm-objdump -d -'
Relocation section '.rela.text' at offset 0x160 contains 4 entries:
Offset Info Type Symbol's Value Symbol's Name + Addend
0000000000011158 0000000600000033 R_RISCV_RELAX 0000000000000123 firstpage + 0
0000000000011158 0000000000000033 R_RISCV_RELAX 0
0000000000011158 0000000600000102 Unknown 0000000000000123 firstpage + 0
0000000000011158 0000000000000033 R_RISCV_RELAX 0
<stdin>: file format elf64-littleriscv
Disassembly of section .text:
0000000000011158 <_start>:
11158: 12300513 li a0, 0x123
```
Presumably somehow we want the original relocations to be present here at least, somehow, but pointing at what? R_RISCV_ALIGN is surely the least of our worries. But really I'd view this as the nail in the coffin for --emit-relocs, it just makes absolutely no sense to me in this context and I'd argue it should just be a forbidden combination. If we're going to allow it, we should first fix this abomination somehow, based on input from people who are actually using --emit-relocs and can articulate what information they need in the presence of RISC-V-style linker relaxation.
https://github.com/llvm/llvm-project/pull/206321
More information about the llvm-commits
mailing list