[llvm] r237799 - MC: Use MCSymbol in MachObjectWriter, NFC
Duncan P. N. Exon Smith
dexonsmith at apple.com
Wed May 20 08:16:15 PDT 2015
Author: dexonsmith
Date: Wed May 20 10:16:14 2015
New Revision: 237799
URL: http://llvm.org/viewvc/llvm-project?rev=237799&view=rev
Log:
MC: Use MCSymbol in MachObjectWriter, NFC
Replace uses of `MCSymbolData` with `MCSymbol` where both are needed, so
we can remove the backpointer.
Modified:
llvm/trunk/include/llvm/MC/MCMachObjectWriter.h
llvm/trunk/lib/MC/MachObjectWriter.cpp
llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp
llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp
Modified: llvm/trunk/include/llvm/MC/MCMachObjectWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCMachObjectWriter.h?rev=237799&r1=237798&r2=237799&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCMachObjectWriter.h (original)
+++ llvm/trunk/include/llvm/MC/MCMachObjectWriter.h Wed May 20 10:16:14 2015
@@ -81,7 +81,7 @@ class MachObjectWriter : public MCObject
/// MachSymbolData - Helper struct for containing some precomputed information
/// on symbols.
struct MachSymbolData {
- MCSymbolData *SymbolData;
+ const MCSymbol *Symbol;
uint64_t StringIndex;
uint8_t SectionIndex;
@@ -152,7 +152,7 @@ public:
uint64_t getPaddingSize(const MCSectionData *SD,
const MCAsmLayout &Layout) const;
- bool doesSymbolRequireExternRelocation(const MCSymbolData *SD);
+ bool doesSymbolRequireExternRelocation(const MCSymbol &S);
/// @}
Modified: llvm/trunk/lib/MC/MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MachObjectWriter.cpp?rev=237799&r1=237798&r2=237799&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/MachObjectWriter.cpp Wed May 20 10:16:14 2015
@@ -39,15 +39,14 @@ void MachObjectWriter::reset() {
MCObjectWriter::reset();
}
-bool MachObjectWriter::
-doesSymbolRequireExternRelocation(const MCSymbolData *SD) {
+bool MachObjectWriter::doesSymbolRequireExternRelocation(const MCSymbol &S) {
// Undefined symbols are always extern.
- if (SD->getSymbol().isUndefined())
+ if (S.isUndefined())
return true;
// References to weak definitions require external relocation entries; the
// definition may not always be the one in the same object file.
- if (SD->getFlags() & SF_WeakDefinition)
+ if (S.getData().getFlags() & SF_WeakDefinition)
return true;
// Otherwise, we can use an internal relocation.
@@ -56,8 +55,7 @@ doesSymbolRequireExternRelocation(const
bool MachObjectWriter::
MachSymbolData::operator<(const MachSymbolData &RHS) const {
- return SymbolData->getSymbol().getName() <
- RHS.SymbolData->getSymbol().getName();
+ return Symbol->getName() < RHS.Symbol->getName();
}
bool MachObjectWriter::isFixupKindPCRel(const MCAssembler &Asm, unsigned Kind) {
@@ -303,15 +301,15 @@ void MachObjectWriter::WriteDysymtabLoad
MachObjectWriter::MachSymbolData *
MachObjectWriter::findSymbolData(const MCSymbol &Sym) {
for (auto &Entry : LocalSymbolData)
- if (&Entry.SymbolData->getSymbol() == &Sym)
+ if (Entry.Symbol == &Sym)
return &Entry;
for (auto &Entry : ExternalSymbolData)
- if (&Entry.SymbolData->getSymbol() == &Sym)
+ if (Entry.Symbol == &Sym)
return &Entry;
for (auto &Entry : UndefinedSymbolData)
- if (&Entry.SymbolData->getSymbol() == &Sym)
+ if (Entry.Symbol == &Sym)
return &Entry;
return nullptr;
@@ -331,8 +329,8 @@ const MCSymbol &MachObjectWriter::findAl
void MachObjectWriter::WriteNlist(MachSymbolData &MSD,
const MCAsmLayout &Layout) {
- MCSymbolData &Data = *MSD.SymbolData;
- const MCSymbol *Symbol = &Data.getSymbol();
+ const MCSymbol *Symbol = MSD.Symbol;
+ MCSymbolData &Data = Symbol->getData();
const MCSymbol *AliasedSymbol = &findAliasedSymbol(*Symbol);
uint8_t SectionIndex = MSD.SectionIndex;
uint8_t Type = 0;
@@ -570,7 +568,7 @@ void MachObjectWriter::ComputeSymbolTabl
continue;
MachSymbolData MSD;
- MSD.SymbolData = &SD;
+ MSD.Symbol = &Symbol;
MSD.StringIndex = StringTable.getOffset(Symbol.getName());
if (Symbol.isUndefined()) {
@@ -598,7 +596,7 @@ void MachObjectWriter::ComputeSymbolTabl
continue;
MachSymbolData MSD;
- MSD.SymbolData = &SD;
+ MSD.Symbol = &Symbol;
MSD.StringIndex = StringTable.getOffset(Symbol.getName());
if (Symbol.isAbsolute()) {
@@ -618,11 +616,11 @@ void MachObjectWriter::ComputeSymbolTabl
// Set the symbol indices.
Index = 0;
for (unsigned i = 0, e = LocalSymbolData.size(); i != e; ++i)
- LocalSymbolData[i].SymbolData->setIndex(Index++);
+ LocalSymbolData[i].Symbol->getData().setIndex(Index++);
for (unsigned i = 0, e = ExternalSymbolData.size(); i != e; ++i)
- ExternalSymbolData[i].SymbolData->setIndex(Index++);
+ ExternalSymbolData[i].Symbol->getData().setIndex(Index++);
for (unsigned i = 0, e = UndefinedSymbolData.size(); i != e; ++i)
- UndefinedSymbolData[i].SymbolData->setIndex(Index++);
+ UndefinedSymbolData[i].Symbol->getData().setIndex(Index++);
for (const MCSectionData &SD : Asm) {
std::vector<RelAndSymbol> &Relocs = Relocations[&SD];
Modified: llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp?rev=237799&r1=237798&r2=237799&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp Wed May 20 10:16:14 2015
@@ -44,9 +44,8 @@ class ARMMachObjectWriter : public MCMac
bool requiresExternRelocation(MachObjectWriter *Writer,
const MCAssembler &Asm,
- const MCFragment &Fragment,
- unsigned RelocType, const MCSymbolData *SD,
- uint64_t FixedValue);
+ const MCFragment &Fragment, unsigned RelocType,
+ const MCSymbol &S, uint64_t FixedValue);
public:
ARMMachObjectWriter(bool Is64Bit, uint32_t CPUType,
@@ -309,10 +308,10 @@ bool ARMMachObjectWriter::requiresExtern
const MCAssembler &Asm,
const MCFragment &Fragment,
unsigned RelocType,
- const MCSymbolData *SD,
+ const MCSymbol &S,
uint64_t FixedValue) {
// Most cases can be identified purely from the symbol.
- if (Writer->doesSymbolRequireExternRelocation(SD))
+ if (Writer->doesSymbolRequireExternRelocation(S))
return true;
int64_t Value = (int64_t)FixedValue; // The displacement is signed.
int64_t Range;
@@ -334,8 +333,7 @@ bool ARMMachObjectWriter::requiresExtern
// BL/BLX also use external relocations when an internal relocation
// would result in the target being out of range. This gives the linker
// enough information to generate a branch island.
- const MCSectionData &SymSD = Asm.getSectionData(
- SD->getSymbol().getSection());
+ const MCSectionData &SymSD = Asm.getSectionData(S.getSection());
Value += Writer->getSectionAddress(&SymSD);
Value -= Writer->getSectionAddress(Fragment.getParent());
// If the resultant value would be out of range for an internal relocation,
@@ -375,9 +373,9 @@ void ARMMachObjectWriter::RecordRelocati
}
// Get the symbol data, if any.
- const MCSymbolData *SD = nullptr;
+ const MCSymbol *A = nullptr;
if (Target.getSymA())
- SD = &Asm.getSymbolData(Target.getSymA()->getSymbol());
+ A = &Target.getSymA()->getSymbol();
// FIXME: For other platforms, we need to use scattered relocations for
// internal relocations with offsets. If this is an internal relocation with
@@ -387,7 +385,7 @@ void ARMMachObjectWriter::RecordRelocati
uint32_t Offset = Target.getConstant();
if (IsPCRel && RelocType == MachO::ARM_RELOC_VANILLA)
Offset += 1 << Log2Size;
- if (Offset && SD && !Writer->doesSymbolRequireExternRelocation(SD))
+ if (Offset && A && !Writer->doesSymbolRequireExternRelocation(*A))
return RecordARMScatteredRelocation(Writer, Asm, Layout, Fragment, Fixup,
Target, RelocType, Log2Size,
FixedValue);
@@ -404,29 +402,28 @@ void ARMMachObjectWriter::RecordRelocati
"not yet implemented");
} else {
// Resolve constant variables.
- if (SD->getSymbol().isVariable()) {
+ if (A->isVariable()) {
int64_t Res;
- if (SD->getSymbol().getVariableValue()->EvaluateAsAbsolute(
- Res, Layout, Writer->getSectionAddressMap())) {
+ if (A->getVariableValue()->EvaluateAsAbsolute(
+ Res, Layout, Writer->getSectionAddressMap())) {
FixedValue = Res;
return;
}
}
// Check whether we need an external or internal relocation.
- if (requiresExternRelocation(Writer, Asm, *Fragment, RelocType, SD,
+ if (requiresExternRelocation(Writer, Asm, *Fragment, RelocType, *A,
FixedValue)) {
- RelSymbol = &SD->getSymbol();
+ RelSymbol = A;
// For external relocations, make sure to offset the fixup value to
// compensate for the addend of the symbol address, if it was
// undefined. This occurs with weak definitions, for example.
- if (!SD->getSymbol().isUndefined())
- FixedValue -= Layout.getSymbolOffset(SD->getSymbol());
+ if (!A->isUndefined())
+ FixedValue -= Layout.getSymbolOffset(*A);
} else {
// The index is the section ordinal (1-based).
- const MCSectionData &SymSD = Asm.getSectionData(
- SD->getSymbol().getSection());
+ const MCSectionData &SymSD = Asm.getSectionData(A->getSection());
Index = SymSD.getOrdinal() + 1;
FixedValue += Writer->getSectionAddress(&SymSD);
}
Modified: llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp?rev=237799&r1=237798&r2=237799&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp Wed May 20 10:16:14 2015
@@ -324,9 +324,9 @@ void PPCMachObjectWriter::RecordPPCReloc
// this doesn't seem right for RIT_PPC_BR24
// Get the symbol data, if any.
- const MCSymbolData *SD = nullptr;
+ const MCSymbol *A = nullptr;
if (Target.getSymA())
- SD = &Asm.getSymbolData(Target.getSymA()->getSymbol());
+ A = &Target.getSymA()->getSymbol();
// See <reloc.h>.
const uint32_t FixupOffset = getFixupOffset(Layout, Fragment, Fixup);
@@ -344,9 +344,9 @@ void PPCMachObjectWriter::RecordPPCReloc
// the above line stolen from ARM, not sure
} else {
// Resolve constant variables.
- if (SD->getSymbol().isVariable()) {
+ if (A->isVariable()) {
int64_t Res;
- if (SD->getSymbol().getVariableValue()->EvaluateAsAbsolute(
+ if (A->getVariableValue()->EvaluateAsAbsolute(
Res, Layout, Writer->getSectionAddressMap())) {
FixedValue = Res;
return;
@@ -354,17 +354,16 @@ void PPCMachObjectWriter::RecordPPCReloc
}
// Check whether we need an external or internal relocation.
- if (Writer->doesSymbolRequireExternRelocation(SD)) {
- RelSymbol = &SD->getSymbol();
+ if (Writer->doesSymbolRequireExternRelocation(*A)) {
+ RelSymbol = A;
// For external relocations, make sure to offset the fixup value to
// compensate for the addend of the symbol address, if it was
// undefined. This occurs with weak definitions, for example.
- if (!SD->getSymbol().isUndefined())
- FixedValue -= Layout.getSymbolOffset(SD->getSymbol());
+ if (!A->isUndefined())
+ FixedValue -= Layout.getSymbolOffset(*A);
} else {
// The index is the section ordinal (1-based).
- const MCSectionData &SymSD =
- Asm.getSectionData(SD->getSymbol().getSection());
+ const MCSectionData &SymSD = Asm.getSectionData(A->getSection());
Index = SymSD.getOrdinal() + 1;
FixedValue += Writer->getSectionAddress(&SymSD);
}
Modified: llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp?rev=237799&r1=237798&r2=237799&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp Wed May 20 10:16:14 2015
@@ -504,9 +504,9 @@ void X86MachObjectWriter::RecordX86Reloc
}
// Get the symbol data, if any.
- const MCSymbolData *SD = nullptr;
+ const MCSymbol *A = nullptr;
if (Target.getSymA())
- SD = &Asm.getSymbolData(Target.getSymA()->getSymbol());
+ A = &Target.getSymA()->getSymbol();
// If this is an internal relocation with an offset, it also needs a scattered
// relocation entry.
@@ -516,9 +516,9 @@ void X86MachObjectWriter::RecordX86Reloc
// Try to record the scattered relocation if needed. Fall back to non
// scattered if necessary (see comments in RecordScatteredRelocation()
// for details).
- if (Offset && SD && !Writer->doesSymbolRequireExternRelocation(SD) &&
- RecordScatteredRelocation(Writer, Asm, Layout, Fragment, Fixup,
- Target, Log2Size, FixedValue))
+ if (Offset && A && !Writer->doesSymbolRequireExternRelocation(*A) &&
+ RecordScatteredRelocation(Writer, Asm, Layout, Fragment, Fixup, Target,
+ Log2Size, FixedValue))
return;
// See <reloc.h>.
@@ -535,27 +535,26 @@ void X86MachObjectWriter::RecordX86Reloc
Type = MachO::GENERIC_RELOC_VANILLA;
} else {
// Resolve constant variables.
- if (SD->getSymbol().isVariable()) {
+ if (A->isVariable()) {
int64_t Res;
- if (SD->getSymbol().getVariableValue()->EvaluateAsAbsolute(
- Res, Layout, Writer->getSectionAddressMap())) {
+ if (A->getVariableValue()->EvaluateAsAbsolute(
+ Res, Layout, Writer->getSectionAddressMap())) {
FixedValue = Res;
return;
}
}
// Check whether we need an external or internal relocation.
- if (Writer->doesSymbolRequireExternRelocation(SD)) {
- RelSymbol = &SD->getSymbol();
+ if (Writer->doesSymbolRequireExternRelocation(*A)) {
+ RelSymbol = A;
// For external relocations, make sure to offset the fixup value to
// compensate for the addend of the symbol address, if it was
// undefined. This occurs with weak definitions, for example.
- if (!SD->getSymbol().isUndefined())
- FixedValue -= Layout.getSymbolOffset(SD->getSymbol());
+ if (!A->isUndefined())
+ FixedValue -= Layout.getSymbolOffset(*A);
} else {
// The index is the section ordinal (1-based).
- const MCSectionData &SymSD = Asm.getSectionData(
- SD->getSymbol().getSection());
+ const MCSectionData &SymSD = Asm.getSectionData(A->getSection());
Index = SymSD.getOrdinal() + 1;
FixedValue += Writer->getSectionAddress(&SymSD);
}
More information about the llvm-commits
mailing list