[lld] [lld][ELF] Fix a corner case of elf::getLoongArchPageDelta (PR #71907)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 19 04:26:50 PST 2023
heiher wrote:
> > Another corner case?
> > DEST: 0 PC: 0x80000ffc
> > ```
> > 80000ffc: 05 00 00 1b pcalau12i $a1, -524288
> > 80001000: 04 00 c0 02 addi.d $a0, $zero, 0
> > 80001004: e4 ff ff 17 lu32i.d $a0, -1
> > 80001008: 84 fc 3f 03 lu52i.d $a0, $a0, -1
> > 8000100c: 84 94 10 00 add.d $a0, $a0, $a1
> > ```
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > ugly test: https://gist.github.com/heiher/3c7a2a9e7d05354e818b50d69e40b8cb
>
> ld is correct in this case.
>
> ```
> 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
> ```
>
> @MQ-mengqing Can you post an example you mentioned in [rui314/mold#1131 (comment)](https://github.com/rui314/mold/issues/1131#issuecomment-1771892552) ?
I found that different ld versions have different results, it doesn't seem to be completely correct? :disappointed:
### DEST: 0 PC: 0x80000ffc
#### ld 2.40 (correct)
```asm
80000ffc: 1b000005 pcalau12i $a1, -524288(0x80000)
80001000: 02c00004 addi.d $a0, $zero, 0
80001004: 16000004 lu32i.d $a0, 0
80001008: 03000084 lu52i.d $a0, $a0, 0
8000100c: 00109484 add.d $a0, $a0, $a1 # $a0 = 0
```
#### ld 2.41 or git mainline (incorrect)
```asm
80000ffc: 1b000005 pcalau12i $a1, -524288(0x80000)
80001000: 02c00004 addi.d $a0, $zero, 0
80001004: 17ffffe4 lu32i.d $a0, -1(0xfffff)
80001008: 033ffc84 lu52i.d $a0, $a0, -1(0xfff)
8000100c: 00109484 add.d $a0, $a0, $a1 # $a0 = 0xffffffff00000000
```
### DEST: 0 PC: 0x80001000
#### ld 2.40 (incorrect)
```asm
80001000: 1affffe5 pcalau12i $a1, 524287(0x7ffff)
80001004: 02c00004 addi.d $a0, $zero, 0
80001008: 16000004 lu32i.d $a0, 0
8000100c: 03000084 lu52i.d $a0, $a0, 0
80001010: 00109484 add.d $a0, $a0, $a1 # $a0 = 0x100000000
```
#### ld 2.41 or git mainline (correct)
```asm
80001000: 1affffe5 pcalau12i $a1, 524287(0x7ffff)
80001004: 02c00004 addi.d $a0, $zero, 0
80001008: 17ffffe4 lu32i.d $a0, -1(0xfffff)
8000100c: 033ffc84 lu52i.d $a0, $a0, -1(0xfff)
80001010: 00109484 add.d $a0, $a0, $a1 # $a0 = 0
```
https://github.com/llvm/llvm-project/pull/71907
More information about the llvm-commits
mailing list