Skip to content

Commit ad45df9

Browse files
committed
[ELF][PPC64] Remove unneeded PPC64PCRelLongBranchThunk
This reverts the PPC64PCRelLongBranchThunk part from D86706. PPC64PCRelLongBranchThunk is the same as PPC64R12SetupStub. Use `__gep_setup_` instead of `__long_branch_pcrel_` for the stub symbol name as it more closely indicates the operation. (Note: GNU ld uses `*.long_branch.*` and `*.plt_branch.*`). Reviewed By: NeHuang, nemanjai Differential Revision: https://reviews.llvm.org/D114656
1 parent 4fa9e43 commit ad45df9

File tree

4 files changed

+6
-61
lines changed

4 files changed

+6
-61
lines changed

lld/ELF/Thunks.cpp

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -399,24 +399,6 @@ class PPC64PDLongBranchThunk final : public PPC64LongBranchThunk {
399399
}
400400
};
401401

402-
// A bl instruction uses a signed 24 bit offset, with an implicit 4 byte
403-
// alignment. This gives a possible 26 bits of 'reach'. If the caller and
404-
// callee do not use toc and the call offset is larger than 26 bits,
405-
// we need to emit a pc-rel based long-branch thunk. The target address of
406-
// the callee is computed with a PC-relative offset.
407-
class PPC64PCRelLongBranchThunk final : public Thunk {
408-
public:
409-
PPC64PCRelLongBranchThunk(Symbol &dest, int64_t addend)
410-
: Thunk(dest, addend) {
411-
alignment = 16;
412-
}
413-
uint32_t size() override { return 32; }
414-
void writeTo(uint8_t *buf) override;
415-
void addSymbols(ThunkSection &isec) override;
416-
bool isCompatibleWith(const InputSection &isec,
417-
const Relocation &rel) const override;
418-
};
419-
420402
} // end anonymous namespace
421403

422404
Defined *Thunk::addSymbol(StringRef name, uint8_t type, uint64_t value,
@@ -1061,42 +1043,6 @@ bool PPC64LongBranchThunk::isCompatibleWith(const InputSection &isec,
10611043
return rel.type == R_PPC64_REL24 || rel.type == R_PPC64_REL14;
10621044
}
10631045

1064-
void PPC64PCRelLongBranchThunk::writeTo(uint8_t *buf) {
1065-
int64_t offset = destination.getVA() - getThunkTargetSym()->getVA();
1066-
if (!isInt<34>(offset))
1067-
reportRangeError(buf, offset, 34, destination,
1068-
"PC-relative long branch stub offset");
1069-
1070-
int nextInstOffset;
1071-
if (!config->power10Stubs) {
1072-
uint32_t off = destination.getVA(addend) - getThunkTargetSym()->getVA() - 8;
1073-
write32(buf + 0, 0x7c0802a6); // mflr r12
1074-
write32(buf + 4, 0x429f0005); // bcl 20,31,.+4
1075-
write32(buf + 8, 0x7d6802a6); // mflr r11
1076-
write32(buf + 12, 0x7d8803a6); // mtlr r12
1077-
write32(buf + 16, 0x3d8b0000 | computeHiBits(off)); // addis r12,r11,off@ha
1078-
write32(buf + 20, 0x398c0000 | (off & 0xffff)); // addi r12,r12,off@l
1079-
nextInstOffset = 24;
1080-
} else {
1081-
uint64_t paddi = PADDI_R12_NO_DISP | (((offset >> 16) & 0x3ffff) << 32) |
1082-
(offset & 0xffff);
1083-
writePrefixedInstruction(buf + 0, paddi); // paddi r12, 0, func@pcrel, 1
1084-
nextInstOffset = 8;
1085-
}
1086-
write32(buf + nextInstOffset, MTCTR_R12); // mtctr r12
1087-
write32(buf + nextInstOffset + 4, BCTR); // bctr
1088-
}
1089-
1090-
void PPC64PCRelLongBranchThunk::addSymbols(ThunkSection &isec) {
1091-
addSymbol(saver.save("__long_branch_pcrel_" + destination.getName()),
1092-
STT_FUNC, 0, isec);
1093-
}
1094-
1095-
bool PPC64PCRelLongBranchThunk::isCompatibleWith(const InputSection &isec,
1096-
const Relocation &rel) const {
1097-
return rel.type == R_PPC64_REL24_NOTOC;
1098-
}
1099-
11001046
Thunk::Thunk(Symbol &d, int64_t a) : destination(d), addend(a), offset(0) {}
11011047

11021048
Thunk::~Thunk() = default;
@@ -1223,9 +1169,7 @@ static Thunk *addThunkPPC64(RelType type, Symbol &s, int64_t a) {
12231169
return make<PPC64R2SaveStub>(s, a);
12241170

12251171
if (type == R_PPC64_REL24_NOTOC)
1226-
return (s.stOther >> 5) > 1
1227-
? (Thunk *)make<PPC64R12SetupStub>(s)
1228-
: (Thunk *)make<PPC64PCRelLongBranchThunk>(s, a);
1172+
return make<PPC64R12SetupStub>(s);
12291173

12301174
if (config->picThunk)
12311175
return make<PPC64PILongBranchThunk>(s, a);

lld/test/ELF/ppc64-pcrel-cross-link.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# NOSWAP-NEXT: blr
3030
# NOSWAP-LABEL: 10030010 <__gep_setup_callee_toc>:
3131
# NOSWAP: bctr
32-
# NOSWAP-LABEL: 10030030 <__long_branch_pcrel_callee_notoc>:
32+
# NOSWAP-LABEL: 10030030 <__gep_setup_callee_notoc>:
3333
# NOSWAP: bctr
3434
# NOSWAP-LABEL: 10040000 <caller_toc>:
3535
# NOSWAP: bl 0x10040020
@@ -68,7 +68,7 @@
6868
# SWAP-NEXT: blr
6969
# SWAP-LABEL: 10040010 <__gep_setup_callee_toc>:
7070
# SWAP: bctr
71-
# SWAP-LABEL: 10040030 <__long_branch_pcrel_callee_notoc>:
71+
# SWAP-LABEL: 10040030 <__gep_setup_callee_notoc>:
7272
# SWAP: bctr
7373

7474
#--- lds

lld/test/ELF/ppc64-pcrel-long-branch-error.s

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
# RUN: ld.lld -shared --script %t/lds %t.o -o %t1 --noinhibit-exec
1919
# RUN: rm %t.o %t1
2020

21-
# CHECK: error: PC-relative long branch stub offset is out of range: 8589934592 is not in [-8589934592, 8589934591]; references high
21+
## Note: GNU ld uses sldi 11, 11, 34 and add 12, 11, 12 to support offsets beyond +-2**33.
22+
# CHECK: error: R12 setup stub offset is out of range: 8589934592 is not in [-8589934592, 8589934591]; references high
2223
# CHECK-NEXT: >>> defined in {{.*}}.o
2324

2425
//--- asm

lld/test/ELF/ppc64-pcrel-long-branch.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# CHECK-NEXT: trap
2828

2929
## Callee address - program counter = 0x2002000 - 0x2010 = 33554416
30-
# CHECK-LABEL: <__long_branch_pcrel_high>:
30+
# CHECK-LABEL: <__gep_setup_high>:
3131
# CHECK-NEXT: 2010: paddi 12, 0, 33554416, 1
3232
# CHECK-NEXT: mtctr 12
3333
# CHECK-NEXT: bctr

0 commit comments

Comments
 (0)