[llvm] 262ad4c - [MC] Remove the MCAsmLayout parameter from MCMachObjectTargetWriter

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 30 21:53:40 PDT 2024


Author: Fangrui Song
Date: 2024-06-30T21:53:35-07:00
New Revision: 262ad4cdf4e9dd44ceec7a993cfce2b35a33fc34

URL: https://github.com/llvm/llvm-project/commit/262ad4cdf4e9dd44ceec7a993cfce2b35a33fc34
DIFF: https://github.com/llvm/llvm-project/commit/262ad4cdf4e9dd44ceec7a993cfce2b35a33fc34.diff

LOG: [MC] Remove the MCAsmLayout parameter from MCMachObjectTargetWriter

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCMachObjectWriter.h
    llvm/lib/MC/MachObjectWriter.cpp
    llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
    llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
    llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCMachObjectWriter.h b/llvm/include/llvm/MC/MCMachObjectWriter.h
index 6f47f12f73f13..9cdeaee7cdafd 100644
--- a/llvm/include/llvm/MC/MCMachObjectWriter.h
+++ b/llvm/include/llvm/MC/MCMachObjectWriter.h
@@ -73,7 +73,6 @@ class MCMachObjectTargetWriter : public MCObjectTargetWriter {
   /// @{
 
   virtual void recordRelocation(MachObjectWriter *Writer, MCAssembler &Asm,
-                                const MCAsmLayout &Layout,
                                 const MCFragment *Fragment,
                                 const MCFixup &Fixup, MCValue Target,
                                 uint64_t &FixedValue) = 0;

diff  --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp
index cecca548d8f0e..b3655dee5c190 100644
--- a/llvm/lib/MC/MachObjectWriter.cpp
+++ b/llvm/lib/MC/MachObjectWriter.cpp
@@ -502,8 +502,8 @@ void MachObjectWriter::recordRelocation(MCAssembler &Asm,
     return;
   }
 
-  TargetObjectWriter->recordRelocation(this, Asm, Layout, Fragment, Fixup,
-                                       Target, FixedValue);
+  TargetObjectWriter->recordRelocation(this, Asm, Fragment, Fixup, Target,
+                                       FixedValue);
 }
 
 void MachObjectWriter::bindIndirectSymbols(MCAssembler &Asm) {

diff  --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
index 51ae41c0ca192..1801d1060e297 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
@@ -42,9 +42,8 @@ class AArch64MachObjectWriter : public MCMachObjectTargetWriter {
       : MCMachObjectTargetWriter(!IsILP32 /* is64Bit */, CPUType, CPUSubtype) {}
 
   void recordRelocation(MachObjectWriter *Writer, MCAssembler &Asm,
-                        const MCAsmLayout &Layout, const MCFragment *Fragment,
-                        const MCFixup &Fixup, MCValue Target,
-                        uint64_t &FixedValue) override;
+                        const MCFragment *Fragment, const MCFixup &Fixup,
+                        MCValue Target, uint64_t &FixedValue) override;
 };
 
 } // end anonymous namespace
