Return a MCSection from MCFragment::getParent().
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 26 May 2015 00:36:57 +0000 (00:36 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 26 May 2015 00:36:57 +0000 (00:36 +0000)
Another step in merging MCSectionData and MCSection.

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

include/llvm/MC/MCAssembler.h
lib/MC/ELFObjectWriter.cpp
lib/MC/MCAssembler.cpp
lib/MC/MCExpr.cpp
lib/MC/MCObjectWriter.cpp
lib/MC/MachObjectWriter.cpp
lib/MC/WinCOFFObjectWriter.cpp
lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp
lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp

index 2c0a0fd157d1010ab04d86c02143ca3170265bfa..95d27fb2e6eaf7614b551501e0b1ba6957e0147b 100644 (file)
@@ -98,9 +98,7 @@ public:
 
   FragmentType getKind() const { return Kind; }
 
-  MCSectionData *getParent() const {
-    return &Parent->getSectionData();
-  }
+  MCSection *getParent() const { return Parent; }
   void setParent(MCSection *Value) { Parent = Value; }
 
   const MCSymbol *getAtom() const { return Atom; }
index 6dd8bd7466978fc11d4e8c6234587b3845f2113d..62363cec91c88e5a03b6cabf8f3baae9373b24fe 100644 (file)
@@ -491,8 +491,7 @@ void ELFObjectWriter::WriteSymbol(SymbolTableWriter &Writer, ELFSymbolData &MSD,
                                   const MCAsmLayout &Layout) {
   MCSymbolData &OrigData = MSD.Symbol->getData();
   assert((!OrigData.getFragment() ||
-          (&OrigData.getFragment()->getParent()->getSection() ==
-           &MSD.Symbol->getSection())) &&
+          (OrigData.getFragment()->getParent() == &MSD.Symbol->getSection())) &&
          "The symbol's section doesn't match the fragment's symbol");
   const MCSymbol *Base = Layout.getBaseSymbol(*MSD.Symbol);
 
@@ -751,9 +750,7 @@ void ELFObjectWriter::RecordRelocation(MCAssembler &Asm,
                                        const MCFragment *Fragment,
                                        const MCFixup &Fixup, MCValue Target,
                                        bool &IsPCRel, uint64_t &FixedValue) {
-  const MCSectionData *FixupSectionD = Fragment->getParent();
-  const MCSectionELF &FixupSection =
-      cast<MCSectionELF>(FixupSectionD->getSection());
+  const MCSectionELF &FixupSection = cast<MCSectionELF>(*Fragment->getParent());
   uint64_t C = Target.getConstant();
   uint64_t FixupOffset = Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
 
index 1d8f70309a1f9ec0e5171436bda8ff81bcfe720c..b3df76eef4c2069f123c30c8cc45d32ca6f55a49 100644 (file)
@@ -77,7 +77,7 @@ MCAsmLayout::MCAsmLayout(MCAssembler &Asm)
 }
 
 bool MCAsmLayout::isFragmentValid(const MCFragment *F) const {
-  const MCSectionData &SD = *F->getParent();
+  const MCSectionData &SD = F->getParent()->getSectionData();
   const MCFragment *LastValid = LastValidFragment.lookup(&SD);
   if (!LastValid)
     return false;
@@ -92,12 +92,12 @@ void MCAsmLayout::invalidateFragmentsFrom(MCFragment *F) {
 
   // Otherwise, reset the last valid fragment to the previous fragment
   // (if this is the first fragment, it will be NULL).
-  const MCSectionData &SD = *F->getParent();
+  const MCSectionData &SD = F->getParent()->getSectionData();
   LastValidFragment[&SD] = F->getPrevNode();
 }
 
 void MCAsmLayout::ensureValid(const MCFragment *F) const {
-  MCSectionData &SD = *F->getParent();
+  MCSectionData &SD = F->getParent()->getSectionData();
 
   MCFragment *Cur = LastValidFragment[&SD];
   if (!Cur)
@@ -421,7 +421,7 @@ const MCSymbol *MCAssembler::getAtom(const MCSymbol &S) const {
   // Non-linker visible symbols in sections which can't be atomized have no
   // defining atom.
   if (!getContext().getAsmInfo()->isSectionAtomizableBySymbols(
-          S.getData().getFragment()->getParent()->getSection()))
+          *S.getData().getFragment()->getParent()))
     return nullptr;
 
   // Otherwise, return the atom for the containing fragment.
@@ -568,7 +568,7 @@ void MCAsmLayout::layoutFragment(MCFragment *F) {
     F->Offset = Prev->Offset + getAssembler().computeFragmentSize(*this, *Prev);
   else
     F->Offset = 0;
-  LastValidFragment[F->getParent()] = F;
+  LastValidFragment[&F->getParent()->getSectionData()] = F;
 
   // If bundling is enabled and this fragment has instructions in it, it has to
   // obey the bundling restrictions. With padding, we'll have:
index b2c6965319fc5735c6a6324d8ea2702c64ebfc34..47a1efe28b60814ebb53a24ebe1a7e9576ca3f10 100644 (file)
@@ -491,8 +491,8 @@ static void AttemptToFoldSymbolOffsetDifference(
   if (!Layout)
     return;
 
-  const MCSectionData &SecA = *AD.getFragment()->getParent();
-  const MCSectionData &SecB = *BD.getFragment()->getParent();
+  const MCSection &SecA = *AD.getFragment()->getParent();
+  const MCSection &SecB = *BD.getFragment()->getParent();
 
   if ((&SecA != &SecB) && !Addrs)
     return;
@@ -501,7 +501,8 @@ static void AttemptToFoldSymbolOffsetDifference(
   Addend += Layout->getSymbolOffset(A->getSymbol()) -
             Layout->getSymbolOffset(B->getSymbol());
   if (Addrs && (&SecA != &SecB))
-    Addend += (Addrs->lookup(&SecA) - Addrs->lookup(&SecB));
+    Addend += (Addrs->lookup(&SecA.getSectionData()) -
+               Addrs->lookup(&SecB.getSectionData()));
 
   // Pointers to Thumb symbols need to have their low-bit set to allow
   // for interworking.
index 7a9fd49035e6078af2ed1c905740514c832eaae3..5cc629b81ba0dd5e48c7a0cdcb41c33ac3346b69 100644 (file)
@@ -43,7 +43,7 @@ bool MCObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl(
     const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB,
     bool InSet, bool IsPCRel) const {
   const MCSection &SecA = SymA.getSection();
-  const MCSection &SecB = FB.getParent()->getSection();
+  const MCSection &SecB = *FB.getParent();
   // On ELF and COFF  A - B is absolute if A and B are in the same section.
   return &SecA == &SecB;
 }
index 240aa4da07635441a133994d979845fa69c27d9a..585b4f747732715a53e17ceef5e4b0f94f1b4c0e 100644 (file)
@@ -67,8 +67,8 @@ bool MachObjectWriter::isFixupKindPCRel(const MCAssembler &Asm, unsigned Kind) {
 
 uint64_t MachObjectWriter::getFragmentAddress(const MCFragment *Fragment,
                                               const MCAsmLayout &Layout) const {
-  return getSectionAddress(Fragment->getParent()) +
-    Layout.getFragmentOffset(Fragment);
+  return getSectionAddress(&Fragment->getParent()->getSectionData()) +
+         Layout.getFragmentOffset(Fragment);
 }
 
 uint64_t MachObjectWriter::getSymbolAddress(const MCSymbol &S,
@@ -101,7 +101,8 @@ uint64_t MachObjectWriter::getSymbolAddress(const MCSymbol &S,
     return Address;
   }
 
-  return getSectionAddress(S.getData().getFragment()->getParent()) +
+  return getSectionAddress(
+             &S.getData().getFragment()->getParent()->getSectionData()) +
          Layout.getSymbolOffset(S);
 }
 
@@ -679,7 +680,7 @@ bool MachObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl(
   //  addr(atom(A)) - addr(atom(B)) == 0.
   const MCSymbol &SA = findAliasedSymbol(SymA);
   const MCSection &SecA = SA.getSection();
-  const MCSection &SecB = FB.getParent()->getSection();
+  const MCSection &SecB = *FB.getParent();
 
   if (IsPCRel) {
     // The simple (Darwin, except on x86_64) way of dealing with this was to
index 3866eb38663bbfe4f7eac6aa25e2fcc0448d364f..ce3f8385ec44b953853f397da1f3af66dcd30233 100644 (file)
@@ -420,8 +420,7 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &Symbol,
     } else {
       const MCSymbolData &BaseData = Assembler.getSymbolData(*Base);
       if (BaseData.getFragment()) {
-        COFFSection *Sec =
-            SectionMap[&BaseData.getFragment()->getParent()->getSection()];
+        COFFSection *Sec = SectionMap[BaseData.getFragment()->getParent()];
 
         if (coff_symbol->Section && coff_symbol->Section != Sec)
           report_fatal_error("conflicting sections for symbol");
@@ -689,15 +688,15 @@ void WinCOFFObjectWriter::RecordRelocation(
 
   const MCSymbolData &A_SD = Asm.getSymbolData(A);
 
-  MCSectionData const *SectionData = Fragment->getParent();
+  MCSection *Section = Fragment->getParent();
 
   // Mark this symbol as requiring an entry in the symbol table.
-  assert(SectionMap.find(&SectionData->getSection()) != SectionMap.end() &&
+  assert(SectionMap.find(Section) != SectionMap.end() &&
          "Section must already have been defined in ExecutePostLayoutBinding!");
   assert(SymbolMap.find(&A) != SymbolMap.end() &&
          "Symbol must already have been defined in ExecutePostLayoutBinding!");
 
-  COFFSection *coff_section = SectionMap[&SectionData->getSection()];
+  COFFSection *coff_section = SectionMap[Section];
   COFFSymbol *coff_symbol = SymbolMap[&A];
   const MCSymbolRefExpr *SymB = Target.getSymB();
   bool CrossSection = false;
index cd74b4800aae8dbca1f16af2a0ec6b289fc0ae4f..a08572cb18716942924e8e23fe8e408b72e69b85 100644 (file)
@@ -229,7 +229,8 @@ void AArch64MachObjectWriter::RecordRelocation(
       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, &Fragment->getParent()->getSectionData(),
+                            MRE);
       return;
     } else if (Target.getSymA()->getKind() != MCSymbolRefExpr::VK_None ||
                Target.getSymB()->getKind() != MCSymbolRefExpr::VK_None)
@@ -278,14 +279,15 @@ void AArch64MachObjectWriter::RecordRelocation(
     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, &Fragment->getParent()->getSectionData(),
+                          MRE);
 
     RelSymbol = B_Base;
     Type = MachO::ARM64_RELOC_SUBTRACTOR;
   } else { // A + constant
     const MCSymbol *Symbol = &Target.getSymA()->getSymbol();
-    const MCSectionMachO &Section = static_cast<const MCSectionMachO &>(
-        Fragment->getParent()->getSection());
+    const MCSectionMachO &Section =
+        static_cast<const MCSectionMachO &>(*Fragment->getParent());
 
     bool CanUseLocalRelocation =
         canUseLocalRelocation(Section, *Symbol, Log2Size);
@@ -385,7 +387,8 @@ void AArch64MachObjectWriter::RecordRelocation(
     MRE.r_word0 = FixupOffset;
     MRE.r_word1 =
         (Index << 0) | (IsPCRel << 24) | (Log2Size << 25) | (Type << 28);
-    Writer->addRelocation(RelSymbol, Fragment->getParent(), MRE);
+    Writer->addRelocation(RelSymbol, &Fragment->getParent()->getSectionData(),
+                          MRE);
 
     // Now set up the Addend relocation.
     Type = MachO::ARM64_RELOC_ADDEND;
@@ -406,7 +409,8 @@ void AArch64MachObjectWriter::RecordRelocation(
   MRE.r_word0 = FixupOffset;
   MRE.r_word1 =
       (Index << 0) | (IsPCRel << 24) | (Log2Size << 25) | (Type << 28);
-  Writer->addRelocation(RelSymbol, Fragment->getParent(), MRE);
+  Writer->addRelocation(RelSymbol, &Fragment->getParent()->getSectionData(),
+                        MRE);
 }
 
 MCObjectWriter *llvm::createAArch64MachObjectWriter(raw_pwrite_stream &OS,
index 84585b913906b7ae330189627dab13485dde316a..3199efb1935ce0c77e921602bf17cfef57d30884 100644 (file)
@@ -161,8 +161,8 @@ RecordARMScatteredHalfRelocation(MachObjectWriter *Writer,
 
   uint32_t Value = Writer->getSymbolAddress(*A, Layout);
   uint32_t Value2 = 0;
-  uint64_t SecAddr =
-    Writer->getSectionAddress(A_SD->getFragment()->getParent());
+  uint64_t SecAddr = Writer->getSectionAddress(
+      &A_SD->getFragment()->getParent()->getSectionData());
   FixedValue += SecAddr;
 
   if (const MCSymbolRefExpr *B = Target.getSymB()) {
@@ -176,7 +176,8 @@ RecordARMScatteredHalfRelocation(MachObjectWriter *Writer,
     // Select the appropriate difference relocation type.
     Type = MachO::ARM_RELOC_HALF_SECTDIFF;
     Value2 = Writer->getSymbolAddress(B->getSymbol(), Layout);
-    FixedValue -= Writer->getSectionAddress(B_SD->getFragment()->getParent());
+    FixedValue -= Writer->getSectionAddress(
+        &B_SD->getFragment()->getParent()->getSectionData());
   }
 
   // Relocations are written out in reverse order, so the PAIR comes first.
@@ -227,7 +228,8 @@ RecordARMScatteredHalfRelocation(MachObjectWriter *Writer,
                    (IsPCRel               << 30) |
                    MachO::R_SCATTERED);
     MRE.r_word1 = Value2;
-    Writer->addRelocation(nullptr, Fragment->getParent(), MRE);
+    Writer->addRelocation(nullptr, &Fragment->getParent()->getSectionData(),
+                          MRE);
   }
 
   MachO::any_relocation_info MRE;
@@ -238,7 +240,7 @@ RecordARMScatteredHalfRelocation(MachObjectWriter *Writer,
                  (IsPCRel     << 30) |
                  MachO::R_SCATTERED);
   MRE.r_word1 = Value;
-  Writer->addRelocation(nullptr, Fragment->getParent(), MRE);
+  Writer->addRelocation(nullptr, &Fragment->getParent()->getSectionData(), MRE);
 }
 
 void ARMMachObjectWriter::RecordARMScatteredRelocation(MachObjectWriter *Writer,
@@ -263,7 +265,8 @@ void ARMMachObjectWriter::RecordARMScatteredRelocation(MachObjectWriter *Writer,
                        "' can not be undefined in a subtraction expression");
 
   uint32_t Value = Writer->getSymbolAddress(*A, Layout);
-  uint64_t SecAddr = Writer->getSectionAddress(A_SD->getFragment()->getParent());
+  uint64_t SecAddr = Writer->getSectionAddress(
+      &A_SD->getFragment()->getParent()->getSectionData());
   FixedValue += SecAddr;
   uint32_t Value2 = 0;
 
@@ -279,7 +282,8 @@ void ARMMachObjectWriter::RecordARMScatteredRelocation(MachObjectWriter *Writer,
     // Select the appropriate difference relocation type.
     Type = MachO::ARM_RELOC_SECTDIFF;
     Value2 = Writer->getSymbolAddress(B->getSymbol(), Layout);
-    FixedValue -= Writer->getSectionAddress(B_SD->getFragment()->getParent());
+    FixedValue -= Writer->getSectionAddress(
+        &B_SD->getFragment()->getParent()->getSectionData());
   }
 
   // Relocations are written out in reverse order, so the PAIR comes first.
@@ -292,7 +296,8 @@ void ARMMachObjectWriter::RecordARMScatteredRelocation(MachObjectWriter *Writer,
                    (IsPCRel               << 30) |
                    MachO::R_SCATTERED);
     MRE.r_word1 = Value2;
-    Writer->addRelocation(nullptr, Fragment->getParent(), MRE);
+    Writer->addRelocation(nullptr, &Fragment->getParent()->getSectionData(),
+                          MRE);
   }
 
   MachO::any_relocation_info MRE;
@@ -302,7 +307,7 @@ void ARMMachObjectWriter::RecordARMScatteredRelocation(MachObjectWriter *Writer,
                  (IsPCRel     << 30) |
                  MachO::R_SCATTERED);
   MRE.r_word1 = Value;
-  Writer->addRelocation(nullptr, Fragment->getParent(), MRE);
+  Writer->addRelocation(nullptr, &Fragment->getParent()->getSectionData(), MRE);
 }
 
 bool ARMMachObjectWriter::requiresExternRelocation(MachObjectWriter *Writer,
@@ -336,7 +341,7 @@ bool ARMMachObjectWriter::requiresExternRelocation(MachObjectWriter *Writer,
   // enough information to generate a branch island.
   const MCSectionData &SymSD = Asm.getSectionData(S.getSection());
   Value += Writer->getSectionAddress(&SymSD);
-  Value -= Writer->getSectionAddress(Fragment.getParent());
+  Value -= Writer->getSectionAddress(&Fragment.getParent()->getSectionData());
   // If the resultant value would be out of range for an internal relocation,
   // use an external instead.
   if (Value > Range || Value < -(Range + 1))
@@ -430,7 +435,8 @@ void ARMMachObjectWriter::RecordRelocation(MachObjectWriter *Writer,
       FixedValue += Writer->getSectionAddress(&SymSD);
     }
     if (IsPCRel)
-      FixedValue -= Writer->getSectionAddress(Fragment->getParent());
+      FixedValue -=
+          Writer->getSectionAddress(&Fragment->getParent()->getSectionData());
 
     // The type is determined by the fixup kind.
     Type = RelocType;
@@ -465,10 +471,12 @@ void ARMMachObjectWriter::RecordRelocation(MachObjectWriter *Writer,
                        (Log2Size              << 25) |
                        (MachO::ARM_RELOC_PAIR << 28));
 
-    Writer->addRelocation(nullptr, Fragment->getParent(), MREPair);
+    Writer->addRelocation(nullptr, &Fragment->getParent()->getSectionData(),
+                          MREPair);
   }
 
-  Writer->addRelocation(RelSymbol, Fragment->getParent(), MRE);
+  Writer->addRelocation(RelSymbol, &Fragment->getParent()->getSectionData(),
+                        MRE);
 }
 
 MCObjectWriter *llvm::createARMMachObjectWriter(raw_pwrite_stream &OS,
index 1bdf031b81bc9f9fa91b13f4da5b335f37da193d..6fec196909f51474ef0ba5bf630afd67f5554504 100644 (file)
@@ -213,8 +213,8 @@ bool PPCMachObjectWriter::RecordScatteredRelocation(
                        "' can not be undefined in a subtraction expression");
 
   uint32_t Value = Writer->getSymbolAddress(*A, Layout);
-  uint64_t SecAddr =
-      Writer->getSectionAddress(A_SD->getFragment()->getParent());
+  uint64_t SecAddr = Writer->getSectionAddress(
+      &A_SD->getFragment()->getParent()->getSectionData());
   FixedValue += SecAddr;
   uint32_t Value2 = 0;
 
@@ -227,7 +227,8 @@ bool PPCMachObjectWriter::RecordScatteredRelocation(
 
     // FIXME: is Type correct? see include/llvm/Support/MachO.h
     Value2 = Writer->getSymbolAddress(B->getSymbol(), Layout);
-    FixedValue -= Writer->getSectionAddress(B_SD->getFragment()->getParent());
+    FixedValue -= Writer->getSectionAddress(
+        &B_SD->getFragment()->getParent()->getSectionData());
   }
   // FIXME: does FixedValue get used??
 
@@ -282,7 +283,8 @@ bool PPCMachObjectWriter::RecordScatteredRelocation(
     MachO::any_relocation_info MRE;
     makeScatteredRelocationInfo(MRE, other_half, MachO::GENERIC_RELOC_PAIR,
                                 Log2Size, IsPCRel, Value2);
-    Writer->addRelocation(nullptr, Fragment->getParent(), MRE);
+    Writer->addRelocation(nullptr, &Fragment->getParent()->getSectionData(),
+                          MRE);
   } else {
     // If the offset is more than 24-bits, it won't fit in a scattered
     // relocation offset field, so we fall back to using a non-scattered
@@ -296,7 +298,7 @@ bool PPCMachObjectWriter::RecordScatteredRelocation(
   }
   MachO::any_relocation_info MRE;
   makeScatteredRelocationInfo(MRE, FixupOffset, Type, Log2Size, IsPCRel, Value);
-  Writer->addRelocation(nullptr, Fragment->getParent(), MRE);
+  Writer->addRelocation(nullptr, &Fragment->getParent()->getSectionData(), MRE);
   return true;
 }
 
@@ -369,13 +371,15 @@ void PPCMachObjectWriter::RecordPPCRelocation(
       FixedValue += Writer->getSectionAddress(&SymSD);
     }
     if (IsPCRel)
-      FixedValue -= Writer->getSectionAddress(Fragment->getParent());
+      FixedValue -=
+          Writer->getSectionAddress(&Fragment->getParent()->getSectionData());
   }
 
   // struct relocation_info (8 bytes)
   MachO::any_relocation_info MRE;
   makeRelocationInfo(MRE, FixupOffset, Index, IsPCRel, Log2Size, false, Type);
-  Writer->addRelocation(RelSymbol, Fragment->getParent(), MRE);
+  Writer->addRelocation(RelSymbol, &Fragment->getParent()->getSectionData(),
+                        MRE);
 }
 
 MCObjectWriter *llvm::createPPCMachObjectWriter(raw_pwrite_stream &OS,
index e2d5ef20d4dc037e7d14c66a9b41cba1f8936594..05b58866b2763763a09b4d7c1e96770c7a491672 100644 (file)
@@ -190,19 +190,20 @@ void X86MachObjectWriter::RecordX86_64Relocation(
              (!B_Base ? 0 : Writer->getSymbolAddress(*B_Base, Layout));
 
     if (!A_Base)
-      Index = A_SD.getFragment()->getParent()->getSection().getOrdinal() + 1;
+      Index = A_SD.getFragment()->getParent()->getOrdinal() + 1;
     Type = MachO::X86_64_RELOC_UNSIGNED;
 
     MachO::any_relocation_info MRE;
     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, &Fragment->getParent()->getSectionData(),
+                          MRE);
 
     if (B_Base)
       RelSymbol = B_Base;
     else
-      Index = B_SD.getFragment()->getParent()->getSection().getOrdinal() + 1;
+      Index = B_SD.getFragment()->getParent()->getOrdinal() + 1;
     Type = MachO::X86_64_RELOC_SUBTRACTOR;
   } else {
     const MCSymbol *Symbol = &Target.getSymA()->getSymbol();
@@ -219,8 +220,8 @@ void X86MachObjectWriter::RecordX86_64Relocation(
     // understand x86_64 relocation entries, and expects to find values that
     // have already been fixed up.
     if (Symbol->isInSection()) {
-      const MCSectionMachO &Section = static_cast<const MCSectionMachO&>(
-        Fragment->getParent()->getSection());
+      const MCSectionMachO &Section =
+          static_cast<const MCSectionMachO &>(*Fragment->getParent());
       if (Section.hasAttribute(MachO::S_ATTR_DEBUG))
         RelSymbol = nullptr;
     }
@@ -235,7 +236,7 @@ void X86MachObjectWriter::RecordX86_64Relocation(
                  Layout.getSymbolOffset(*RelSymbol);
     } else if (Symbol->isInSection() && !Symbol->isVariable()) {
       // The index is the section ordinal (1-based).
-      Index = SD.getFragment()->getParent()->getSection().getOrdinal() + 1;
+      Index = SD.getFragment()->getParent()->getOrdinal() + 1;
       Value += Writer->getSymbolAddress(*Symbol, Layout);
 
       if (IsPCRel)
@@ -336,7 +337,8 @@ void X86MachObjectWriter::RecordX86_64Relocation(
   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, &Fragment->getParent()->getSectionData(),
+                        MRE);
 }
 
 bool X86MachObjectWriter::RecordScatteredRelocation(MachObjectWriter *Writer,
@@ -362,7 +364,8 @@ bool X86MachObjectWriter::RecordScatteredRelocation(MachObjectWriter *Writer,
                        false);
 
   uint32_t Value = Writer->getSymbolAddress(*A, Layout);
-  uint64_t SecAddr = Writer->getSectionAddress(A_SD->getFragment()->getParent());
+  uint64_t SecAddr = Writer->getSectionAddress(
+      &A_SD->getFragment()->getParent()->getSectionData());
   FixedValue += SecAddr;
   uint32_t Value2 = 0;
 
@@ -382,7 +385,8 @@ bool X86MachObjectWriter::RecordScatteredRelocation(MachObjectWriter *Writer,
     Type = A_SD->isExternal() ? (unsigned)MachO::GENERIC_RELOC_SECTDIFF :
       (unsigned)MachO::GENERIC_RELOC_LOCAL_SECTDIFF;
     Value2 = Writer->getSymbolAddress(B->getSymbol(), Layout);
-    FixedValue -= Writer->getSectionAddress(B_SD->getFragment()->getParent());
+    FixedValue -= Writer->getSectionAddress(
+        &B_SD->getFragment()->getParent()->getSectionData());
   }
 
   // Relocations are written out in reverse order, so the PAIR comes first.
@@ -408,7 +412,8 @@ bool X86MachObjectWriter::RecordScatteredRelocation(MachObjectWriter *Writer,
                    (IsPCRel                   << 30) |
                    MachO::R_SCATTERED);
     MRE.r_word1 = Value2;
-    Writer->addRelocation(nullptr, Fragment->getParent(), MRE);
+    Writer->addRelocation(nullptr, &Fragment->getParent()->getSectionData(),
+                          MRE);
   } else {
     // If the offset is more than 24-bits, it won't fit in a scattered
     // relocation offset field, so we fall back to using a non-scattered
@@ -430,7 +435,7 @@ bool X86MachObjectWriter::RecordScatteredRelocation(MachObjectWriter *Writer,
                  (IsPCRel     << 30) |
                  MachO::R_SCATTERED);
   MRE.r_word1 = Value;
-  Writer->addRelocation(nullptr, Fragment->getParent(), MRE);
+  Writer->addRelocation(nullptr, &Fragment->getParent()->getSectionData(), MRE);
   return true;
 }
 
@@ -472,8 +477,8 @@ void X86MachObjectWriter::RecordTLVPRelocation(MachObjectWriter *Writer,
   MRE.r_word0 = Value;
   MRE.r_word1 =
       (IsPCRel << 24) | (Log2Size << 25) | (MachO::GENERIC_RELOC_TLV << 28);
-  Writer->addRelocation(&Target.getSymA()->getSymbol(), Fragment->getParent(),
-                        MRE);
+  Writer->addRelocation(&Target.getSymA()->getSymbol(),
+                        &Fragment->getParent()->getSectionData(), MRE);
 }
 
 void X86MachObjectWriter::RecordX86Relocation(MachObjectWriter *Writer,
@@ -560,7 +565,8 @@ void X86MachObjectWriter::RecordX86Relocation(MachObjectWriter *Writer,
       FixedValue += Writer->getSectionAddress(&SymSD);
     }
     if (IsPCRel)
-      FixedValue -= Writer->getSectionAddress(Fragment->getParent());
+      FixedValue -=
+          Writer->getSectionAddress(&Fragment->getParent()->getSectionData());
 
     Type = MachO::GENERIC_RELOC_VANILLA;
   }
@@ -570,7 +576,8 @@ void X86MachObjectWriter::RecordX86Relocation(MachObjectWriter *Writer,
   MRE.r_word0 = FixupOffset;
   MRE.r_word1 =
       (Index << 0) | (IsPCRel << 24) | (Log2Size << 25) | (Type << 28);
-  Writer->addRelocation(RelSymbol, Fragment->getParent(), MRE);
+  Writer->addRelocation(RelSymbol, &Fragment->getParent()->getSectionData(),
+                        MRE);
 }
 
 MCObjectWriter *llvm::createX86MachObjectWriter(raw_pwrite_stream &OS,