Skip to content

Commit c177dbe

Browse files
authored
Move X86-specific MCSymbolRefExpr::VariantKind to X86MCExpr::Specifier
Move target-specific members outside of MCSymbolRefExpr::VariantKind (a legacy interface I am eliminating). Most changes are mechanic, except: * ELFObjectWriter::shouldRelocateWithSymbol * 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, and RISC-V. In the future, we should encode expressions with a relocation specifier as X86MCExpr and use MCValue::RefKind to hold the specifier of the relocatable expression. https://maskray.me/blog/2025-03-16-relocation-generation-in-assemblers While here, rename "Modifier' to "Specifier": > "Relocation modifier", though concise, suggests adjustments happen during the linker's relocation step rather than the assembler's expression evaluation. I landed on "relocation specifier" as the winner. It's clear, aligns with Arm and IBM’s usage, and fits the assembler's role seamlessly. Pull Request: llvm#132149
1 parent 0ca10ef commit c177dbe

17 files changed

+230
-164
lines changed

llvm/include/llvm/MC/MCExpr.h

+1-10
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,10 @@ class MCSymbolRefExpr : public MCExpr {
199199
VK_GOT,
200200
VK_GOTENT,
201201
VK_GOTOFF,
202-
VK_GOTREL,
203-
VK_PCREL,
204202
VK_GOTPCREL,
205-
VK_GOTPCREL_NORELAX,
206203
VK_GOTTPOFF,
207204
VK_INDNTPOFF,
208205
VK_NTPOFF,
209-
VK_GOTNTPOFF,
210206
VK_PLT,
211207
VK_TLSGD,
212208
VK_TLSLD,
@@ -223,7 +219,6 @@ class MCSymbolRefExpr : public MCExpr {
223219
VK_GOTPAGE,
224220
VK_GOTPAGEOFF,
225221
VK_SECREL,
226-
VK_SIZE, // symbol@SIZE
227222
VK_WEAKREF, // The link between the symbols in .weakref foo, bar
228223
VK_FUNCDESC,
229224
VK_GOTFUNCDESC,
@@ -232,9 +227,6 @@ class MCSymbolRefExpr : public MCExpr {
232227
VK_TLSLDM_FDPIC,
233228
VK_GOTTPOFF_FDPIC,
234229

235-
VK_X86_ABS8,
236-
VK_X86_PLTOFF,
237-
238230
VK_ARM_NONE,
239231
VK_ARM_GOT_PREL,
240232
VK_ARM_TARGET1,
@@ -261,8 +253,7 @@ class MCSymbolRefExpr : public MCExpr {
261253
VK_AMDGPU_ABS32_LO, // symbol@abs32@lo
262254
VK_AMDGPU_ABS32_HI, // symbol@abs32@hi
263255

264-
VK_TPREL,
265-
VK_DTPREL
256+
FirstTargetSpecifier,
266257
};
267258

268259
private:

llvm/lib/MC/ELFObjectWriter.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,6 @@ bool ELFObjectWriter::shouldRelocateWithSymbol(const MCAssembler &Asm,
12691269
case MCSymbolRefExpr::VK_GOT:
12701270
case MCSymbolRefExpr::VK_PLT:
12711271
case MCSymbolRefExpr::VK_GOTPCREL:
1272-
case MCSymbolRefExpr::VK_GOTPCREL_NORELAX:
12731272
return true;
12741273
}
12751274

@@ -1526,16 +1525,13 @@ void ELFObjectWriter::fixSymbolsInTLSFixups(MCAssembler &Asm,
15261525
case MCSymbolRefExpr::VK_GOTTPOFF:
15271526
case MCSymbolRefExpr::VK_INDNTPOFF:
15281527
case MCSymbolRefExpr::VK_NTPOFF:
1529-
case MCSymbolRefExpr::VK_GOTNTPOFF:
15301528
case MCSymbolRefExpr::VK_TLSCALL:
15311529
case MCSymbolRefExpr::VK_TLSDESC:
15321530
case MCSymbolRefExpr::VK_TLSGD:
15331531
case MCSymbolRefExpr::VK_TLSLD:
15341532
case MCSymbolRefExpr::VK_TLSLDM:
15351533
case MCSymbolRefExpr::VK_TPOFF:
1536-
case MCSymbolRefExpr::VK_TPREL:
15371534
case MCSymbolRefExpr::VK_DTPOFF:
1538-
case MCSymbolRefExpr::VK_DTPREL:
15391535
break;
15401536
}
15411537
Asm.registerSymbol(symRef.getSymbol());

llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2116,7 +2116,7 @@ bool X86AsmParser::ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &End) {
21162116
if (IDVal == "f" || IDVal == "b") {
21172117
MCSymbol *Sym =
21182118
getContext().getDirectionalLocalSymbol(IntVal, IDVal == "b");
2119-
MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
2119+
auto Variant = X86MCExpr::VK_None;
21202120
const MCExpr *Val =
21212121
MCSymbolRefExpr::create(Sym, Variant, getContext());
21222122
if (IDVal == "b" && Sym->isUndefined())
@@ -2263,7 +2263,7 @@ bool X86AsmParser::ParseIntelInlineAsmIdentifier(
22632263
return false;
22642264
// Create the symbol reference.
22652265
MCSymbol *Sym = getContext().getOrCreateSymbol(Identifier);
2266-
MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
2266+
auto Variant = X86MCExpr::VK_None;
22672267
Val = MCSymbolRefExpr::create(Sym, Variant, getParser().getContext());
22682268
return false;
22692269
}

llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "MCTargetDesc/X86BaseInfo.h"
1010
#include "MCTargetDesc/X86EncodingOptimization.h"
1111
#include "MCTargetDesc/X86FixupKinds.h"
12+
#include "MCTargetDesc/X86MCExpr.h"
1213
#include "llvm/ADT/StringSwitch.h"
1314
#include "llvm/BinaryFormat/ELF.h"
1415
#include "llvm/BinaryFormat/MachO.h"
@@ -360,7 +361,7 @@ static bool hasVariantSymbol(const MCInst &MI) {
360361
continue;
361362
const MCExpr &Expr = *Operand.getExpr();
362363
if (Expr.getKind() == MCExpr::SymbolRef &&
363-
cast<MCSymbolRefExpr>(Expr).getKind() != MCSymbolRefExpr::VK_None)
364+
getSpecifier(cast<MCSymbolRefExpr>(&Expr)) != X86MCExpr::VK_None)
364365
return true;
365366
}
366367
return false;
@@ -746,7 +747,7 @@ bool X86AsmBackend::fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
746747
MCValue Target;
747748
if (Fixup.getValue()->evaluateAsRelocatable(Target, &Asm) &&
748749
Target.getSymA() &&
749-
Target.getSymA()->getKind() == MCSymbolRefExpr::VK_X86_ABS8)
750+
getSpecifier(Target.getSymA()) == X86MCExpr::VK_ABS8)
750751
return false;
751752
}
752753
return true;

0 commit comments

Comments
 (0)