Skip to content

Commit 2ada0c1

Browse files
committed
[AArch64] 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.
1 parent aead088 commit 2ada0c1

File tree

4 files changed

+16
-47
lines changed

4 files changed

+16
-47
lines changed

llvm/include/llvm/MC/MCExpr.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,9 @@ class MCTargetExpr : public MCExpr {
571571
virtual void visitUsedExpr(MCStreamer& Streamer) const = 0;
572572
virtual MCFragment *findAssociatedFragment() const = 0;
573573

574-
virtual void fixELFSymbolsInTLSFixups(MCAssembler &) const = 0;
574+
// Deprecated way to set the type of referenced ELF symbols to STT_TLS when
575+
// the derived MCELFObjectTargetWriter::getRelocType does not update symbols.
576+
virtual void fixELFSymbolsInTLSFixups(MCAssembler &) const {}
575577

576578
static bool classof(const MCExpr *E) {
577579
return E->getKind() == MCExpr::Target;

llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,19 @@ unsigned AArch64ELFObjectWriter::getRelocType(MCContext &Ctx,
126126
Target.getSymB()->getKind() == MCSymbolRefExpr::VK_None) &&
127127
"Should only be expression-level modifiers here");
128128

129+
switch (SymLoc) {
130+
case AArch64MCExpr::VK_DTPREL:
131+
case AArch64MCExpr::VK_GOTTPREL:
132+
case AArch64MCExpr::VK_TPREL:
133+
case AArch64MCExpr::VK_TLSDESC:
134+
case AArch64MCExpr::VK_TLSDESC_AUTH:
135+
if (auto *S = Target.getSymA())
136+
cast<MCSymbolELF>(S->getSymbol()).setType(ELF::STT_TLS);
137+
break;
138+
default:
139+
break;
140+
}
141+
129142
if (IsPCRel) {
130143
switch (Kind) {
131144
case FK_Data_1:

llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -120,50 +120,6 @@ bool AArch64MCExpr::evaluateAsRelocatableImpl(MCValue &Res,
120120
return true;
121121
}
122122

123-
static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) {
124-
switch (Expr->getKind()) {
125-
case MCExpr::Target:
126-
llvm_unreachable("Can't handle nested target expression");
127-
break;
128-
case MCExpr::Constant:
129-
break;
130-
131-
case MCExpr::Binary: {
132-
const MCBinaryExpr *BE = cast<MCBinaryExpr>(Expr);
133-
fixELFSymbolsInTLSFixupsImpl(BE->getLHS(), Asm);
134-
fixELFSymbolsInTLSFixupsImpl(BE->getRHS(), Asm);
135-
break;
136-
}
137-
138-
case MCExpr::SymbolRef: {
139-
// We're known to be under a TLS fixup, so any symbol should be
140-
// modified. There should be only one.
141-
const MCSymbolRefExpr &SymRef = *cast<MCSymbolRefExpr>(Expr);
142-
cast<MCSymbolELF>(SymRef.getSymbol()).setType(ELF::STT_TLS);
143-
break;
144-
}
145-
146-
case MCExpr::Unary:
147-
fixELFSymbolsInTLSFixupsImpl(cast<MCUnaryExpr>(Expr)->getSubExpr(), Asm);
148-
break;
149-
}
150-
}
151-
152-
void AArch64MCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const {
153-
switch (getSymbolLoc(Kind)) {
154-
default:
155-
return;
156-
case VK_DTPREL:
157-
case VK_GOTTPREL:
158-
case VK_TPREL:
159-
case VK_TLSDESC:
160-
case VK_TLSDESC_AUTH:
161-
break;
162-
}
163-
164-
fixELFSymbolsInTLSFixupsImpl(getSubExpr(), Asm);
165-
}
166-
167123
const AArch64AuthMCExpr *AArch64AuthMCExpr::create(const MCExpr *Expr,
168124
uint16_t Discriminator,
169125
AArch64PACKey::ID Key,

llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ class AArch64MCExpr : public MCTargetExpr {
178178
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
179179
const MCFixup *Fixup) const override;
180180

181-
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override;
182-
183181
static bool classof(const MCExpr *E) {
184182
return E->getKind() == MCExpr::Target;
185183
}

0 commit comments

Comments
 (0)