@@ -148,13 +147,12 @@ static bool canUseLocalRelocation(const MCSectionMachO &Section,
 }
 
 void AArch64MachObjectWriter::recordRelocation(
-    MachObjectWriter *Writer, MCAssembler &Asm, const MCAsmLayout &Layout,
-    const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target,
-    uint64_t &FixedValue) {
+    MachObjectWriter *Writer, MCAssembler &Asm, const MCFragment *Fragment,
+    const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue) {
   unsigned IsPCRel = Writer->isFixupKindPCRel(Asm, Fixup.getKind());
 
   // See <reloc.h>.
-  uint32_t FixupOffset = Layout.getFragmentOffset(Fragment);
+  uint32_t FixupOffset = Asm.getFragmentOffset(*Fragment);
   unsigned Log2Size = 0;
   int64_t Value = 0;
   unsigned Index = 0;
@@ -227,8 +225,8 @@ void AArch64MachObjectWriter::recordRelocation(
     //    ... _foo at got - Ltmp0
     if (Target.getSymA()->getKind() == MCSymbolRefExpr::VK_GOT &&
         Target.getSymB()->getKind() == MCSymbolRefExpr::VK_None &&
-        Layout.getSymbolOffset(*B) ==
-            Layout.getFragmentOffset(Fragment) + Fixup.getOffset()) {
+        Asm.getSymbolOffset(*B) ==
+            Asm.getFragmentOffset(*Fragment) + Fixup.getOffset()) {
       // SymB is the PC, so use a PC-rel pointer-to-GOT relocation.
       Type = MachO::ARM64_RELOC_POINTER_TO_GOT;
       IsPCRel = 1;
@@ -280,12 +278,18 @@ void AArch64MachObjectWriter::recordRelocation(
       return;
     }
 
-    Value += (!A->getFragment() ? 0 : Writer->getSymbolAddress(*A, Layout)) -
-             (!A_Base || !A_Base->getFragment() ? 0 : Writer->getSymbolAddress(
-                                                          *A_Base, Layout));
-    Value -= (!B->getFragment() ? 0 : Writer->getSymbolAddress(*B, Layout)) -
-             (!B_Base || !B_Base->getFragment() ? 0 : Writer->getSymbolAddress(
-                                                          *B_Base, Layout));
+    Value +=
+        (!A->getFragment() ? 0
+                           : Writer->getSymbolAddress(*A, *Asm.getLayout())) -
+        (!A_Base || !A_Base->getFragment()
+             ? 0
+             : Writer->getSymbolAddress(*A_Base, *Asm.getLayout()));
+    Value -=
+        (!B->getFragment() ? 0
+                           : Writer->getSymbolAddress(*B, *Asm.getLayout())) -
+        (!B_Base || !B_Base->getFragment()
+             ? 0
+             : Writer->getSymbolAddress(*B_Base, *Asm.getLayout()));
 
     Type = MachO::ARM64_RELOC_UNSIGNED;
 
@@ -341,8 +345,7 @@ void AArch64MachObjectWriter::recordRelocation(
 
       // Add the local offset, if needed.
       if (Base != Symbol)
-        Value +=
-            Layout.getSymbolOffset(*Symbol) - Layout.getSymbolOffset(*Base);
+        Value += Asm.getSymbolOffset(*Symbol) - Asm.getSymbolOffset(*Base);
     } else if (Symbol->isInSection()) {
       if (!CanUseLocalRelocation) {
         Asm.getContext().reportError(
@@ -355,10 +358,10 @@ void AArch64MachObjectWriter::recordRelocation(
       // The index is the section ordinal (1-based).
       const MCSection &Sec = Symbol->getSection();
       Index = Sec.getOrdinal() + 1;
-      Value += Writer->getSymbolAddress(*Symbol, Layout);
+      Value += Writer->getSymbolAddress(*Symbol, *Asm.getLayout());
 
       if (IsPCRel)
-        Value -= Writer->getFragmentAddress(Fragment, Layout) +
+        Value -= Writer->getFragmentAddress(Fragment, *Asm.getLayout()) +
                  Fixup.getOffset() + (1ULL << Log2Size);
     } else {
       llvm_unreachable(

diff  --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
index 5626c0b3eaca5..2a2372d44b5d5 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
@@ -27,18 +27,14 @@ using namespace llvm;
 
 namespace {
 class ARMMachObjectWriter : public MCMachObjectTargetWriter {
-  void RecordARMScatteredRelocation(MachObjectWriter *Writer,
+  void recordARMScatteredRelocation(MachObjectWriter *Writer,
                                     const MCAssembler &Asm,
-                                    const MCAsmLayout &Layout,
                                     const MCFragment *Fragment,
-                                    const MCFixup &Fixup,
-                                    MCValue Target,
-                                    unsigned Type,
-                                    unsigned Log2Size,
+                                    const MCFixup &Fixup, MCValue Target,
+                                    unsigned Type, unsigned Log2Size,
                                     uint64_t &FixedValue);
-  void RecordARMScatteredHalfRelocation(MachObjectWriter *Writer,
+  void recordARMScatteredHalfRelocation(MachObjectWriter *Writer,
                                         const MCAssembler &Asm,
-                                        const MCAsmLayout &Layout,
                                         const MCFragment *Fragment,
                                         const MCFixup &Fixup, MCValue Target,
                                         uint64_t &FixedValue);
@@ -53,9 +49,8 @@ class ARMMachObjectWriter : public MCMachObjectTargetWriter {
       : MCMachObjectTargetWriter(Is64Bit, CPUType, CPUSubtype) {}
 
   void recordRelocation(MachObjectWriter *Writer, MCAssembler &Asm,
-                        const MCAsmLayout &Layout, const MCFragment *Fragment,
-                        const MCFixup &Fixup, MCValue Target,
-                        uint64_t &FixedValue) override;
+                        const MCFragment *Fragment, const MCFixup &Fixup,
+                        MCValue Target, uint64_t &FixedValue) override;
 };
 }
 
@@ -136,15 +131,11 @@ static bool getARMFixupKindMachOInfo(unsigned Kind, unsigned &RelocType,
   }
 }
 
-void ARMMachObjectWriter::
-RecordARMScatteredHalfRelocation(MachObjectWriter *Writer,
-                                 const MCAssembler &Asm,
-                                 const MCAsmLayout &Layout,
-                                 const MCFragment *Fragment,
-                                 const MCFixup &Fixup,
-                                 MCValue Target,
-                                 uint64_t &FixedValue) {
-  uint32_t FixupOffset = Layout.getFragmentOffset(Fragment)+Fixup.getOffset();
+void ARMMachObjectWriter::recordARMScatteredHalfRelocation(
+    MachObjectWriter *Writer, const MCAssembler &Asm,
+    const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target,
+    uint64_t &FixedValue) {
+  uint32_t FixupOffset = Asm.getFragmentOffset(*Fragment) + Fixup.getOffset();
 
   if (FixupOffset & 0xff000000) {
     Asm.getContext().reportError(Fixup.getLoc(),
@@ -167,7 +158,7 @@ RecordARMScatteredHalfRelocation(MachObjectWriter *Writer,
     return;
   }
 
-  uint32_t Value = Writer->getSymbolAddress(*A, Layout);
+  uint32_t Value = Writer->getSymbolAddress(*A, *Asm.getLayout());
   uint32_t Value2 = 0;
   uint64_t SecAddr = Writer->getSectionAddress(A->getFragment()->getParent());
   FixedValue += SecAddr;
@@ -184,7 +175,7 @@ RecordARMScatteredHalfRelocation(MachObjectWriter *Writer,
 
     // Select the appropriate 
diff erence relocation type.
     Type = MachO::ARM_RELOC_HALF_SECTDIFF;
-    Value2 = Writer->getSymbolAddress(B->getSymbol(), Layout);
+    Value2 = Writer->getSymbolAddress(B->getSymbol(), *Asm.getLayout());
     FixedValue -= Writer->getSectionAddress(SB->getFragment()->getParent());
   }
 
@@ -250,16 +241,11 @@ RecordARMScatteredHalfRelocation(MachObjectWriter *Writer,
   Writer->addRelocation(nullptr, Fragment->getParent(), MRE);
 }
 
-void ARMMachObjectWriter::RecordARMScatteredRelocation(MachObjectWriter *Writer,
-                                                    const MCAssembler &Asm,
-                                                    const MCAsmLayout &Layout,
-                                                    const MCFragment *Fragment,
-                                                    const MCFixup &Fixup,
-                                                    MCValue Target,
-                                                    unsigned Type,
-                                                    unsigned Log2Size,
-                                                    uint64_t &FixedValue) {
-  uint32_t FixupOffset = Layout.getFragmentOffset(Fragment)+Fixup.getOffset();
+void ARMMachObjectWriter::recordARMScatteredRelocation(
+    MachObjectWriter *Writer, const MCAssembler &Asm,
+    const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target,
+    unsigned Type, unsigned Log2Size, uint64_t &FixedValue) {
+  uint32_t FixupOffset = Asm.getFragmentOffset(*Fragment) + Fixup.getOffset();
 
   if (FixupOffset & 0xff000000) {
     Asm.getContext().reportError(Fixup.getLoc(),
@@ -281,7 +267,7 @@ void ARMMachObjectWriter::RecordARMScatteredRelocation(MachObjectWriter *Writer,
     return;
   }
 
-  uint32_t Value = Writer->getSymbolAddress(*A, Layout);
+  uint32_t Value = Writer->getSymbolAddress(*A, *Asm.getLayout());
   uint64_t SecAddr = Writer->getSectionAddress(A->getFragment()->getParent());
   FixedValue += SecAddr;
   uint32_t Value2 = 0;
@@ -299,7 +285,7 @@ void ARMMachObjectWriter::RecordARMScatteredRelocation(MachObjectWriter *Writer,
 
     // Select the appropriate 
diff erence relocation type.
     Type = MachO::ARM_RELOC_SECTDIFF;
-    Value2 = Writer->getSymbolAddress(B->getSymbol(), Layout);
+    Value2 = Writer->getSymbolAddress(B->getSymbol(), *Asm.getLayout());
     FixedValue -= Writer->getSectionAddress(SB->getFragment()->getParent());
   }
 
@@ -374,7 +360,6 @@ bool ARMMachObjectWriter::requiresExternRelocation(MachObjectWriter *Writer,
 
 void ARMMachObjectWriter::recordRelocation(MachObjectWriter *Writer,
                                            MCAssembler &Asm,
-                                           const MCAsmLayout &Layout,
                                            const MCFragment *Fragment,
                                            const MCFixup &Fixup, MCValue Target,
                                            uint64_t &FixedValue) {
@@ -395,11 +380,10 @@ void ARMMachObjectWriter::recordRelocation(MachObjectWriter *Writer,
   // relocations.
   if (Target.getSymB()) {
     if (RelocType == MachO::ARM_RELOC_HALF)
-      return RecordARMScatteredHalfRelocation(Writer, Asm, Layout, Fragment,
-                                              Fixup, Target, FixedValue);
-    return RecordARMScatteredRelocation(Writer, Asm, Layout, Fragment, Fixup,
-                                        Target, RelocType, Log2Size,
-                                        FixedValue);
+      return recordARMScatteredHalfRelocation(Writer, Asm, Fragment, Fixup,
+                                              Target, FixedValue);
+    return recordARMScatteredRelocation(Writer, Asm, Fragment, Fixup, Target,
+                                        RelocType, Log2Size, FixedValue);
   }
 
   // Get the symbol data, if any.
@@ -417,12 +401,11 @@ void ARMMachObjectWriter::recordRelocation(MachObjectWriter *Writer,
     Offset += 1 << Log2Size;
   if (Offset && A && !Writer->doesSymbolRequireExternRelocation(*A) &&
       RelocType != MachO::ARM_RELOC_HALF)
-    return RecordARMScatteredRelocation(Writer, Asm, Layout, Fragment, Fixup,
-                                        Target, RelocType, Log2Size,
-                                        FixedValue);
+    return recordARMScatteredRelocation(Writer, Asm, Fragment, Fixup, Target,
+                                        RelocType, Log2Size, FixedValue);
 
   // See <reloc.h>.
-  uint32_t FixupOffset = Layout.getFragmentOffset(Fragment)+Fixup.getOffset();
+  uint32_t FixupOffset = Asm.getFragmentOffset(*Fragment) + Fixup.getOffset();
   unsigned Index = 0;
   unsigned Type = 0;
   const MCSymbol *RelSymbol = nullptr;
@@ -453,7 +436,7 @@ void ARMMachObjectWriter::recordRelocation(MachObjectWriter *Writer,
       // compensate for the addend of the symbol address, if it was
       // undefined. This occurs with weak definitions, for example.
       if (!A->isUndefined())
-        FixedValue -= Layout.getSymbolOffset(*A);
+        FixedValue -= Asm.getSymbolOffset(*A);
     } else {
       // The index is the section ordinal (1-based).
       const MCSection &Sec = A->getSection();

diff  --git a/llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp
index 825bd3a203d1f..0dbf367c5fa1b 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp
@@ -27,7 +27,6 @@ namespace {
 class X86MachObjectWriter : public MCMachObjectTargetWriter {
   bool recordScatteredRelocation(MachObjectWriter *Writer,
                                  const MCAssembler &Asm,
-                                 const MCAsmLayout &Layout,
                                  const MCFragment *Fragment,
                                  const MCFixup &Fixup,
                                  MCValue Target,
@@ -35,7 +34,6 @@ class X86MachObjectWriter : public MCMachObjectTargetWriter {
                                  uint64_t &FixedValue);
   void recordTLVPRelocation(MachObjectWriter *Writer,
                             const MCAssembler &Asm,
-                            const MCAsmLayout &Layout,
                             const MCFragment *Fragment,
                             const MCFixup &Fixup,
                             MCValue Target,
@@ -43,13 +41,11 @@ class X86MachObjectWriter : public MCMachObjectTargetWriter {
 
   void RecordX86Relocation(MachObjectWriter *Writer,
                               const MCAssembler &Asm,
-                              const MCAsmLayout &Layout,
                               const MCFragment *Fragment,
                               const MCFixup &Fixup,
                               MCValue Target,
                               uint64_t &FixedValue);
   void RecordX86_64Relocation(MachObjectWriter *Writer, MCAssembler &Asm,
-                              const MCAsmLayout &Layout,
                               const MCFragment *Fragment, const MCFixup &Fixup,
                               MCValue Target, uint64_t &FixedValue);
 
@@ -58,15 +54,12 @@ class X86MachObjectWriter : public MCMachObjectTargetWriter {
       : MCMachObjectTargetWriter(Is64Bit, CPUType, CPUSubtype) {}
 
   void recordRelocation(MachObjectWriter *Writer, MCAssembler &Asm,
-                        const MCAsmLayout &Layout, const MCFragment *Fragment,
-                        const MCFixup &Fixup, MCValue Target,
-                        uint64_t &FixedValue) override {
+                        const MCFragment *Fragment, const MCFixup &Fixup,
+                        MCValue Target, uint64_t &FixedValue) override {
     if (Writer->is64Bit())
-      RecordX86_64Relocation(Writer, Asm, Layout, Fragment, Fixup, Target,
-                             FixedValue);
+      RecordX86_64Relocation(Writer, Asm, Fragment, Fixup, Target, FixedValue);
     else
-      RecordX86Relocation(Writer, Asm, Layout, Fragment, Fixup, Target,
-                          FixedValue);
+      RecordX86Relocation(Writer, Asm, Fragment, Fixup, Target, FixedValue);
   }
 };
 } // namespace
@@ -101,18 +94,17 @@ static unsigned getFixupKindLog2Size(unsigned Kind) {
 }
 
 void X86MachObjectWriter::RecordX86_64Relocation(
-    MachObjectWriter *Writer, MCAssembler &Asm, const MCAsmLayout &Layout,
-    const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target,
-    uint64_t &FixedValue) {
+    MachObjectWriter *Writer, MCAssembler &Asm, const MCFragment *Fragment,
+    const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue) {
   unsigned IsPCRel = Writer->isFixupKindPCRel(Asm, Fixup.getKind());
   unsigned IsRIPRel = isFixupKindRIPRel(Fixup.getKind());
   unsigned Log2Size = getFixupKindLog2Size(Fixup.getKind());
 
   // See <reloc.h>.
-  uint32_t FixupOffset =
-    Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
+  uint32_t FixupOffset = Asm.getFragmentOffset(*Fragment) + Fixup.getOffset();
   uint32_t FixupAddress =
-    Writer->getFragmentAddress(Fragment, Layout) + Fixup.getOffset();
+      Writer->getFragmentAddress(Fragment, *Asm.getLayout()) +
+      Fixup.getOffset();
   int64_t Value = 0;
   unsigned Index = 0;
   unsigned IsExtern = 0;
@@ -194,10 +186,12 @@ void X86MachObjectWriter::RecordX86_64Relocation(
       return;
     }
 
-    Value += Writer->getSymbolAddress(*A, Layout) -
-             (!A_Base ? 0 : Writer->getSymbolAddress(*A_Base, Layout));
-    Value -= Writer->getSymbolAddress(*B, Layout) -
-             (!B_Base ? 0 : Writer->getSymbolAddress(*B_Base, Layout));
+    Value +=
+        Writer->getSymbolAddress(*A, *Asm.getLayout()) -
+        (!A_Base ? 0 : Writer->getSymbolAddress(*A_Base, *Asm.getLayout()));
+    Value -=
+        Writer->getSymbolAddress(*B, *Asm.getLayout()) -
+        (!B_Base ? 0 : Writer->getSymbolAddress(*B_Base, *Asm.getLayout()));
 
     if (!A_Base)
       Index = A->getFragment()->getParent()->getOrdinal() + 1;
@@ -240,12 +234,11 @@ void X86MachObjectWriter::RecordX86_64Relocation(
     if (RelSymbol) {
       // Add the local offset, if needed.
       if (RelSymbol != Symbol)
-        Value += Layout.getSymbolOffset(*Symbol) -
-                 Layout.getSymbolOffset(*RelSymbol);
+        Value += Asm.getSymbolOffset(*Symbol) - Asm.getSymbolOffset(*RelSymbol);
     } else if (Symbol->isInSection() && !Symbol->isVariable()) {
       // The index is the section ordinal (1-based).
       Index = Symbol->getFragment()->getParent()->getOrdinal() + 1;
-      Value += Writer->getSymbolAddress(*Symbol, Layout);
+      Value += Writer->getSymbolAddress(*Symbol, *Asm.getLayout());
 
       if (IsPCRel)
         Value -= FixupAddress + (1 << Log2Size);
@@ -363,14 +356,13 @@ void X86MachObjectWriter::RecordX86_64Relocation(
 
 bool X86MachObjectWriter::recordScatteredRelocation(MachObjectWriter *Writer,
                                                     const MCAssembler &Asm,
-                                                    const MCAsmLayout &Layout,
                                                     const MCFragment *Fragment,
                                                     const MCFixup &Fixup,
                                                     MCValue Target,
                                                     unsigned Log2Size,
                                                     uint64_t &FixedValue) {
   uint64_t OriginalFixedValue = FixedValue;
-  uint32_t FixupOffset = Layout.getFragmentOffset(Fragment)+Fixup.getOffset();
+  uint32_t FixupOffset = Asm.getFragmentOffset(*Fragment) + Fixup.getOffset();
   unsigned IsPCRel = Writer->isFixupKindPCRel(Asm, Fixup.getKind());
   unsigned Type = MachO::GENERIC_RELOC_VANILLA;
 
@@ -385,7 +377,7 @@ bool X86MachObjectWriter::recordScatteredRelocation(MachObjectWriter *Writer,
     return false;
   }
 
-  uint32_t Value = Writer->getSymbolAddress(*A, Layout);
+  uint32_t Value = Writer->getSymbolAddress(*A, *Asm.getLayout());
   uint64_t SecAddr = Writer->getSectionAddress(A->getFragment()->getParent());
   FixedValue += SecAddr;
   uint32_t Value2 = 0;
@@ -408,7 +400,7 @@ bool X86MachObjectWriter::recordScatteredRelocation(MachObjectWriter *Writer,
     // pedantic compatibility with 'as'.
     Type = A->isExternal() ? (unsigned)MachO::GENERIC_RELOC_SECTDIFF
                            : (unsigned)MachO::GENERIC_RELOC_LOCAL_SECTDIFF;
-    Value2 = Writer->getSymbolAddress(*SB, Layout);
+    Value2 = Writer->getSymbolAddress(*SB, *Asm.getLayout());
     FixedValue -= Writer->getSectionAddress(SB->getFragment()->getParent());
   }
 
@@ -463,7 +455,6 @@ bool X86MachObjectWriter::recordScatteredRelocation(MachObjectWriter *Writer,
 
 void X86MachObjectWriter::recordTLVPRelocation(MachObjectWriter *Writer,
                                                const MCAssembler &Asm,
-                                               const MCAsmLayout &Layout,
                                                const MCFragment *Fragment,
                                                const MCFixup &Fixup,
                                                MCValue Target,
@@ -473,7 +464,7 @@ void X86MachObjectWriter::recordTLVPRelocation(MachObjectWriter *Writer,
          "Should only be called with a 32-bit TLVP relocation!");
 
   unsigned Log2Size = getFixupKindLog2Size(Fixup.getKind());
-  uint32_t Value = Layout.getFragmentOffset(Fragment)+Fixup.getOffset();
+  uint32_t Value = Asm.getFragmentOffset(*Fragment) + Fixup.getOffset();
   unsigned IsPCRel = 0;
 
   // We're only going to have a second symbol in pic mode and it'll be a
@@ -483,10 +474,11 @@ void X86MachObjectWriter::recordTLVPRelocation(MachObjectWriter *Writer,
   if (auto *SymB = Target.getSymB()) {
     // If this is a subtraction then we're pcrel.
     uint32_t FixupAddress =
-      Writer->getFragmentAddress(Fragment, Layout) + Fixup.getOffset();
+        Writer->getFragmentAddress(Fragment, *Asm.getLayout()) +
+        Fixup.getOffset();
     IsPCRel = 1;
     FixedValue = FixupAddress -
-                 Writer->getSymbolAddress(SymB->getSymbol(), Layout) +
+                 Writer->getSymbolAddress(SymB->getSymbol(), *Asm.getLayout()) +
                  Target.getConstant();
     FixedValue += 1ULL << Log2Size;
   } else {
@@ -503,7 +495,6 @@ void X86MachObjectWriter::recordTLVPRelocation(MachObjectWriter *Writer,
 
 void X86MachObjectWriter::RecordX86Relocation(MachObjectWriter *Writer,
                                               const MCAssembler &Asm,
-                                              const MCAsmLayout &Layout,
                                               const MCFragment *Fragment,
                                               const MCFixup &Fixup,
                                               MCValue Target,
@@ -514,8 +505,7 @@ void X86MachObjectWriter::RecordX86Relocation(MachObjectWriter *Writer,
   // If this is a 32-bit TLVP reloc it's handled a bit 
diff erently.
   if (Target.getSymA() &&
       Target.getSymA()->getKind() == MCSymbolRefExpr::VK_TLVP) {
-    recordTLVPRelocation(Writer, Asm, Layout, Fragment, Fixup, Target,
-                         FixedValue);
+    recordTLVPRelocation(Writer, Asm, Fragment, Fixup, Target, FixedValue);
     return;
   }
 
@@ -523,8 +513,8 @@ void X86MachObjectWriter::RecordX86Relocation(MachObjectWriter *Writer,
   // scattered relocation entry. Differences always require scattered
   // relocations.
   if (Target.getSymB()) {
-    recordScatteredRelocation(Writer, Asm, Layout, Fragment, Fixup,
-                              Target, Log2Size, FixedValue);
+    recordScatteredRelocation(Writer, Asm, Fragment, Fixup, Target, Log2Size,
+                              FixedValue);
     return;
   }
 
@@ -543,12 +533,12 @@ void X86MachObjectWriter::RecordX86Relocation(MachObjectWriter *Writer,
   // scattered if necessary (see comments in recordScatteredRelocation()
   // for details).
   if (Offset && A && !Writer->doesSymbolRequireExternRelocation(*A) &&
-      recordScatteredRelocation(Writer, Asm, Layout, Fragment, Fixup, Target,
-                                Log2Size, FixedValue))
+      recordScatteredRelocation(Writer, Asm, Fragment, Fixup, Target, Log2Size,
+                                FixedValue))
     return;
 
   // See <reloc.h>.
-  uint32_t FixupOffset = Layout.getFragmentOffset(Fragment)+Fixup.getOffset();
+  uint32_t FixupOffset = Asm.getFragmentOffset(*Fragment) + Fixup.getOffset();
   unsigned Index = 0;
   unsigned Type = 0;
   const MCSymbol *RelSymbol = nullptr;
@@ -579,7 +569,7 @@ void X86MachObjectWriter::RecordX86Relocation(MachObjectWriter *Writer,
       // compensate for the addend of the symbol address, if it was
       // undefined. This occurs with weak definitions, for example.
       if (!A->isUndefined())
-        FixedValue -= Layout.getSymbolOffset(*A);
+        FixedValue -= Asm.getSymbolOffset(*A);
     } else {
       // The index is the section ordinal (1-based).
       const MCSection &Sec = A->getSection();


        


More information about the llvm-commits mailing list