Skip to content

Commit f3dd9c9

Browse files
committed
Revert "[lld][LoongArch] Relax call36/tail36: R_LARCH_CALL36 (#123576)"
This reverts commit 6fbe491. Broke check-lld, see the many bot comments on #123576
1 parent 029e102 commit f3dd9c9

File tree

4 files changed

+7
-279
lines changed

4 files changed

+7
-279
lines changed

lld/ELF/Arch/LoongArch.cpp

-41
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ enum Op {
5858
LD_W = 0x28800000,
5959
LD_D = 0x28c00000,
6060
JIRL = 0x4c000000,
61-
B = 0x50000000,
62-
BL = 0x54000000,
6361
};
6462

6563
enum Reg {
@@ -832,37 +830,6 @@ static void relaxPCHi20Lo12(Ctx &ctx, const InputSection &sec, size_t i,
832830
remove = 4;
833831
}
834832

835-
// Relax code sequence.
836-
// From:
837-
// pcaddu18i $ra, %call36(foo)
838-
// jirl $ra, $ra, 0
839-
// To:
840-
// b/bl foo
841-
static void relaxCall36(Ctx &ctx, const InputSection &sec, size_t i,
842-
uint64_t loc, Relocation &r, uint32_t &remove) {
843-
const uint64_t dest =
844-
(r.expr == R_PLT_PC ? r.sym->getPltVA(ctx) : r.sym->getVA(ctx)) +
845-
r.addend;
846-
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))
850-
return;
851-
852-
const uint32_t nextInsn = read32le(sec.content().data() + r.offset + 4);
853-
if (getD5(nextInsn) == R_RA) {
854-
// convert jirl to bl
855-
sec.relaxAux->relocTypes[i] = R_LARCH_B26;
856-
sec.relaxAux->writes.push_back(insn(BL, 0, 0, 0));
857-
remove = 4;
858-
} else if (getD5(nextInsn) == R_ZERO) {
859-
// convert jirl to b
860-
sec.relaxAux->relocTypes[i] = R_LARCH_B26;
861-
sec.relaxAux->writes.push_back(insn(B, 0, 0, 0));
862-
remove = 4;
863-
}
864-
}
865-
866833
static bool relax(Ctx &ctx, InputSection &sec) {
867834
const uint64_t secAddr = sec.getVA();
868835
const MutableArrayRef<Relocation> relocs = sec.relocs();
@@ -907,10 +874,6 @@ static bool relax(Ctx &ctx, InputSection &sec) {
907874
if (isPairRelaxable(relocs, i))
908875
relaxPCHi20Lo12(ctx, sec, i, loc, r, relocs[i + 2], remove);
909876
break;
910-
case R_LARCH_CALL36:
911-
if (relaxable(relocs, i))
912-
relaxCall36(ctx, sec, i, loc, r, remove);
913-
break;
914877
}
915878

916879
// For all anchors whose offsets are <= r.offset, they are preceded by
@@ -1014,10 +977,6 @@ void LoongArch::finalizeRelax(int passes) const {
1014977
// RelExpr is needed for relocating.
1015978
r.expr = r.sym->hasFlag(NEEDS_PLT) ? R_PLT_PC : R_PC;
1016979
break;
1017-
case R_LARCH_B26:
1018-
skip = 4;
1019-
write32le(p, aux.writes[writesIdx++]);
1020-
break;
1021980
default:
1022981
llvm_unreachable("unsupported type");
1023982
}

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

-65
This file was deleted.

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

-136
This file was deleted.

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

+7-37
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 --defsym ELF64=1 %s -o %t.64.o
5+
# RUN: llvm-mc --filetype=obj --triple=loongarch64 --mattr=+relax %s -o %t.64.o
66
# RUN: ld.lld -Ttext=0x10000 -section-start=.got=0x20000 --emit-relocs %t.32.o -o %t.32
77
# RUN: ld.lld -Ttext=0x10000 -section-start=.got=0x20000 --emit-relocs %t.64.o -o %t.64
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
8+
# RUN: llvm-objdump -dr %t.32 | FileCheck %s --check-prefix=RELAX
9+
# RUN: llvm-objdump -dr %t.64 | FileCheck %s --check-prefix=RELAX
1010

1111
## -r should keep original relocations.
1212
# RUN: ld.lld -r %t.64.o -o %t.64.r
@@ -27,19 +27,10 @@
2727
# RELAX-NEXT: R_LARCH_RELAX *ABS*
2828
# RELAX-NEXT: R_LARCH_PCREL20_S2 _start
2929
# RELAX-NEXT: R_LARCH_RELAX *ABS*
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
30+
# RELAX-NEXT: nop
31+
# RELAX-NEXT: R_LARCH_ALIGN *ABS*+0xc
32+
# RELAX-NEXT: nop
33+
# RELAX-NEXT: ret
4334

4435
# NORELAX: <_start>:
4536
# NORELAX-NEXT: pcalau12i $a0, 0
@@ -54,14 +45,6 @@
5445
# NORELAX-NEXT: ld.d $a0, $a0, 0
5546
# NORELAX-NEXT: R_LARCH_GOT_PC_LO12 _start
5647
# 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
6548
# NORELAX-NEXT: ret
6649
# NORELAX-NEXT: R_LARCH_ALIGN *ABS*+0xc
6750

@@ -78,14 +61,6 @@
7861
# CHECKR-NEXT: ld.d $a0, $a0, 0
7962
# CHECKR-NEXT: R_LARCH_GOT_PC_LO12 _start
8063
# 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
8964
# CHECKR-NEXT: nop
9065
# CHECKR-NEXT: R_LARCH_ALIGN *ABS*+0xc
9166
# CHECKR-NEXT: nop
@@ -96,10 +71,5 @@
9671
_start:
9772
la.pcrel $a0, _start
9873
la.got $a0, _start
99-
100-
.ifdef ELF64
101-
call36 _start
102-
tail36 $a0, _start
103-
.endif
10474
.p2align 4
10575
ret

0 commit comments

Comments
 (0)