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;

0 commit comments

Comments
 (0)