Skip to content

Commit 8ec96cc

Browse files
committed
[LoongArch] Move STT_TLS setting from fixELFSymbolsInTLSFixups to getRelocType
The legacy generic code uses `ELFObjectWriter::fixSymbolsInTLSFixups` to set `STT_TLS` (and use an unnecessary expression walk). The better way is to do this in `getRelocType`, which I have done for AArch64, PowerPC, RISC-V, and X86.
1 parent 445837a commit 8ec96cc

File tree

3 files changed

+23
-50
lines changed

3 files changed

+23
-50
lines changed

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "MCTargetDesc/LoongArchFixupKinds.h"
10+
#include "MCTargetDesc/LoongArchMCExpr.h"
1011
#include "MCTargetDesc/LoongArchMCTargetDesc.h"
1112
#include "llvm/BinaryFormat/ELF.h"
1213
#include "llvm/MC/MCContext.h"
1314
#include "llvm/MC/MCELFObjectWriter.h"
1415
#include "llvm/MC/MCFixup.h"
1516
#include "llvm/MC/MCObjectWriter.h"
17+
#include "llvm/MC/MCValue.h"
1618
#include "llvm/Support/ErrorHandling.h"
1719

1820
using namespace llvm;
@@ -48,6 +50,27 @@ unsigned LoongArchELFObjectWriter::getRelocType(MCContext &Ctx,
4850
const MCValue &Target,
4951
const MCFixup &Fixup,
5052
bool IsPCRel) const {
53+
switch (Target.getRefKind()) {
54+
case LoongArchMCExpr::VK_TLS_LE_HI20:
55+
case LoongArchMCExpr::VK_TLS_IE_PC_HI20:
56+
case LoongArchMCExpr::VK_TLS_IE_HI20:
57+
case LoongArchMCExpr::VK_TLS_LD_PC_HI20:
58+
case LoongArchMCExpr::VK_TLS_LD_HI20:
59+
case LoongArchMCExpr::VK_TLS_GD_PC_HI20:
60+
case LoongArchMCExpr::VK_TLS_GD_HI20:
61+
case LoongArchMCExpr::VK_TLS_DESC_PC_HI20:
62+
case LoongArchMCExpr::VK_TLS_DESC_HI20:
63+
case LoongArchMCExpr::VK_TLS_LE_HI20_R:
64+
case LoongArchMCExpr::VK_TLS_LD_PCREL20_S2:
65+
case LoongArchMCExpr::VK_TLS_GD_PCREL20_S2:
66+
case LoongArchMCExpr::VK_TLS_DESC_PCREL20_S2:
67+
if (auto *S = Target.getSymA())
68+
cast<MCSymbolELF>(S->getSymbol()).setType(ELF::STT_TLS);
69+
break;
70+
default:
71+
break;
72+
}
73+
5174
// Determine the type of the relocation
5275
unsigned Kind = Fixup.getTargetKind();
5376

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.cpp

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -232,51 +232,3 @@ LoongArchMCExpr::Specifier LoongArchMCExpr::parseSpecifier(StringRef name) {
232232
.Case("desc_pcrel_20", VK_TLS_DESC_PCREL20_S2)
233233
.Default(VK_None);
234234
}
235-
236-
static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) {
237-
switch (Expr->getKind()) {
238-
case MCExpr::Target:
239-
llvm_unreachable("Can't handle nested target expression");
240-
break;
241-
case MCExpr::Constant:
242-
break;
243-
case MCExpr::Unary:
244-
fixELFSymbolsInTLSFixupsImpl(cast<MCUnaryExpr>(Expr)->getSubExpr(), Asm);
245-
break;
246-
case MCExpr::Binary: {
247-
const MCBinaryExpr *BE = cast<MCBinaryExpr>(Expr);
248-
fixELFSymbolsInTLSFixupsImpl(BE->getLHS(), Asm);
249-
fixELFSymbolsInTLSFixupsImpl(BE->getRHS(), Asm);
250-
break;
251-
}
252-
case MCExpr::SymbolRef: {
253-
// We're known to be under a TLS fixup, so any symbol should be
254-
// modified. There should be only one.
255-
const MCSymbolRefExpr &SymRef = *cast<MCSymbolRefExpr>(Expr);
256-
cast<MCSymbolELF>(SymRef.getSymbol()).setType(ELF::STT_TLS);
257-
break;
258-
}
259-
}
260-
}
261-
262-
void LoongArchMCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const {
263-
switch (specifier) {
264-
default:
265-
return;
266-
case VK_TLS_LE_HI20:
267-
case VK_TLS_IE_PC_HI20:
268-
case VK_TLS_IE_HI20:
269-
case VK_TLS_LD_PC_HI20:
270-
case VK_TLS_LD_HI20:
271-
case VK_TLS_GD_PC_HI20:
272-
case VK_TLS_GD_HI20:
273-
case VK_TLS_DESC_PC_HI20:
274-
case VK_TLS_DESC_HI20:
275-
case VK_TLS_LE_HI20_R:
276-
case VK_TLS_LD_PCREL20_S2:
277-
case VK_TLS_GD_PCREL20_S2:
278-
case VK_TLS_DESC_PCREL20_S2:
279-
break;
280-
}
281-
fixELFSymbolsInTLSFixupsImpl(getSubExpr(), Asm);
282-
}

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ class LoongArchMCExpr : public MCTargetExpr {
105105
return getSubExpr()->findAssociatedFragment();
106106
}
107107

108-
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override;
109-
110108
static bool classof(const MCExpr *E) {
111109
return E->getKind() == MCExpr::Target;
112110
}

0 commit comments

Comments
 (0)