Skip to content

Commit a1a29c3

Browse files
committed
[Mips] Move fixELFSymbolsInTLSFixups to getRelocType
fixELFSymbolsInTLSFixups walks the expression tree, which is complex and unnecessary. As the expression must be relocatable, we can move the code to getRelocType and just set SymA. The behavior is similar to GNU assembler.
1 parent 8ff27bb commit a1a29c3

File tree

3 files changed

+17
-69
lines changed

3 files changed

+17
-69
lines changed

llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp

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

99
#include "MCTargetDesc/MipsFixupKinds.h"
10+
#include "MCTargetDesc/MipsMCExpr.h"
1011
#include "MCTargetDesc/MipsMCTargetDesc.h"
1112
#include "llvm/ADT/STLExtras.h"
1213
#include "llvm/BinaryFormat/ELF.h"
@@ -161,6 +162,22 @@ unsigned MipsELFObjectWriter::getRelocType(MCContext &Ctx,
161162
if (Kind >= FirstLiteralRelocationKind)
162163
return Kind - FirstLiteralRelocationKind;
163164

165+
switch (Target.getRefKind()) {
166+
case MipsMCExpr::MEK_DTPREL:
167+
case MipsMCExpr::MEK_DTPREL_HI:
168+
case MipsMCExpr::MEK_DTPREL_LO:
169+
case MipsMCExpr::MEK_TLSLDM:
170+
case MipsMCExpr::MEK_TLSGD:
171+
case MipsMCExpr::MEK_GOTTPREL:
172+
case MipsMCExpr::MEK_TPREL_HI:
173+
case MipsMCExpr::MEK_TPREL_LO:
174+
if (auto *S = Target.getSymA())
175+
cast<MCSymbolELF>(S->getSymbol()).setType(ELF::STT_TLS);
176+
break;
177+
default:
178+
break;
179+
}
180+
164181
switch (Kind) {
165182
case FK_NONE:
166183
return ELF::R_MIPS_NONE;

llvm/lib/Target/Mips/MCTargetDesc/MipsMCExpr.cpp

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -219,73 +219,6 @@ void MipsMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
219219
Streamer.visitUsedExpr(*getSubExpr());
220220
}
221221

222-
static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) {
223-
switch (Expr->getKind()) {
224-
case MCExpr::Target:
225-
fixELFSymbolsInTLSFixupsImpl(cast<MipsMCExpr>(Expr)->getSubExpr(), Asm);
226-
break;
227-
case MCExpr::Constant:
228-
break;
229-
case MCExpr::Binary: {
230-
const MCBinaryExpr *BE = cast<MCBinaryExpr>(Expr);
231-
fixELFSymbolsInTLSFixupsImpl(BE->getLHS(), Asm);
232-
fixELFSymbolsInTLSFixupsImpl(BE->getRHS(), Asm);
233-
break;
234-
}
235-
case MCExpr::SymbolRef: {
236-
// We're known to be under a TLS fixup, so any symbol should be
237-
// modified. There should be only one.
238-
const MCSymbolRefExpr &SymRef = *cast<MCSymbolRefExpr>(Expr);
239-
cast<MCSymbolELF>(SymRef.getSymbol()).setType(ELF::STT_TLS);
240-
break;
241-
}
242-
case MCExpr::Unary:
243-
fixELFSymbolsInTLSFixupsImpl(cast<MCUnaryExpr>(Expr)->getSubExpr(), Asm);
244-
break;
245-
}
246-
}
247-
248-
void MipsMCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const {
249-
switch (getKind()) {
250-
case MEK_None:
251-
case MEK_Special:
252-
llvm_unreachable("MEK_None and MEK_Special are invalid");
253-
break;
254-
case MEK_CALL_HI16:
255-
case MEK_CALL_LO16:
256-
case MEK_GOT:
257-
case MEK_GOT_CALL:
258-
case MEK_GOT_DISP:
259-
case MEK_GOT_HI16:
260-
case MEK_GOT_LO16:
261-
case MEK_GOT_OFST:
262-
case MEK_GOT_PAGE:
263-
case MEK_GPREL:
264-
case MEK_HI:
265-
case MEK_HIGHER:
266-
case MEK_HIGHEST:
267-
case MEK_LO:
268-
case MEK_NEG:
269-
case MEK_PCREL_HI16:
270-
case MEK_PCREL_LO16:
271-
// If we do have nested target-specific expressions, they will be in
272-
// a consecutive chain.
273-
if (const MipsMCExpr *E = dyn_cast<const MipsMCExpr>(getSubExpr()))
274-
E->fixELFSymbolsInTLSFixups(Asm);
275-
break;
276-
case MEK_DTPREL:
277-
case MEK_DTPREL_HI:
278-
case MEK_DTPREL_LO:
279-
case MEK_TLSLDM:
280-
case MEK_TLSGD:
281-
case MEK_GOTTPREL:
282-
case MEK_TPREL_HI:
283-
case MEK_TPREL_LO:
284-
fixELFSymbolsInTLSFixupsImpl(getSubExpr(), Asm);
285-
break;
286-
}
287-
}
288-
289222
bool MipsMCExpr::isGpOff(MipsExprKind &Kind) const {
290223
if (getKind() == MEK_HI || getKind() == MEK_LO) {
291224
if (const MipsMCExpr *S1 = dyn_cast<const MipsMCExpr>(getSubExpr())) {

llvm/lib/Target/Mips/MCTargetDesc/MipsMCExpr.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ class MipsMCExpr : public MCTargetExpr {
7474
return getSubExpr()->findAssociatedFragment();
7575
}
7676

77-
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override;
78-
7977
static bool classof(const MCExpr *E) {
8078
return E->getKind() == MCExpr::Target;
8179
}

0 commit comments

Comments
 (0)