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

Jinyang He via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 13 17:53:37 PST 2023


================
@@ -159,6 +159,10 @@ uint64_t elf::getLoongArchPageDelta(uint64_t dest, uint64_t pc) {
   bool negativeA = lo12(dest) > 0x7ff;
   bool negativeB = (result & 0x8000'0000) != 0;
 
+  // A corner case; directly return the expected result.
+  if (result == 0xfffffffffffff000 && negativeA)
+    return result = 0xffffffff00000000;
----------------
MQ-mengqing wrote:

I had report this bug to mengqinggang and Rui https://github.com/rui314/mold/issues/1131#issuecomment-1771892552
That's because we can not get consistent PC from `R_LARCH_PCALA_HI20` and `R_LARCH_PCALA64_{LO20,HI12}`. With this fix, we will wrong when span (+2 + 4N)G.

```
0x12344ffc orig (pcalau12i, ori, lu32i, lu52i)
0x92345AAA dest
lo12: 0xAAA
pagedelta: 0x80001000
hi20: 80001000
64_lo20: 0
64_hi12: 0
result: 0xffffffff92345AAA
```


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


More information about the llvm-commits mailing list