Skip to content

Commit 7ccdc3d

Browse files
committed
[MC] Replace getSymA()->getSymbol() with getAddSym. NFC
We will replace the MCSymbolRefExpr member in MCValue with MCSymbol. This change reduces dependence on MCSymbolRefExpr.
1 parent 2fd6f8f commit 7ccdc3d

File tree

11 files changed

+40
-52
lines changed

11 files changed

+40
-52
lines changed

llvm/lib/MC/ELFObjectWriter.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,10 +1251,9 @@ bool ELFObjectWriter::shouldRelocateWithSymbol(const MCAssembler &Asm,
12511251
const MCSymbolELF *Sym,
12521252
uint64_t C,
12531253
unsigned Type) const {
1254-
const MCSymbolRefExpr *RefA = Val.getSymA();
12551254
// A PCRel relocation to an absolute value has no symbol (or section). We
12561255
// represent that with a relocation to a null section.
1257-
if (!RefA)
1256+
if (!Val.getAddSym())
12581257
return false;
12591258

12601259
// An undefined symbol is not in any section, so the relocation has to point
@@ -1379,8 +1378,8 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
13791378
if (auto *RefB = Target.getSubSym()) {
13801379
// When there is no relocation specifier, a linker relaxation target may
13811380
// emit ADD/SUB relocations for A-B+C.
1382-
if (Target.getSymA() && Backend.handleAddSubRelocations(
1383-
Asm, *Fragment, Fixup, Target, FixedValue))
1381+
if (Target.getAddSym() && Backend.handleAddSubRelocations(
1382+
Asm, *Fragment, Fixup, Target, FixedValue))
13841383
return;
13851384

13861385
const auto &SymB = cast<MCSymbolELF>(*RefB);
@@ -1405,8 +1404,8 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
14051404
}
14061405

14071406
// We either rejected the fixup or folded B into C at this point.
1408-
const MCSymbolRefExpr *RefA = Target.getSymA();
1409-
const auto *SymA = RefA ? cast<MCSymbolELF>(&RefA->getSymbol()) : nullptr;
1407+
const auto *RefA = Target.getAddSym();
1408+
const auto *SymA = RefA ? cast<MCSymbolELF>(RefA) : nullptr;
14101409

14111410
bool ViaWeakRef = false;
14121411
if (SymA && SymA->isVariable()) {

llvm/lib/MC/MCAssembler.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,11 @@ bool MCAssembler::isThumbFunc(const MCSymbol *Symbol) const {
125125
if (V.getSubSym() || V.getRefKind() != MCSymbolRefExpr::VK_None)
126126
return false;
127127

128-
const MCSymbolRefExpr *Ref = V.getSymA();
129-
if (!Ref)
128+
auto *Sym = V.getAddSym();
129+
if (!Sym || V.getSymSpecifier())
130130
return false;
131131

132-
if (Ref->getKind() != MCSymbolRefExpr::VK_None)
133-
return false;
134-
135-
const MCSymbol &Sym = Ref->getSymbol();
136-
if (!isThumbFunc(&Sym))
132+
if (!isThumbFunc(Sym))
137133
return false;
138134

139135
ThumbFuncs.insert(Symbol); // Cache it.
@@ -460,14 +456,14 @@ static bool getSymbolOffsetImpl(const MCAssembler &Asm, const MCSymbol &S,
460456

461457
uint64_t Offset = Target.getConstant();
462458

463-
const MCSymbolRefExpr *A = Target.getSymA();
459+
const MCSymbol *A = Target.getAddSym();
464460
if (A) {
465461
uint64_t ValA;
466462
// FIXME: On most platforms, `Target`'s component symbols are labels from
467463
// having been simplified during evaluation, but on Mach-O they can be
468464
// variables due to PR19203. This, and the line below for `B` can be
469465
// restored to call `getLabelOffset` when PR19203 is fixed.
470-
if (!getSymbolOffsetImpl(Asm, A->getSymbol(), ReportError, ValA))
466+
if (!getSymbolOffsetImpl(Asm, *A, ReportError, ValA))
471467
return false;
472468
Offset += ValA;
473469
}
@@ -516,11 +512,11 @@ const MCSymbol *MCAssembler::getBaseSymbol(const MCSymbol &Symbol) const {
516512
return nullptr;
517513
}
518514

519-
const MCSymbolRefExpr *A = Value.getSymA();
515+
const MCSymbol *A = Value.getAddSym();
520516
if (!A)
521517
return nullptr;
522518

523-
const MCSymbol &ASym = A->getSymbol();
519+
const MCSymbol &ASym = *A;
524520
if (ASym.isCommon()) {
525521
getContext().reportError(Expr->getLoc(),
526522
"Common symbol '" + ASym.getName() +

llvm/lib/MC/MCExpr.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -536,15 +536,14 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
536536
if (Res.getRefKind() != MCSymbolRefExpr::VK_None || !Res.getSymA() ||
537537
Res.getSubSym() || Res.getConstant())
538538
return false;
539-
Res =
540-
MCValue::get(MCSymbolRefExpr::create(&Res.getSymA()->getSymbol(),
541-
Kind, Asm->getContext()),
542-
Res.getSymB(), Res.getConstant(), Res.getRefKind());
539+
Res = MCValue::get(
540+
MCSymbolRefExpr::create(Res.getAddSym(), Kind, Asm->getContext()),
541+
Res.getSymB(), Res.getConstant(), Res.getRefKind());
543542
}
544543
if (!IsMachO)
545544
return true;
546545

547-
const MCSymbolRefExpr *A = Res.getSymA();
546+
auto *A = Res.getAddSym();
548547
auto *B = Res.getSubSym();
549548
// FIXME: This is small hack. Given
550549
// a = b + 4

llvm/lib/MC/MachObjectWriter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ uint64_t MachObjectWriter::getSymbolAddress(const MCSymbol &S,
109109
S.getName() + "'");
110110

111111
// Verify that any used symbols are defined.
112-
if (Target.getSymA() && Target.getSymA()->getSymbol().isUndefined())
112+
if (Target.getSymA() && Target.getAddSym()->isUndefined())
113113
report_fatal_error("unable to evaluate offset to undefined symbol '" +
114-
Target.getSymA()->getSymbol().getName() + "'");
114+
Target.getAddSym()->getName() + "'");
115115
if (Target.getSubSym() && Target.getSubSym()->isUndefined())
116116
report_fatal_error("unable to evaluate offset to undefined symbol '" +
117117
Target.getSubSym()->getName() + "'");
@@ -507,7 +507,7 @@ void MachObjectWriter::writeLinkerOptionsLoadCommand(
507507
static bool isFixupTargetValid(const MCValue &Target) {
508508
// Target is (LHS - RHS + cst).
509509
// We don't support the form where LHS is null: -RHS + cst
510-
if (!Target.getSymA() && Target.getSubSym())
510+
if (!Target.getAddSym() && Target.getSubSym())
511511
return false;
512512
return true;
513513
}

llvm/lib/MC/XCOFFObjectWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ void XCOFFWriter::recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
686686
return SectionMap[ContainingSect]->Address + Asm.getSymbolOffset(*Sym);
687687
};
688688

689-
const MCSymbol *const SymA = &Target.getSymA()->getSymbol();
689+
const MCSymbol *const SymA = Target.getAddSym();
690690

691691
MCAsmBackend &Backend = Asm.getBackend();
692692
bool IsPCRel = Backend.getFixupKindInfo(Fixup.getKind()).Flags &

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,10 @@ void AArch64MachObjectWriter::recordRelocation(
176176
// assembler local symbols. If we got here, that's not what we have,
177177
// so complain loudly.
178178
if (Kind == AArch64::fixup_aarch64_pcrel_branch19) {
179-
Asm.getContext().reportError(Fixup.getLoc(),
180-
"conditional branch requires assembler-local"
181-
" label. '" +
182-
Target.getSymA()->getSymbol().getName() +
183-
"' is external.");
179+
Asm.getContext().reportError(
180+
Fixup.getLoc(), "conditional branch requires assembler-local"
181+
" label. '" +
182+
Target.getAddSym()->getName() + "' is external.");
184183
return;
185184
}
186185

@@ -214,7 +213,7 @@ void AArch64MachObjectWriter::recordRelocation(
214213
// something similar?
215214
}
216215
} else if (auto *B = Target.getSubSym()) { // A - B + constant
217-
const MCSymbol *A = &Target.getSymA()->getSymbol();
216+
const MCSymbol *A = Target.getAddSym();
218217
const MCSymbol *A_Base = Writer->getAtom(*A);
219218
const MCSymbol *B_Base = Writer->getAtom(*B);
220219

@@ -293,7 +292,7 @@ void AArch64MachObjectWriter::recordRelocation(
293292
RelSymbol = B_Base;
294293
Type = MachO::ARM64_RELOC_SUBTRACTOR;
295294
} else { // A + constant
296-
const MCSymbol *Symbol = &Target.getSymA()->getSymbol();
295+
const MCSymbol *Symbol = Target.getAddSym();
297296
const MCSectionMachO &Section =
298297
static_cast<const MCSectionMachO &>(*Fragment->getParent());
299298

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void ARMMachObjectWriter::recordARMScatteredHalfRelocation(
149149
unsigned Type = MachO::ARM_RELOC_HALF;
150150

151151
// See <reloc.h>.
152-
const MCSymbol *A = &Target.getSymA()->getSymbol();
152+
const MCSymbol *A = Target.getAddSym();
153153

154154
if (!A->getFragment()) {
155155
Asm.getContext().reportError(Fixup.getLoc(),
@@ -257,7 +257,7 @@ void ARMMachObjectWriter::recordARMScatteredRelocation(
257257
unsigned IsPCRel = Writer->isFixupKindPCRel(Asm, Fixup.getKind());
258258

259259
// See <reloc.h>.
260-
const MCSymbol *A = &Target.getSymA()->getSymbol();
260+
const MCSymbol *A = Target.getAddSym();
261261

262262
if (!A->getFragment()) {
263263
Asm.getContext().reportError(Fixup.getLoc(),
@@ -388,7 +388,7 @@ void ARMMachObjectWriter::recordRelocation(MachObjectWriter *Writer,
388388
// Get the symbol data, if any.
389389
const MCSymbol *A = nullptr;
390390
if (Target.getSymA())
391-
A = &Target.getSymA()->getSymbol();
391+
A = Target.getAddSym();
392392

393393
// FIXME: For other platforms, we need to use scattered relocations for
394394
// internal relocations with offsets. If this is an internal relocation with

llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2945,15 +2945,14 @@ bool MipsAsmParser::loadAndAddSymbolAddress(const MCExpr *SymExpr,
29452945

29462946
bool IsPtr64 = ABI.ArePtrs64bit();
29472947
bool IsLocalSym =
2948-
Res.getSymA()->getSymbol().isInSection() ||
2949-
Res.getSymA()->getSymbol().isTemporary() ||
2950-
(Res.getSymA()->getSymbol().isELF() &&
2948+
Res.getAddSym()->isInSection() || Res.getAddSym()->isTemporary() ||
2949+
(Res.getAddSym()->isELF() &&
29512950
cast<MCSymbolELF>(Res.getSymA()->getSymbol()).getBinding() ==
29522951
ELF::STB_LOCAL);
29532952
// For O32, "$"-prefixed symbols are recognized as temporary while
29542953
// .L-prefixed symbols are not (PrivateGlobalPrefix is "$"). Recognize ".L"
29552954
// manually.
2956-
if (ABI.IsO32() && Res.getSymA()->getSymbol().getName().starts_with(".L"))
2955+
if (ABI.IsO32() && Res.getAddSym()->getName().starts_with(".L"))
29572956
IsLocalSym = true;
29582957
bool UseXGOT = STI->hasFeature(Mips::FeatureXGOT) && !IsLocalSym;
29592958

llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ namespace {
277277
default:
278278
return false;
279279
case Sparc::fixup_sparc_wplt30:
280-
if (Target.getSymA()->getSymbol().isTemporary())
280+
if (Target.getAddSym()->isTemporary())
281281
return false;
282282
[[fallthrough]];
283283
case Sparc::fixup_sparc_tls_gd_hi22:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ unsigned X86ELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
353353
case X86MCExpr::VK_TLSLDM:
354354
case X86MCExpr::VK_TPOFF:
355355
case X86MCExpr::VK_DTPOFF:
356-
if (auto *S = Target.getSymA())
357-
cast<MCSymbolELF>(S->getSymbol()).setType(ELF::STT_TLS);
356+
if (auto *S = Target.getAddSym())
357+
cast<MCSymbolELF>(S)->setType(ELF::STT_TLS);
358358
break;
359359
default:
360360
break;

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void X86MachObjectWriter::RecordX86_64Relocation(
140140
Type = MachO::X86_64_RELOC_BRANCH;
141141
}
142142
} else if (Target.getSubSym()) { // A - B + constant
143-
const MCSymbol *A = &Target.getSymA()->getSymbol();
143+
const MCSymbol *A = Target.getAddSym();
144144
if (A->isTemporary())
145145
A = &Writer->findAliasedSymbol(*A);
146146
const MCSymbol *A_Base = Writer->getAtom(*A);
@@ -212,7 +212,7 @@ void X86MachObjectWriter::RecordX86_64Relocation(
212212
Index = B->getFragment()->getParent()->getOrdinal() + 1;
213213
Type = MachO::X86_64_RELOC_SUBTRACTOR;
214214
} else {
215-
const MCSymbol *Symbol = &Target.getSymA()->getSymbol();
215+
const MCSymbol *Symbol = Target.getAddSym();
216216
if (Symbol->isTemporary() && Value) {
217217
const MCSection &Sec = Symbol->getSection();
218218
if (!MCAsmInfoDarwin::isSectionAtomizableBySymbols(Sec))
@@ -370,7 +370,7 @@ bool X86MachObjectWriter::recordScatteredRelocation(MachObjectWriter *Writer,
370370
unsigned Type = MachO::GENERIC_RELOC_VANILLA;
371371

372372
// See <reloc.h>.
373-
const MCSymbol *A = &Target.getSymA()->getSymbol();
373+
const MCSymbol *A = Target.getAddSym();
374374

375375
if (!A->getFragment()) {
376376
Asm.getContext().reportError(
@@ -500,9 +500,10 @@ void X86MachObjectWriter::RecordX86Relocation(MachObjectWriter *Writer,
500500
uint64_t &FixedValue) {
501501
unsigned IsPCRel = Writer->isFixupKindPCRel(Asm, Fixup.getKind());
502502
unsigned Log2Size = getFixupKindLog2Size(Fixup.getKind());
503+
const MCSymbol *A = Target.getAddSym();
503504

504505
// If this is a 32-bit TLVP reloc it's handled a bit differently.
505-
if (Target.getSymA() && Target.getSymSpecifier() == X86MCExpr::VK_TLVP) {
506+
if (A && Target.getSymSpecifier() == X86MCExpr::VK_TLVP) {
506507
recordTLVPRelocation(Writer, Asm, Fragment, Fixup, Target, FixedValue);
507508
return;
508509
}
@@ -516,11 +517,6 @@ void X86MachObjectWriter::RecordX86Relocation(MachObjectWriter *Writer,
516517
return;
517518
}
518519

519-
// Get the symbol data, if any.
520-
const MCSymbol *A = nullptr;
521-
if (Target.getSymA())
522-
A = &Target.getSymA()->getSymbol();
523-
524520
// If this is an internal relocation with an offset, it also needs a scattered
525521
// relocation entry.
526522
uint32_t Offset = Target.getConstant();

0 commit comments

Comments
 (0)