MC: Change MCFragment::Atom to an MCSymbol, NFC
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sat, 16 May 2015 00:48:58 +0000 (00:48 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sat, 16 May 2015 00:48:58 +0000 (00:48 +0000)
Change `MCFragment::Atom` from an `MCSymbolData` to an `MCSymbol`,
moving in the direction of removing the back-pointer.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237497 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCAssembler.h
lib/MC/MCAssembler.cpp
lib/MC/MCMachOStreamer.cpp
lib/MC/MachObjectWriter.cpp
lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp

index 945f42209750ba2afe113886a933d43484aaa597..46d6046a346753c01c1e2e8070bfbb4edc89e43a 100644 (file)
@@ -70,7 +70,7 @@ private:
 
   /// Atom - The atom this fragment is in, as represented by it's defining
   /// symbol.
 
   /// Atom - The atom this fragment is in, as represented by it's defining
   /// symbol.
-  MCSymbolData *Atom;
+  const MCSymbol *Atom;
 
   /// \name Assembler Backend Data
   /// @{
 
   /// \name Assembler Backend Data
   /// @{
@@ -99,8 +99,8 @@ public:
   MCSectionData *getParent() const { return Parent; }
   void setParent(MCSectionData *Value) { Parent = Value; }
 
   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; }
 
   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.
 
   /// 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
 
   /// 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
index ff230dfd9f9f246b520c43144cacd3665f589cb3..197b9221b3fe574992527c6752982a8c72005f33 100644 (file)
@@ -460,10 +460,10 @@ bool MCAssembler::isSymbolLinkerVisible(const MCSymbol &Symbol) const {
   return false;
 }
 
   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()))
   // 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())
 
   // Absolute and undefined symbols have no defining atom.
   if (!SD->getFragment())
index ee3f35878edc1577ffd13faaf3a36e815292de8f..b381e5780405e899bb714d434063007273024a1d 100644 (file)
@@ -478,11 +478,11 @@ void MCMachOStreamer::FinishImpl() {
   // symbol.
   for (MCAssembler::iterator it = getAssembler().begin(),
          ie = getAssembler().end(); it != ie; ++it) {
   // 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))
     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);
     }
   }
       it2->setAtom(CurrentAtom);
     }
   }
