[lld] [lld][ELF] Fix a corner case of elf::getLoongArchPageDelta (PR #71907)

Xi Ruoyao via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 22 05:02:18 PST 2023


xry111 wrote:

I cannot figure out any reasonable solution if we allow the address materialize sequence to cross page boundary.  It looks like we'll have to generate something like:

```
.la_sym_1: pcalau12i $a0, %pc_hi20(sym)
nop # "nop" for other instructions scheduled here
nop
nop
addi.d $a1, $zero, %pc_lo12(sym)
nop
nop
lu32i.d $a1, %pc64_lo20(sym + (. - .la_sym_1))
nop
nop
nop
lu52i.d $a1, $a1, %pc64_hi12(sym + (. - la_sym_1))
```

With relaxation disabled, ". - la_sym1" can be evaluated precisely by the assembler so we can store it into the addend; with relaxation enabled, we'll just keep the entire address materializing sequence intact (for taking advantage with relaxation) and we end up:

```
pcalau12i $a0, %pc_hi20(sym)
addi.d $a1, $zero, %pc_lo12(sym)
lu32i.d $a1, %pc64_lo20(sym + 8)
lu52i.d $a1, $a1, %pc64_hi12(sym + 12)
```

"8" and "12" can be encoded into addend too.

https://github.com/llvm/llvm-project/pull/71907


More information about the llvm-commits mailing list