[llvm] r237497 - MC: Change MCFragment::Atom to an MCSymbol, NFC
Duncan P. N. Exon Smith
dexonsmith at apple.com
Fri May 15 17:48:59 PDT 2015
Author: dexonsmith
Date: Fri May 15 19:48:58 2015
New Revision: 237497
URL: http://llvm.org/viewvc/llvm-project?rev=237497&view=rev
Log:
MC: Change MCFragment::Atom to an MCSymbol, NFC
Change `MCFragment::Atom` from an `MCSymbolData` to an `MCSymbol`,
moving in the direction of removing the back-pointer.
Modified:
llvm/trunk/include/llvm/MC/MCAssembler.h
llvm/trunk/lib/MC/MCAssembler.cpp
llvm/trunk/lib/MC/MCMachOStreamer.cpp
llvm/trunk/lib/MC/MachObjectWriter.cpp
llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp
Modified: llvm/trunk/include/llvm/MC/MCAssembler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAssembler.h?rev=237497&r1=237496&r2=237497&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAssembler.h (original)
+++ llvm/trunk/include/llvm/MC/MCAssembler.h Fri May 15 19:48:58 2015
@@ -70,7 +70,7 @@ private:
/// Atom - The atom this fragment is in, as represented by it's defining
/// symbol.
- MCSymbolData *Atom;
+ const MCSymbol *Atom;
/// \name Assembler Backend Data
/// @{
@@ -99,8 +99,8 @@ public:
MCSectionData *getParent() const { return Parent; }
void setParent(MCSectionData *Value) { Parent = Value; }
- MCSymbolData *getAtom() const { return Atom; }
- void setAtom(MCSymbolData *Value) { Atom = Value; }
+ const MCSymbol *getAtom() const { return Atom; }
+ void setAtom(const MCSymbol *Value) { Atom = Value; }
unsigned getLayoutOrder() const { return LayoutOrder; }
void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
@@ -834,7 +834,7 @@ public:
/// Find the symbol which defines the atom containing the given symbol, or
/// null if there is no such symbol.
- const MCSymbolData *getAtom(const MCSymbolData *Symbol) const;
+ const MCSymbol *getAtom(const MCSymbolData *Symbol) const;
/// Check whether a particular symbol is visible to the linker and is required
/// in the symbol table, or whether it can be discarded by the assembler. This
Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=237497&r1=237496&r2=237497&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Fri May 15 19:48:58 2015
@@ -460,10 +460,10 @@ bool MCAssembler::isSymbolLinkerVisible(
return false;
}
-const MCSymbolData *MCAssembler::getAtom(const MCSymbolData *SD) const {
+const MCSymbol *MCAssembler::getAtom(const MCSymbolData *SD) const {
// Linker visible symbols define atoms.
if (isSymbolLinkerVisible(SD->getSymbol()))
- return SD;
+ return &SD->getSymbol();
// Absolute and undefined symbols have no defining atom.
if (!SD->getFragment())
Modified: llvm/trunk/lib/MC/MCMachOStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCMachOStreamer.cpp?rev=237497&r1=237496&r2=237497&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCMachOStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCMachOStreamer.cpp Fri May 15 19:48:58 2015
@@ -478,11 +478,11 @@ void MCMachOStreamer::FinishImpl() {
// symbol.
for (MCAssembler::iterator it = getAssembler().begin(),
ie = getAssembler().end(); it != ie; ++it) {
- MCSymbolData *CurrentAtom = nullptr;
+ const MCSymbol *CurrentAtom = nullptr;
for (MCSectionData::iterator it2 = it->begin(),
ie2 = it->end(); it2 != ie2; ++it2) {
if (MCSymbolData *SD = DefiningSymbolMap.lookup(it2))
- CurrentAtom = SD;
+ CurrentAtom = &SD->getSymbol();
it2->setAtom(CurrentAtom);
}
}
Modified: llvm/trunk/lib/MC/MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MachObjectWriter.cpp?rev=237497&r1=237496&r2=237497&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/MachObjectWriter.cpp Fri May 15 19:48:58 2015
@@ -679,8 +679,6 @@ bool MachObjectWriter::IsSymbolRefDiffer
// - addr(atom(B)) - offset(B)
// and the offsets are not relocatable, so the fixup is fully resolved when
// addr(atom(A)) - addr(atom(B)) == 0.
- const MCSymbolData *A_Base = nullptr, *B_Base = nullptr;
-
const MCSymbol &SA = findAliasedSymbol(DataA.getSymbol());
const MCSection &SecA = SA.getSection();
const MCSection &SecB = FB.getParent()->getSection();
@@ -733,11 +731,8 @@ bool MachObjectWriter::IsSymbolRefDiffer
if (!FA)
return false;
- A_Base = FA->getAtom();
- B_Base = FB.getAtom();
-
// If the atoms are the same, they are guaranteed to have the same address.
- if (A_Base == B_Base)
+ if (FA->getAtom() == FB.getAtom())
return true;
// Otherwise, we can't prove this is fully resolved.
Modified: llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp?rev=237497&r1=237496&r2=237497&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp Fri May 15 19:48:58 2015
@@ -154,7 +154,7 @@ void AArch64MachObjectWriter::RecordRelo
unsigned Index = 0;
unsigned Type = 0;
unsigned Kind = Fixup.getKind();
- const MCSymbolData *RelSymbol = nullptr;
+ const MCSymbol *RelSymbol = nullptr;
FixupOffset += Fixup.getOffset();
@@ -211,11 +211,11 @@ void AArch64MachObjectWriter::RecordRelo
} else if (Target.getSymB()) { // A - B + constant
const MCSymbol *A = &Target.getSymA()->getSymbol();
const MCSymbolData &A_SD = Asm.getSymbolData(*A);
- const MCSymbolData *A_Base = Asm.getAtom(&A_SD);
+ const MCSymbol *A_Base = Asm.getAtom(&A_SD);
const MCSymbol *B = &Target.getSymB()->getSymbol();
const MCSymbolData &B_SD = Asm.getSymbolData(*B);
- const MCSymbolData *B_Base = Asm.getAtom(&B_SD);
+ const MCSymbol *B_Base = Asm.getAtom(&B_SD);
// Check for "_foo at got - .", which comes through here as:
// Ltmp0:
@@ -230,7 +230,8 @@ void AArch64MachObjectWriter::RecordRelo
MachO::any_relocation_info MRE;
MRE.r_word0 = FixupOffset;
MRE.r_word1 = (IsPCRel << 24) | (Log2Size << 25) | (Type << 28);
- Writer->addRelocation(A_Base, Fragment->getParent(), MRE);
+ Writer->addRelocation(A_Base ? &A_Base->getData() : nullptr,
+ Fragment->getParent(), MRE);
return;
} else if (Target.getSymA()->getKind() != MCSymbolRefExpr::VK_None ||
Target.getSymB()->getKind() != MCSymbolRefExpr::VK_None)
@@ -265,23 +266,24 @@ void AArch64MachObjectWriter::RecordRelo
Asm.getContext().FatalError(Fixup.getLoc(),
"unsupported relocation with identical base");
- Value += (!A_SD.getFragment() ? 0
- : Writer->getSymbolAddress(&A_SD, Layout)) -
- (!A_Base || !A_Base->getFragment()
- ? 0
- : Writer->getSymbolAddress(A_Base, Layout));
- Value -= (!B_SD.getFragment() ? 0
- : Writer->getSymbolAddress(&B_SD, Layout)) -
- (!B_Base || !B_Base->getFragment()
- ? 0
- : Writer->getSymbolAddress(B_Base, Layout));
+ Value +=
+ (!A_SD.getFragment() ? 0 : Writer->getSymbolAddress(&A_SD, Layout)) -
+ (!A_Base || !A_Base->getData().getFragment()
+ ? 0
+ : Writer->getSymbolAddress(&A_Base->getData(), Layout));
+ Value -=
+ (!B_SD.getFragment() ? 0 : Writer->getSymbolAddress(&B_SD, Layout)) -
+ (!B_Base || !B_Base->getData().getFragment()
+ ? 0
+ : Writer->getSymbolAddress(&B_Base->getData(), Layout));
Type = MachO::ARM64_RELOC_UNSIGNED;
MachO::any_relocation_info MRE;
MRE.r_word0 = FixupOffset;
MRE.r_word1 = (IsPCRel << 24) | (Log2Size << 25) | (Type << 28);
- Writer->addRelocation(A_Base, Fragment->getParent(), MRE);
+ Writer->addRelocation(A_Base ? &A_Base->getData() : nullptr,
+ Fragment->getParent(), MRE);
RelSymbol = B_Base;
Type = MachO::ARM64_RELOC_SUBTRACTOR;
@@ -299,7 +301,7 @@ void AArch64MachObjectWriter::RecordRelo
}
const MCSymbolData &SD = Asm.getSymbolData(*Symbol);
- const MCSymbolData *Base = Asm.getAtom(&SD);
+ const MCSymbol *Base = Asm.getAtom(&SD);
// If the symbol is a variable and we weren't able to get a Base for it
// (i.e., it's not in the symbol table associated with a section) resolve
@@ -342,8 +344,9 @@ void AArch64MachObjectWriter::RecordRelo
RelSymbol = Base;
// Add the local offset, if needed.
- if (Base != &SD)
- Value += Layout.getSymbolOffset(&SD) - Layout.getSymbolOffset(Base);
+ if (&Base->getData() != &SD)
+ Value += Layout.getSymbolOffset(&SD) -
+ Layout.getSymbolOffset(&Base->getData());
} else if (Symbol->isInSection()) {
if (!CanUseLocalRelocation)
Asm.getContext().FatalError(
@@ -389,7 +392,8 @@ void AArch64MachObjectWriter::RecordRelo
MRE.r_word0 = FixupOffset;
MRE.r_word1 =
(Index << 0) | (IsPCRel << 24) | (Log2Size << 25) | (Type << 28);
- Writer->addRelocation(RelSymbol, Fragment->getParent(), MRE);
+ Writer->addRelocation(RelSymbol ? &RelSymbol->getData() : nullptr,
+ Fragment->getParent(), MRE);
// Now set up the Addend relocation.
Type = MachO::ARM64_RELOC_ADDEND;
@@ -410,7 +414,8 @@ void AArch64MachObjectWriter::RecordRelo
MRE.r_word0 = FixupOffset;
MRE.r_word1 =
(Index << 0) | (IsPCRel << 24) | (Log2Size << 25) | (Type << 28);
- Writer->addRelocation(RelSymbol, Fragment->getParent(), MRE);
+ Writer->addRelocation(RelSymbol ? &RelSymbol->getData() : nullptr,
+ Fragment->getParent(), MRE);
}
MCObjectWriter *llvm::createAArch64MachObjectWriter(raw_pwrite_stream &OS,
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=237497&r1=237496&r2=237497&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp Fri May 15 19:48:58 2015
@@ -113,7 +113,7 @@ void X86MachObjectWriter::RecordX86_64Re
unsigned Index = 0;
unsigned IsExtern = 0;
unsigned Type = 0;
- const MCSymbolData *RelSymbol = nullptr;
+ const MCSymbol *RelSymbol = nullptr;
Value = Target.getConstant();
@@ -143,13 +143,13 @@ void X86MachObjectWriter::RecordX86_64Re
if (A->isTemporary())
A = &Writer->findAliasedSymbol(*A);
const MCSymbolData &A_SD = Asm.getSymbolData(*A);
- const MCSymbolData *A_Base = Asm.getAtom(&A_SD);
+ const MCSymbol *A_Base = Asm.getAtom(&A_SD);
const MCSymbol *B = &Target.getSymB()->getSymbol();
if (B->isTemporary())
B = &Writer->findAliasedSymbol(*B);
const MCSymbolData &B_SD = Asm.getSymbolData(*B);
- const MCSymbolData *B_Base = Asm.getAtom(&B_SD);
+ const MCSymbol *B_Base = Asm.getAtom(&B_SD);
// Neither symbol can be modified.
if (Target.getSymA()->getKind() != MCSymbolRefExpr::VK_None ||
@@ -184,10 +184,12 @@ void X86MachObjectWriter::RecordX86_64Re
Name + "' can not be undefined in a subtraction expression");
}
- Value += Writer->getSymbolAddress(&A_SD, Layout) -
- (!A_Base ? 0 : Writer->getSymbolAddress(A_Base, Layout));
- Value -= Writer->getSymbolAddress(&B_SD, Layout) -
- (!B_Base ? 0 : Writer->getSymbolAddress(B_Base, Layout));
+ Value +=
+ Writer->getSymbolAddress(&A_SD, Layout) -
+ (!A_Base ? 0 : Writer->getSymbolAddress(&A_Base->getData(), Layout));
+ Value -=
+ Writer->getSymbolAddress(&B_SD, Layout) -
+ (!B_Base ? 0 : Writer->getSymbolAddress(&B_Base->getData(), Layout));
if (!A_Base)
Index = A_SD.getFragment()->getParent()->getOrdinal() + 1;
@@ -197,7 +199,8 @@ void X86MachObjectWriter::RecordX86_64Re
MRE.r_word0 = FixupOffset;
MRE.r_word1 =
(Index << 0) | (IsPCRel << 24) | (Log2Size << 25) | (Type << 28);
- Writer->addRelocation(A_Base, Fragment->getParent(), MRE);
+ Writer->addRelocation(A_Base ? &A_Base->getData() : nullptr,
+ Fragment->getParent(), MRE);
if (B_Base)
RelSymbol = B_Base;
@@ -230,9 +233,9 @@ void X86MachObjectWriter::RecordX86_64Re
// non-local symbol).
if (RelSymbol) {
// Add the local offset, if needed.
- if (RelSymbol != &SD)
- Value +=
- Layout.getSymbolOffset(&SD) - Layout.getSymbolOffset(RelSymbol);
+ if (&RelSymbol->getData() != &SD)
+ Value += Layout.getSymbolOffset(&SD) -
+ Layout.getSymbolOffset(&RelSymbol->getData());
} else if (Symbol->isInSection() && !Symbol->isVariable()) {
// The index is the section ordinal (1-based).
Index = SD.getFragment()->getParent()->getOrdinal() + 1;
@@ -336,7 +339,8 @@ void X86MachObjectWriter::RecordX86_64Re
MRE.r_word0 = FixupOffset;
MRE.r_word1 = (Index << 0) | (IsPCRel << 24) | (Log2Size << 25) |
(IsExtern << 27) | (Type << 28);
- Writer->addRelocation(RelSymbol, Fragment->getParent(), MRE);
+ Writer->addRelocation(RelSymbol ? &RelSymbol->getData() : nullptr,
+ Fragment->getParent(), MRE);
}
bool X86MachObjectWriter::RecordScatteredRelocation(MachObjectWriter *Writer,
More information about the llvm-commits
mailing list