index 3ffdc701e65dbedc68aaef1b08755078661c7feb..109e908988f3810cc9aeaf64500e48347ac33db9 100644 (file)
@@ -679,8 +679,6 @@ bool MachObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl(
   //   - 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.
   //   - 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();
   const MCSymbol &SA = findAliasedSymbol(DataA.getSymbol());
   const MCSection &SecA = SA.getSection();
   const MCSection &SecB = FB.getParent()->getSection();
@@ -733,11 +731,8 @@ bool MachObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl(
   if (!FA)
     return false;
 
   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 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.
     return true;
 
   // Otherwise, we can't prove this is fully resolved.
index 61649c4414261aa03434eeb2f67cba56e3b1d1b7..faaf33a9710d65fd335472d70501395f5e4356c6 100644 (file)
@@ -154,7 +154,7 @@ void AArch64MachObjectWriter::RecordRelocation(
   unsigned Index = 0;
   unsigned Type = 0;
   unsigned Kind = Fixup.getKind();
   unsigned Index = 0;
   unsigned Type = 0;
   unsigned Kind = Fixup.getKind();
-  const MCSymbolData *RelSymbol = nullptr;
+  const MCSymbol *RelSymbol = nullptr;
 
   FixupOffset += Fixup.getOffset();
 
 
   FixupOffset += Fixup.getOffset();
 
@@ -211,11 +211,11 @@ void AArch64MachObjectWriter::RecordRelocation(
   } else if (Target.getSymB()) { // A - B + constant
     const MCSymbol *A = &Target.getSymA()->getSymbol();
     const MCSymbolData &A_SD = Asm.getSymbolData(*A);
   } 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 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@got - .", which comes through here as:
     // Ltmp0:
 
     // Check for "_foo@got - .", which comes through here as:
     // Ltmp0:
@@ -230,7 +230,8 @@ void AArch64MachObjectWriter::RecordRelocation(
       MachO::any_relocation_info MRE;
       MRE.r_word0 = FixupOffset;
       MRE.r_word1 = (IsPCRel << 24) | (Log2Size << 25) | (Type << 28);
       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)
       return;
     } else if (Target.getSymA()->getKind() != MCSymbolRefExpr::VK_None ||
                Target.getSymB()->getKind() != MCSymbolRefExpr::VK_None)
@@ -265,23 +266,24 @@ void AArch64MachObjectWriter::RecordRelocation(
       Asm.getContext().FatalError(Fixup.getLoc(),
                                   "unsupported relocation with identical base");
 
       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);
 
     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;
 
     RelSymbol = B_Base;
     Type = MachO::ARM64_RELOC_SUBTRACTOR;
@@ -299,7 +301,7 @@ void AArch64MachObjectWriter::RecordRelocation(
     }
 
     const MCSymbolData &SD = Asm.getSymbolData(*Symbol);
     }
 
     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
 
     // 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::RecordRelocation(
       RelSymbol = Base;
 
       // Add the local offset, if needed.
       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(
     } else if (Symbol->isInSection()) {
       if (!CanUseLocalRelocation)
         Asm.getContext().FatalError(
@@ -389,7 +392,8 @@ void AArch64MachObjectWriter::RecordRelocation(
     MRE.r_word0 = FixupOffset;
     MRE.r_word1 =
         (Index << 0) | (IsPCRel << 24) | (Log2Size << 25) | (Type << 28);
     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;
 
     // Now set up the Addend relocation.
     Type = MachO::ARM64_RELOC_ADDEND;
@@ -410,7 +414,8 @@ void AArch64MachObjectWriter::RecordRelocation(
   MRE.r_word0 = FixupOffset;
   MRE.r_word1 =
       (Index << 0) | (IsPCRel << 24) | (Log2Size << 25) | (Type << 28);
   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,
 }
 
 MCObjectWriter *llvm::createAArch64MachObjectWriter(raw_pwrite_stream &OS,
index b0ddd7674591ea6fe3b18139f1fe584507551aa4..a58c3a45bd2cd64e6d033fce3832c82be572011e 100644 (file)
@@ -113,7 +113,7 @@ void X86MachObjectWriter::RecordX86_64Relocation(
   unsigned Index = 0;
   unsigned IsExtern = 0;
   unsigned Type = 0;
   unsigned Index = 0;
   unsigned IsExtern = 0;
   unsigned Type = 0;
-  const MCSymbolData *RelSymbol = nullptr;
+  const MCSymbol *RelSymbol = nullptr;
 
   Value = Target.getConstant();
 
 
   Value = Target.getConstant();
 
@@ -143,13 +143,13 @@ void X86MachObjectWriter::RecordX86_64Relocation(
     if (A->isTemporary())
       A = &Writer->findAliasedSymbol(*A);
     const MCSymbolData &A_SD = Asm.getSymbolData(*A);
     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 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 ||
 
     // Neither symbol can be modified.
     if (Target.getSymA()->getKind() != MCSymbolRefExpr::VK_None ||
@@ -184,10 +184,12 @@ void X86MachObjectWriter::RecordX86_64Relocation(
         Name + "' can not be undefined in a subtraction expression");
     }
 
         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;
 
     if (!A_Base)
       Index = A_SD.getFragment()->getParent()->getOrdinal() + 1;
@@ -197,7 +199,8 @@ void X86MachObjectWriter::RecordX86_64Relocation(
     MRE.r_word0 = FixupOffset;
     MRE.r_word1 =
         (Index << 0) | (IsPCRel << 24) | (Log2Size << 25) | (Type << 28);
     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;
 
     if (B_Base)
       RelSymbol = B_Base;
@@ -230,9 +233,9 @@ void X86MachObjectWriter::RecordX86_64Relocation(
     // non-local symbol).
     if (RelSymbol) {
       // Add the local offset, if needed.
     // 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;
     } 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_64Relocation(
   MRE.r_word0 = FixupOffset;
   MRE.r_word1 = (Index << 0) | (IsPCRel << 24) | (Log2Size << 25) |
                 (IsExtern << 27) | (Type << 28);
   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,
 }
 
 bool X86MachObjectWriter::RecordScatteredRelocation(MachObjectWriter *Writer,