Skip to content

Commit 52eb11f

Browse files
committed
[MC] Replace getSpecifier(Target.getSymA()) with Target.getSymSpecifier()
Add MCValue::getSymSpecifier as a workaround for targets that encode the relocation specifier on SymA. This function asserts that SymA is not null.
1 parent 582b1b2 commit 52eb11f

File tree

13 files changed

+30
-34
lines changed

13 files changed

+30
-34
lines changed

llvm/include/llvm/MC/MCValue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class MCValue {
6767

6868
// Get the relocation specifier from SymA. This is a workaround for targets
6969
// that do not use MCValue::Specifier.
70+
uint16_t getSymSpecifier() const { return SymA->getSpecifier(); }
71+
// Get the relocation specifier from SymA, or 0 when SymA is null.
7072
uint16_t getAccessVariant() const;
7173

7274
static MCValue get(const MCSymbolRefExpr *SymA,

llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8224,7 +8224,7 @@ bool AArch64AsmParser::classifySymbolRef(const MCExpr *Expr,
82248224
return false;
82258225

82268226
if (Res.getSymA())
8227-
DarwinSpec = AArch64MCExpr::Specifier(Res.getSymA()->getKind());
8227+
DarwinSpec = AArch64MCExpr::Specifier(Res.getSymSpecifier());
82288228
Addend = Res.getConstant();
82298229

82308230
// It's some symbol reference + a constant addend, but really

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ unsigned AArch64ELFObjectWriter::getRelocType(MCContext &Ctx,
117117
bool IsNC = AArch64MCExpr::isNotChecked(RefKind);
118118

119119
assert((!Target.getSymA() ||
120-
getSpecifier(Target.getSymA()) == AArch64MCExpr::None ||
121-
getSpecifier(Target.getSymA()) == AArch64MCExpr::VK_PLT ||
122-
getSpecifier(Target.getSymA()) == AArch64MCExpr::VK_GOTPCREL) &&
120+
Target.getSymSpecifier() == AArch64MCExpr::None ||
121+
Target.getSymSpecifier() == AArch64MCExpr::VK_PLT ||
122+
Target.getSymSpecifier() == AArch64MCExpr::VK_GOTPCREL) &&
123123
"Should only be expression-level modifiers here");
124124

125125
switch (SymLoc) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ void AArch64MachObjectWriter::recordRelocation(
221221
// Check for "_foo@got - .", which comes through here as:
222222
// Ltmp0:
223223
// ... _foo@got - Ltmp0
224-
if (getSpecifier(Target.getSymA()) == AArch64MCExpr::M_GOT &&
224+
if (Target.getSymSpecifier() == AArch64MCExpr::M_GOT &&
225225
Asm.getSymbolOffset(*B) ==
226226
Asm.getFragmentOffset(*Fragment) + Fixup.getOffset()) {
227227
// SymB is the PC, so use a PC-rel pointer-to-GOT relocation.
@@ -232,7 +232,7 @@ void AArch64MachObjectWriter::recordRelocation(
232232
MRE.r_word1 = (IsPCRel << 24) | (Log2Size << 25) | (Type << 28);
233233
Writer->addRelocation(A_Base, Fragment->getParent(), MRE);
234234
return;
235-
} else if (getSpecifier(Target.getSymA()) != AArch64MCExpr::None) {
235+
} else if (Target.getSymSpecifier() != AArch64MCExpr::None) {
236236
// Otherwise, neither symbol can be modified.
237237
Asm.getContext().reportError(Fixup.getLoc(),
238238
"unsupported relocation of modified symbol");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ unsigned AArch64WinCOFFObjectWriter::getRelocType(
6262
}
6363

6464
auto Modifier =
65-
Target.isAbsolute() ? AArch64MCExpr::None : Target.getSymA()->getKind();
65+
Target.isAbsolute() ? AArch64MCExpr::None : Target.getSymSpecifier();
6666
const MCExpr *Expr = Fixup.getValue();
6767

6868
if (const AArch64MCExpr *A64E = dyn_cast<AArch64MCExpr>(Expr)) {

llvm/lib/Target/ARM/MCTargetDesc/ARMWinCOFFObjectWriter.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ unsigned ARMWinCOFFObjectWriter::getRelocType(MCContext &Ctx,
4444
const MCFixup &Fixup,
4545
bool IsCrossSection,
4646
const MCAsmBackend &MAB) const {
47-
MCSymbolRefExpr::VariantKind Modifier = Target.isAbsolute()
48-
? MCSymbolRefExpr::VK_None
49-
: Target.getSymA()->getKind();
50-
47+
auto Spec = Target.getAddSym() ? Target.getSymSpecifier() : 0;
5148
unsigned FixupKind = Fixup.getKind();
5249
if (IsCrossSection) {
5350
if (FixupKind != FK_Data_4) {
@@ -64,7 +61,7 @@ unsigned ARMWinCOFFObjectWriter::getRelocType(MCContext &Ctx,
6461
return COFF::IMAGE_REL_ARM_ABSOLUTE;
6562
}
6663
case FK_Data_4:
67-
switch (Modifier) {
64+
switch (Spec) {
6865
case MCSymbolRefExpr::VK_COFF_IMGREL32:
6966
return COFF::IMAGE_REL_ARM_ADDR32NB;
7067
case MCSymbolRefExpr::VK_SECREL:

llvm/lib/Target/PowerPC/MCTargetDesc/PPCXCOFFObjectWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ llvm::createPPCXCOFFObjectWriter(bool Is64Bit) {
4141
std::pair<uint8_t, uint8_t> PPCXCOFFObjectWriter::getRelocTypeAndSignSize(
4242
const MCValue &Target, const MCFixup &Fixup, bool IsPCRel) const {
4343
const auto Specifier =
44-
Target.isAbsolute() ? PPCMCExpr::VK_None : getSpecifier(Target.getSymA());
44+
Target.isAbsolute() ? PPCMCExpr::VK_None : Target.getSymSpecifier();
4545
// People from AIX OS team says AIX link editor does not care about
4646
// the sign bit in the relocation entry "most" of the time.
4747
// The system assembler seems to set the sign bit on relocation entry

llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ unsigned RISCVELFObjectWriter::getRelocType(MCContext &Ctx,
5151
const MCFixup &Fixup,
5252
bool IsPCRel) const {
5353
assert((!Target.getSymA() ||
54-
Target.getSymA()->getKind() == MCSymbolRefExpr::VK_None) &&
54+
Target.getSymSpecifier() == MCSymbolRefExpr::VK_None) &&
5555
"sym@specifier should have been rejected");
5656
const MCExpr *Expr = Fixup.getValue();
5757
// Determine the type of the relocation

llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ unsigned SystemZELFObjectWriter::getRelocType(MCContext &Ctx,
220220
bool SystemZELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
221221
const MCSymbol &Sym,
222222
unsigned Type) const {
223-
switch (getSpecifier(V.getSymA())) {
223+
switch (V.getSymSpecifier()) {
224224
case SystemZMCExpr::VK_GOT:
225225
case SystemZMCExpr::VK_PLT:
226226
return true;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,7 @@ bool X86AsmBackend::fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
744744
if (Fixup.getKind() == FK_Data_1) {
745745
MCValue Target;
746746
if (Fixup.getValue()->evaluateAsRelocatable(Target, &Asm) &&
747-
Target.getSymA() &&
748-
getSpecifier(Target.getSymA()) == X86MCExpr::VK_ABS8)
747+
Target.getSymA() && Target.getSymSpecifier() == X86MCExpr::VK_ABS8)
749748
return false;
750749
}
751750
return true;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ unsigned X86ELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
391391
bool X86ELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
392392
const MCSymbol &Sym,
393393
unsigned Type) const {
394-
switch (getSpecifier(V.getSymA())) {
394+
switch (V.getSymSpecifier()) {
395395
case X86MCExpr::VK_GOT:
396396
case X86MCExpr::VK_PLT:
397397
case X86MCExpr::VK_GOTPCREL:

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void X86MachObjectWriter::RecordX86_64Relocation(
151151
const MCSymbol *B_Base = Writer->getAtom(*B);
152152

153153
// Neither symbol can be modified.
154-
if (getSpecifier(Target.getSymA()) != X86MCExpr::VK_None) {
154+
if (Target.getSymSpecifier()) {
155155
Asm.getContext().reportError(Fixup.getLoc(),
156156
"unsupported relocation of modified symbol");
157157
return;
@@ -266,7 +266,7 @@ void X86MachObjectWriter::RecordX86_64Relocation(
266266
return;
267267
}
268268

269-
auto Specifier = getSpecifier(Target.getSymA());
269+
auto Specifier = Target.getSymSpecifier();
270270
if (IsPCRel) {
271271
if (IsRIPRel) {
272272
if (Specifier == X86MCExpr::VK_GOTPCREL) {
@@ -279,7 +279,7 @@ void X86MachObjectWriter::RecordX86_64Relocation(
279279
Type = MachO::X86_64_RELOC_GOT;
280280
} else if (Specifier == X86MCExpr::VK_TLVP) {
281281
Type = MachO::X86_64_RELOC_TLV;
282-
} else if (Specifier != X86MCExpr::VK_None) {
282+
} else if (Specifier) {
283283
Asm.getContext().reportError(
284284
Fixup.getLoc(), "unsupported symbol modifier in relocation");
285285
return;
@@ -307,7 +307,7 @@ void X86MachObjectWriter::RecordX86_64Relocation(
307307
}
308308
}
309309
} else {
310-
if (Specifier != X86MCExpr::VK_None) {
310+
if (Specifier) {
311311
Asm.getContext().reportError(
312312
Fixup.getLoc(),
313313
"unsupported symbol modifier in branch relocation");
@@ -330,7 +330,7 @@ void X86MachObjectWriter::RecordX86_64Relocation(
330330
Asm.getContext().reportError(
331331
Fixup.getLoc(), "TLVP symbol modifier should have been rip-rel");
332332
return;
333-
} else if (Specifier != X86MCExpr::VK_None) {
333+
} else if (Specifier) {
334334
Asm.getContext().reportError(
335335
Fixup.getLoc(), "unsupported symbol modifier in relocation");
336336
return;
@@ -460,8 +460,8 @@ void X86MachObjectWriter::recordTLVPRelocation(MachObjectWriter *Writer,
460460
const MCFixup &Fixup,
461461
MCValue Target,
462462
uint64_t &FixedValue) {
463-
const MCSymbolRefExpr *SymA = Target.getSymA();
464-
assert(getSpecifier(SymA) == X86MCExpr::VK_TLVP && !is64Bit() &&
463+
const MCSymbol *SymA = Target.getAddSym();
464+
assert(Target.getSymSpecifier() == X86MCExpr::VK_TLVP && !is64Bit() &&
465465
"Should only be called with a 32-bit TLVP relocation!");
466466

467467
unsigned Log2Size = getFixupKindLog2Size(Fixup.getKind());
@@ -489,7 +489,7 @@ void X86MachObjectWriter::recordTLVPRelocation(MachObjectWriter *Writer,
489489
MRE.r_word0 = Value;
490490
MRE.r_word1 =
491491
(IsPCRel << 24) | (Log2Size << 25) | (MachO::GENERIC_RELOC_TLV << 28);
492-
Writer->addRelocation(&SymA->getSymbol(), Fragment->getParent(), MRE);
492+
Writer->addRelocation(SymA, Fragment->getParent(), MRE);
493493
}
494494

495495
void X86MachObjectWriter::RecordX86Relocation(MachObjectWriter *Writer,
@@ -502,8 +502,7 @@ void X86MachObjectWriter::RecordX86Relocation(MachObjectWriter *Writer,
502502
unsigned Log2Size = getFixupKindLog2Size(Fixup.getKind());
503503

504504
// If this is a 32-bit TLVP reloc it's handled a bit differently.
505-
if (Target.getSymA() &&
506-
getSpecifier(Target.getSymA()) == X86MCExpr::VK_TLVP) {
505+
if (Target.getSymA() && Target.getSymSpecifier() == X86MCExpr::VK_TLVP) {
507506
recordTLVPRelocation(Writer, Asm, Fragment, Fixup, Target, FixedValue);
508507
return;
509508
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ unsigned X86WinCOFFObjectWriter::getRelocType(MCContext &Ctx,
5959
}
6060
}
6161

62-
auto Modifier = Target.isAbsolute() ? MCSymbolRefExpr::VK_None
63-
: Target.getSymA()->getKind();
62+
auto Spec = Target.getAddSym() ? Target.getSymSpecifier() : 0;
6463
if (Is64Bit) {
6564
switch (FixupKind) {
6665
case FK_PCRel_4:
@@ -76,9 +75,9 @@ unsigned X86WinCOFFObjectWriter::getRelocType(MCContext &Ctx,
7675
case FK_Data_4:
7776
case X86::reloc_signed_4byte:
7877
case X86::reloc_signed_4byte_relax:
79-
if (Modifier == MCSymbolRefExpr::VK_COFF_IMGREL32)
78+
if (Spec == MCSymbolRefExpr::VK_COFF_IMGREL32)
8079
return COFF::IMAGE_REL_AMD64_ADDR32NB;
81-
if (Modifier == MCSymbolRefExpr::VK_SECREL)
80+
if (Spec == MCSymbolRefExpr::VK_SECREL)
8281
return COFF::IMAGE_REL_AMD64_SECREL;
8382
return COFF::IMAGE_REL_AMD64_ADDR32;
8483
case FK_Data_8:
@@ -100,9 +99,9 @@ unsigned X86WinCOFFObjectWriter::getRelocType(MCContext &Ctx,
10099
case FK_Data_4:
101100
case X86::reloc_signed_4byte:
102101
case X86::reloc_signed_4byte_relax:
103-
if (Modifier == MCSymbolRefExpr::VK_COFF_IMGREL32)
102+
if (Spec == MCSymbolRefExpr::VK_COFF_IMGREL32)
104103
return COFF::IMAGE_REL_I386_DIR32NB;
105-
if (Modifier == MCSymbolRefExpr::VK_SECREL)
104+
if (Spec == MCSymbolRefExpr::VK_SECREL)
106105
return COFF::IMAGE_REL_I386_SECREL;
107106
return COFF::IMAGE_REL_I386_DIR32;
108107
case FK_SecRel_2:

0 commit comments

Comments
 (0)