Skip to content

Commit 1101829

Browse files
committed
Fixes for reviews.
1 parent b9c2ea1 commit 1101829

File tree

5 files changed

+43
-72
lines changed

5 files changed

+43
-72
lines changed

lld/ELF/Arch/LoongArch.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -840,13 +840,13 @@ static void relaxPCHi20Lo12(Ctx &ctx, const InputSection &sec, size_t i,
840840
// b/bl foo
841841
static void relaxCall36(Ctx &ctx, const InputSection &sec, size_t i,
842842
uint64_t loc, Relocation &r, uint32_t &remove) {
843-
const uint64_t symLocal =
843+
const uint64_t dest =
844844
(r.expr == R_PLT_PC ? r.sym->getPltVA(ctx) : r.sym->getVA(ctx)) +
845845
r.addend;
846846

847-
const int64_t distance = symLocal - loc;
848-
// Check if the distance aligns 4 bytes or exceeds the range of b[l].
849-
if ((distance & 0x3) != 0 || !isInt<28>(distance))
847+
const int64_t displace = dest - loc;
848+
// Check if the displace aligns 4 bytes or exceeds the range of b[l].
849+
if ((displace & 0x3) != 0 || !isInt<28>(displace))
850850
return;
851851

852852
const uint32_t nextInsn = read32le(sec.content().data() + r.offset + 4);

lld/test/ELF/loongarch-relax-call36-2.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# REQUIRES: loongarch
2+
## Relax R_LARCH_CALL36. This test tests boundary cases and some special symbols.
3+
24
# RUN: rm -rf %t && split-file %s %t && cd %t
35
# RUN: llvm-mc -filetype=obj -triple=loongarch64 -mattr=+relax a.s -o a.o
46

lld/test/ELF/loongarch-relax-call36.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# REQUIRES: loongarch
2+
## Relax R_LARCH_CALL36, which involves the macro instructions call36/tail36.
23

34
# RUN: rm -rf %t && split-file %s %t && cd %t
45

lld/test/ELF/loongarch-relax-emit-relocs-2.s

Lines changed: 0 additions & 61 deletions
This file was deleted.

lld/test/ELF/loongarch-relax-emit-relocs.s

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
## Test that we can handle --emit-relocs while relaxing.
33

44
# RUN: llvm-mc --filetype=obj --triple=loongarch32 --mattr=+relax %s -o %t.32.o
5-
# RUN: llvm-mc --filetype=obj --triple=loongarch64 --mattr=+relax %s -o %t.64.o
5+
# RUN: llvm-mc --filetype=obj --triple=loongarch64 --mattr=+relax --defsym ELF64=1 %s -o %t.64.o
66
# RUN: ld.lld -Ttext=0x10000 -section-start=.got=0x20000 --emit-relocs --relax %t.32.o -o %t.32
77
# RUN: ld.lld -Ttext=0x10000 -section-start=.got=0x20000 --emit-relocs --relax %t.64.o -o %t.64
8-
# RUN: llvm-objdump -dr %t.32 | FileCheck %s --check-prefix=RELAX
9-
# RUN: llvm-objdump -dr %t.64 | FileCheck %s --check-prefix=RELAX
8+
# RUN: llvm-objdump -dr %t.32 | FileCheck %s --check-prefixes=RELAX,RELAX32
9+
# RUN: llvm-objdump -dr %t.64 | FileCheck %s --check-prefixes=RELAX,RELAX64
1010

1111
## -r should keep original relocations.
1212
# RUN: ld.lld --relax -r %t.64.o -o %t.64.r
@@ -27,10 +27,19 @@
2727
# RELAX-NEXT: R_LARCH_RELAX *ABS*
2828
# RELAX-NEXT: R_LARCH_PCREL20_S2 _start
2929
# RELAX-NEXT: R_LARCH_RELAX *ABS*
30-
# RELAX-NEXT: nop
31-
# RELAX-NEXT: R_LARCH_ALIGN *ABS*+0xc
32-
# RELAX-NEXT: nop
33-
# RELAX-NEXT: ret
30+
# RELAX32-NEXT: nop
31+
# RELAX32-NEXT: R_LARCH_ALIGN *ABS*+0xc
32+
# RELAX32-NEXT: nop
33+
# RELAX32-NEXT: ret
34+
35+
# RELAX64-NEXT: bl -8
36+
# RELAX64-NEXT: R_LARCH_B26 _start
37+
# RELAX64-NEXT: R_LARCH_RELAX *ABS*
38+
# RELAX64-NEXT: b -12
39+
# RELAX64-NEXT: R_LARCH_B26 _start
40+
# RELAX64-NEXT: R_LARCH_RELAX *ABS*
41+
# RELAX64-NEXT: ret
42+
# RELAX64-NEXT: R_LARCH_ALIGN *ABS*+0xc
3443

3544
# NORELAX: <_start>:
3645
# NORELAX-NEXT: pcalau12i $a0, 0
@@ -45,6 +54,14 @@
4554
# NORELAX-NEXT: ld.d $a0, $a0, 0
4655
# NORELAX-NEXT: R_LARCH_GOT_PC_LO12 _start
4756
# NORELAX-NEXT: R_LARCH_RELAX *ABS*
57+
# NORELAX-NEXT: pcaddu18i $ra, 0
58+
# NORELAX-NEXT: R_LARCH_CALL36 _start
59+
# NORELAX-NEXT: R_LARCH_RELAX *ABS*
60+
# NORELAX-NEXT: jirl $ra, $ra, -16
61+
# NORELAX-NEXT: pcaddu18i $a0, 0
62+
# NORELAX-NEXT: R_LARCH_CALL36 _start
63+
# NORELAX-NEXT: R_LARCH_RELAX *ABS*
64+
# NORELAX-NEXT: jirl $zero, $a0, -24
4865
# NORELAX-NEXT: ret
4966
# NORELAX-NEXT: R_LARCH_ALIGN *ABS*+0xc
5067

@@ -61,6 +78,14 @@
6178
# CHECKR-NEXT: ld.d $a0, $a0, 0
6279
# CHECKR-NEXT: R_LARCH_GOT_PC_LO12 _start
6380
# CHECKR-NEXT: R_LARCH_RELAX *ABS*
81+
# CHECKR-NEXT: pcaddu18i $ra, 0
82+
# CHECKR-NEXT: R_LARCH_CALL36 _start
83+
# CHECKR-NEXT: R_LARCH_RELAX *ABS*
84+
# CHECKR-NEXT: jirl $ra, $ra, 0
85+
# CHECKR-NEXT: pcaddu18i $a0, 0
86+
# CHECKR-NEXT: R_LARCH_CALL36 _start
87+
# CHECKR-NEXT: R_LARCH_RELAX *ABS*
88+
# CHECKR-NEXT: jr $a0
6489
# CHECKR-NEXT: nop
6590
# CHECKR-NEXT: R_LARCH_ALIGN *ABS*+0xc
6691
# CHECKR-NEXT: nop
@@ -71,5 +96,9 @@
7196
_start:
7297
la.pcrel $a0, _start
7398
la.got $a0, _start
99+
.ifdef ELF64
100+
call36 _start
101+
tail36 $a0, _start
102+
.endif
74103
.p2align 4
75104
ret

0 commit comments

Comments
 (0)