[lld] [lld][ELF] Fix a corner case of elf::getLoongArchPageDelta (PR #71907)
Lu Weining via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 19 08:36:43 PST 2023
SixWeining wrote:
> ```assembly
> .L1:
> pcalau12i $a1, 0 # R_LARCH_PCALA_HI20
> addi.d $a0, $zero, A # R_LARCH_PCALA_LO12
> lu32i.d $a0, B # R_LARCH_PCALA64_LO20
> lu52i.d $a0, $a0, C # R_LARCH_PCALA64_HI12
> add.d $a0, $a0, $a1
> ```
Is it possible to use the `r_addend` of `Elf64_Rela` instead of insn imm bits to store the adjusting bits?
For example:
### Before relocation
The addend should be written by linker but not assembler because assembler doesn't know the page delta of current instruction and `pcalau12i`. (Same as the imm bits approach?)
```
0000000000000000 <_start>:
0: 1a000004 pcalau12i $a0, 0
0: R_LARCH_PCALA_HI20 foo
4: 02c00001 addi.d $ra, $zero, 0
4: R_LARCH_PCALA_LO12 foo
8: 16000001 lu32i.d $ra, 0
8: R_LARCH_PCALA64_LO20 foo+0x10000000
c: 03000021 lu52i.d $ra, $ra, 0
c: R_LARCH_PCALA64_HI12 foo+0x10000000000000
10: 00109021 add.d $ra, $ra, $a0
14: 4c000021 jirl $ra, $ra, 0
```
### After link
```
0000000080000ffc <_start>:
80000ffc: 1b000004 pcalau12i $a0, -524288(0x80000)
80001000: 02c00001 addi.d $ra, $zero, 0
80001004: 16000001 lu32i.d $ra, 0
80001008: 03000021 lu52i.d $ra, $ra, 0
8000100c: 00109021 add.d $ra, $ra, $a0
```
https://github.com/llvm/llvm-project/pull/71907
More information about the llvm-commits
mailing list