[llvm] e373f7a - MC: Simplify recordRelocation

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat May 24 09:54:08 PDT 2025


Author: Fangrui Song
Date: 2025-05-24T09:54:03-07:00
New Revision: e373f7a45297ce7ff4e75d8ae45145f4f22ecc46

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

LOG: MC: Simplify recordRelocation

* Remove the MCAssembler * argument. Change subclasses to use MCAssembler *MCObjectWriter::Asm.
* Remove pure specifier and add an empty implementation
* Change MCFragment * to MCFragment &

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCDXContainerWriter.h
    llvm/include/llvm/MC/MCELFObjectWriter.h
    llvm/include/llvm/MC/MCMachObjectWriter.h
    llvm/include/llvm/MC/MCObjectWriter.h
    llvm/include/llvm/MC/MCSPIRVObjectWriter.h
    llvm/include/llvm/MC/MCWinCOFFObjectWriter.h
    llvm/lib/MC/ELFObjectWriter.cpp
    llvm/lib/MC/GOFFObjectWriter.cpp
    llvm/lib/MC/MCAsmBackend.cpp
    llvm/lib/MC/MCObjectWriter.cpp
    llvm/lib/MC/MachObjectWriter.cpp
    llvm/lib/MC/WasmObjectWriter.cpp
    llvm/lib/MC/WinCOFFObjectWriter.cpp
    llvm/lib/MC/XCOFFObjectWriter.cpp
    llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp
    llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
    llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCDXContainerWriter.h b/llvm/include/llvm/MC/MCDXContainerWriter.h
index b3ca3d73a09b7..5822ced4e0929 100644
--- a/llvm/include/llvm/MC/MCDXContainerWriter.h
+++ b/llvm/include/llvm/MC/MCDXContainerWriter.h
@@ -42,10 +42,6 @@ class DXContainerObjectWriter final : public MCObjectWriter {
                           raw_pwrite_stream &OS)
       : W(OS, llvm::endianness::little), TargetObjectWriter(std::move(MOTW)) {}
 
-  void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
-                        const MCFixup &Fixup, MCValue Target,
-                        uint64_t &FixedValue) override {}
-
   uint64_t writeObject(MCAssembler &Asm) override;
 };
 } // end namespace llvm

diff  --git a/llvm/include/llvm/MC/MCELFObjectWriter.h b/llvm/include/llvm/MC/MCELFObjectWriter.h
index 0bac33820ad9d..180c0c3b6bc00 100644
--- a/llvm/include/llvm/MC/MCELFObjectWriter.h
+++ b/llvm/include/llvm/MC/MCELFObjectWriter.h
@@ -170,9 +170,8 @@ class ELFObjectWriter final : public MCObjectWriter {
 
   void reset() override;
   void executePostLayoutBinding() override;
-  void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
-                        const MCFixup &Fixup, MCValue Target,
-                        uint64_t &FixedValue) override;
+  void recordRelocation(const MCFragment &F, const MCFixup &Fixup,
+                        MCValue Target, uint64_t &FixedValue) override;
   bool isSymbolRefDifferenceFullyResolvedImpl(const MCSymbol &SymA,
                                               const MCFragment &FB, bool InSet,
                                               bool IsPCRel) const override;

diff  --git a/llvm/include/llvm/MC/MCMachObjectWriter.h b/llvm/include/llvm/MC/MCMachObjectWriter.h
index 9a6d26237021a..9c2d189284f85 100644
--- a/llvm/include/llvm/MC/MCMachObjectWriter.h
+++ b/llvm/include/llvm/MC/MCMachObjectWriter.h
@@ -327,9 +327,8 @@ class MachObjectWriter final : public MCObjectWriter {
     Relocations[Sec].push_back(P);
   }
 
-  void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
-                        const MCFixup &Fixup, MCValue Target,
-                        uint64_t &FixedValue) override;
+  void recordRelocation(const MCFragment &F, const MCFixup &Fixup,
+                        MCValue Target, uint64_t &FixedValue) override;
 
   void bindIndirectSymbols(MCAssembler &Asm);
 

diff  --git a/llvm/include/llvm/MC/MCObjectWriter.h b/llvm/include/llvm/MC/MCObjectWriter.h
index ef79262700163..23794226f8761 100644
--- a/llvm/include/llvm/MC/MCObjectWriter.h
+++ b/llvm/include/llvm/MC/MCObjectWriter.h
@@ -78,9 +78,8 @@ class MCObjectWriter {
   /// post layout binding. The implementation is responsible for storing
   /// information about the relocation so that it can be emitted during
   /// writeObject().
-  virtual void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
-                                const MCFixup &Fixup, MCValue Target,
-                                uint64_t &FixedValue) = 0;
+  virtual void recordRelocation(const MCFragment &F, const MCFixup &Fixup,
+                                MCValue Target, uint64_t &FixedValue);
 
   /// Check whether the 
diff erence (A - B) between two symbol references is
   /// fully resolved.

diff  --git a/llvm/include/llvm/MC/MCSPIRVObjectWriter.h b/llvm/include/llvm/MC/MCSPIRVObjectWriter.h
index 18bdb8be0145e..4fc205f96ce52 100644
--- a/llvm/include/llvm/MC/MCSPIRVObjectWriter.h
+++ b/llvm/include/llvm/MC/MCSPIRVObjectWriter.h
@@ -46,10 +46,6 @@ class SPIRVObjectWriter final : public MCObjectWriter {
   void setBuildVersion(unsigned Major, unsigned Minor, unsigned Bound);
 
 private:
-  void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
-                        const MCFixup &Fixup, MCValue Target,
-                        uint64_t &FixedValue) override {}
-
   uint64_t writeObject(MCAssembler &Asm) override;
   void writeHeader(const MCAssembler &Asm);
 };

diff  --git a/llvm/include/llvm/MC/MCWinCOFFObjectWriter.h b/llvm/include/llvm/MC/MCWinCOFFObjectWriter.h
index 8c58e7c0efd75..5df93bc889d03 100644
--- a/llvm/include/llvm/MC/MCWinCOFFObjectWriter.h
+++ b/llvm/include/llvm/MC/MCWinCOFFObjectWriter.h
@@ -67,9 +67,8 @@ class WinCOFFObjectWriter final : public MCObjectWriter {
   bool isSymbolRefDifferenceFullyResolvedImpl(const MCSymbol &SymA,
                                               const MCFragment &FB, bool InSet,
                                               bool IsPCRel) const override;
-  void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
-                        const MCFixup &Fixup, MCValue Target,
-                        uint64_t &FixedValue) override;
+  void recordRelocation(const MCFragment &F, const MCFixup &Fixup,
+                        MCValue Target, uint64_t &FixedValue) override;
   uint64_t writeObject(MCAssembler &Asm) override;
   int getSectionNumber(const MCSection &Section) const;
 };

diff  --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 986bc6e098392..4185f4b403e95 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -1322,12 +1322,11 @@ bool ELFObjectWriter::checkRelocation(MCContext &Ctx, SMLoc Loc,
   return true;
 }
 
-void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
-                                       const MCFragment *Fragment,
+void ELFObjectWriter::recordRelocation(const MCFragment &F,
                                        const MCFixup &Fixup, MCValue Target,
                                        uint64_t &FixedValue) {
-  MCAsmBackend &Backend = Asm.getBackend();
-  const MCSectionELF &FixupSection = cast<MCSectionELF>(*Fragment->getParent());
+  MCAsmBackend &Backend = Asm->getBackend();
+  const MCSectionELF &FixupSection = cast<MCSectionELF>(*F.getParent());
   MCContext &Ctx = getContext();
 
   const auto *SymA = cast_or_null<MCSymbolELF>(Target.getAddSym());
@@ -1350,7 +1349,7 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
 
   bool IsPCRel = Backend.getFixupKindInfo(Fixup.getKind()).Flags &
                  MCFixupKindInfo::FKF_IsPCRel;
-  uint64_t FixupOffset = Asm.getFragmentOffset(*Fragment) + Fixup.getOffset();
+  uint64_t FixupOffset = Asm->getFragmentOffset(F) + Fixup.getOffset();
   uint64_t Addend = Target.getConstant();
   if (auto *RefB = Target.getSubSym()) {
     const auto &SymB = cast<MCSymbolELF>(*RefB);
@@ -1371,7 +1370,7 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
 
     assert(!IsPCRel && "should have been folded");
     IsPCRel = true;
-    Addend += FixupOffset - Asm.getSymbolOffset(SymB);
+    Addend += FixupOffset - Asm->getSymbolOffset(SymB);
   }
 
   unsigned Type;
@@ -1383,13 +1382,13 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
   bool UseSectionSym =
       SymA && SymA->getBinding() == ELF::STB_LOCAL && !SymA->isUndefined();
   if (UseSectionSym) {
-    UseSectionSym = useSectionSymbol(Asm, Target, SymA, Addend, Type);
+    UseSectionSym = useSectionSymbol(*Asm, Target, SymA, Addend, Type);
 
     // Disable STT_SECTION adjustment for .reloc directives.
     UseSectionSym &= !mc::isRelocRelocation(Fixup.getKind());
 
     if (UseSectionSym)
-      Addend += Asm.getSymbolOffset(*SymA);
+      Addend += Asm->getSymbolOffset(*SymA);
   }
 
   FixedValue = usesRela(Ctx.getTargetOptions(), FixupSection) ? 0 : Addend;

diff  --git a/llvm/lib/MC/GOFFObjectWriter.cpp b/llvm/lib/MC/GOFFObjectWriter.cpp
index 85deebd89d1f6..00b4692fbc782 100644
--- a/llvm/lib/MC/GOFFObjectWriter.cpp
+++ b/llvm/lib/MC/GOFFObjectWriter.cpp
@@ -243,9 +243,8 @@ class GOFFObjectWriter : public MCObjectWriter {
   void writeEnd();
 
   // Implementation of the MCObjectWriter interface.
-  void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
-                        const MCFixup &Fixup, MCValue Target,
-                        uint64_t &FixedValue) override {}
+  void recordRelocation(const MCFragment &F, const MCFixup &Fixup,
+                        MCValue Target, uint64_t &FixedValue) override {}
   uint64_t writeObject(MCAssembler &Asm) override;
 };
 } // end anonymous namespace

diff  --git a/llvm/lib/MC/MCAsmBackend.cpp b/llvm/lib/MC/MCAsmBackend.cpp
index 750358087b5bc..5570499be5f35 100644
--- a/llvm/lib/MC/MCAsmBackend.cpp
+++ b/llvm/lib/MC/MCAsmBackend.cpp
@@ -126,7 +126,7 @@ bool MCAsmBackend::addReloc(const MCFragment &F, const MCFixup &Fixup,
   if (IsResolved && shouldForceRelocation(Fixup, Target))
     IsResolved = false;
   if (!IsResolved)
-    Asm->getWriter().recordRelocation(*Asm, &F, Fixup, Target, FixedValue);
+    Asm->getWriter().recordRelocation(F, Fixup, Target, FixedValue);
   return IsResolved;
 }
 

diff  --git a/llvm/lib/MC/MCObjectWriter.cpp b/llvm/lib/MC/MCObjectWriter.cpp
index 47bb6b1c01a0a..0c1789a531a9f 100644
--- a/llvm/lib/MC/MCObjectWriter.cpp
+++ b/llvm/lib/MC/MCObjectWriter.cpp
@@ -11,6 +11,7 @@
 #include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCFragment.h"
 #include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCValue.h"
 namespace llvm {
 class MCSection;
 }
@@ -29,6 +30,9 @@ void MCObjectWriter::reset() {
   CGProfile.clear();
 }
 
+void MCObjectWriter::recordRelocation(const MCFragment &F, const MCFixup &Fixup,
+                                      MCValue Target, uint64_t &FixedValue) {}
+
 bool MCObjectWriter::isSymbolRefDifferenceFullyResolved(const MCSymbol &SA,
                                                         const MCSymbol &SB,
                                                         bool InSet) const {

diff  --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp
index 86eb92cec6f2c..3050372257e66 100644
--- a/llvm/lib/MC/MachObjectWriter.cpp
+++ b/llvm/lib/MC/MachObjectWriter.cpp
@@ -511,8 +511,7 @@ static bool isFixupTargetValid(const MCValue &Target) {
   return true;
 }
 
-void MachObjectWriter::recordRelocation(MCAssembler &Asm,
-                                        const MCFragment *Fragment,
+void MachObjectWriter::recordRelocation(const MCFragment &F,
                                         const MCFixup &Fixup, MCValue Target,
                                         uint64_t &FixedValue) {
   if (!isFixupTargetValid(Target)) {
@@ -521,7 +520,7 @@ void MachObjectWriter::recordRelocation(MCAssembler &Asm,
     return;
   }
 
-  TargetObjectWriter->recordRelocation(this, Asm, Fragment, Fixup, Target,
+  TargetObjectWriter->recordRelocation(this, *Asm, &F, Fixup, Target,
                                        FixedValue);
 }
 

diff  --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp
index f6175414ef6f9..03746aeb6a3a6 100644
--- a/llvm/lib/MC/WasmObjectWriter.cpp
+++ b/llvm/lib/MC/WasmObjectWriter.cpp
@@ -292,9 +292,8 @@ class WasmObjectWriter : public MCObjectWriter {
 
   void writeHeader(const MCAssembler &Asm);
 
-  void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
-                        const MCFixup &Fixup, MCValue Target,
-                        uint64_t &FixedValue) override;
+  void recordRelocation(const MCFragment &F, const MCFixup &Fixup,
+                        MCValue Target, uint64_t &FixedValue) override;
 
   void executePostLayoutBinding() override;
   void prepareImports(SmallVectorImpl<wasm::WasmImport> &Imports,
@@ -476,17 +475,16 @@ void WasmObjectWriter::executePostLayoutBinding() {
   }
 }
 
-void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
-                                        const MCFragment *Fragment,
+void WasmObjectWriter::recordRelocation(const MCFragment &F,
                                         const MCFixup &Fixup, MCValue Target,
                                         uint64_t &FixedValue) {
   // The WebAssembly backend should never generate FKF_IsPCRel fixups
-  assert(!(Asm.getBackend().getFixupKindInfo(Fixup.getKind()).Flags &
+  assert(!(Asm->getBackend().getFixupKindInfo(Fixup.getKind()).Flags &
            MCFixupKindInfo::FKF_IsPCRel));
 
-  const auto &FixupSection = cast<MCSectionWasm>(*Fragment->getParent());
+  const auto &FixupSection = cast<MCSectionWasm>(*F.getParent());
   uint64_t C = Target.getConstant();
-  uint64_t FixupOffset = Asm.getFragmentOffset(*Fragment) + Fixup.getOffset();
+  uint64_t FixupOffset = Asm->getFragmentOffset(F) + Fixup.getOffset();
   MCContext &Ctx = getContext();
   bool IsLocRel = false;
 
@@ -515,7 +513,7 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
       return;
     }
     IsLocRel = true;
-    C += FixupOffset - Asm.getSymbolOffset(SymB);
+    C += FixupOffset - Asm->getSymbolOffset(SymB);
   }
 
   // We either rejected the fixup or folded B into C at this point.
@@ -571,7 +569,7 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
     if (!SectionSymbol)
       report_fatal_error("section symbol is required for relocation");
 
-    C += Asm.getSymbolOffset(*SymA);
+    C += Asm->getSymbolOffset(*SymA);
     SymA = cast<MCSymbolWasm>(SectionSymbol);
   }
 
@@ -592,7 +590,7 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
         report_fatal_error("__indirect_function_table symbol has wrong type");
       // Ensure that __indirect_function_table reaches the output.
       Sym->setNoStrip();
-      Asm.registerSymbol(*Sym);
+      Asm->registerSymbol(*Sym);
     }
   }
 

diff  --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp
index b3a8cf0d936f2..e2a386e5c62ec 100644
--- a/llvm/lib/MC/WinCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/WinCOFFObjectWriter.cpp
@@ -159,7 +159,7 @@ class llvm::WinCOFFWriter {
 
   void reset();
   void executePostLayoutBinding(MCAssembler &Asm);
-  void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
+  void recordRelocation(MCAssembler &Asm, const MCFragment &F,
                         const MCFixup &Fixup, MCValue Target,
                         uint64_t &FixedValue);
   uint64_t writeObject(MCAssembler &Asm);
@@ -834,8 +834,7 @@ void WinCOFFWriter::executePostLayoutBinding(MCAssembler &Asm) {
   assignSectionNumbers();
 }
 
-void WinCOFFWriter::recordRelocation(MCAssembler &Asm,
-                                     const MCFragment *Fragment,
+void WinCOFFWriter::recordRelocation(MCAssembler &Asm, const MCFragment &F,
                                      const MCFixup &Fixup, MCValue Target,
                                      uint64_t &FixedValue) {
   assert(Target.getAddSym() && "Relocation must reference a symbol!");
@@ -853,7 +852,7 @@ void WinCOFFWriter::recordRelocation(MCAssembler &Asm,
     return;
   }
 
-  MCSection *MCSec = Fragment->getParent();
+  MCSection *MCSec = F.getParent();
 
   // Mark this symbol as requiring an entry in the symbol table.
   assert(SectionMap.contains(MCSec) &&
@@ -873,8 +872,7 @@ void WinCOFFWriter::recordRelocation(MCAssembler &Asm,
     int64_t OffsetOfB = Asm.getSymbolOffset(*B);
 
     // Offset of the relocation in the section
-    int64_t OffsetOfRelocation =
-        Asm.getFragmentOffset(*Fragment) + Fixup.getOffset();
+    int64_t OffsetOfRelocation = Asm.getFragmentOffset(F) + Fixup.getOffset();
 
     FixedValue = (OffsetOfRelocation - OffsetOfB) + Target.getConstant();
   } else {
@@ -884,7 +882,7 @@ void WinCOFFWriter::recordRelocation(MCAssembler &Asm,
   COFFRelocation Reloc;
 
   Reloc.Data.SymbolTableIndex = 0;
-  Reloc.Data.VirtualAddress = Asm.getFragmentOffset(*Fragment);
+  Reloc.Data.VirtualAddress = Asm.getFragmentOffset(F);
 
   // Turn relocations for temporary symbols into section relocations.
   if (A.isTemporary() && !SymbolMap[&A]) {
@@ -1193,13 +1191,11 @@ void WinCOFFObjectWriter::executePostLayoutBinding() {
     DwoWriter->executePostLayoutBinding(*Asm);
 }
 
-void WinCOFFObjectWriter::recordRelocation(MCAssembler &Asm,
-                                           const MCFragment *Fragment,
+void WinCOFFObjectWriter::recordRelocation(const MCFragment &F,
                                            const MCFixup &Fixup, MCValue Target,
                                            uint64_t &FixedValue) {
-  assert(!isDwoSection(*Fragment->getParent()) &&
-         "No relocation in Dwo sections");
-  ObjWriter->recordRelocation(Asm, Fragment, Fixup, Target, FixedValue);
+  assert(!isDwoSection(*F.getParent()) && "No relocation in Dwo sections");
+  ObjWriter->recordRelocation(*Asm, F, Fixup, Target, FixedValue);
 }
 
 uint64_t WinCOFFObjectWriter::writeObject(MCAssembler &Asm) {

diff  --git a/llvm/lib/MC/XCOFFObjectWriter.cpp b/llvm/lib/MC/XCOFFObjectWriter.cpp
index b0d4bd9ede37d..f429db3706e39 100644
--- a/llvm/lib/MC/XCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/XCOFFObjectWriter.cpp
@@ -350,8 +350,8 @@ class XCOFFWriter final : public XCOFFObjectWriter {
 
   void executePostLayoutBinding() override;
 
-  void recordRelocation(MCAssembler &, const MCFragment *, const MCFixup &,
-                        MCValue, uint64_t &) override;
+  void recordRelocation(const MCFragment &, const MCFixup &, MCValue,
+                        uint64_t &) override;
 
   uint64_t writeObject(MCAssembler &) override;
 
@@ -656,9 +656,8 @@ void XCOFFWriter::executePostLayoutBinding() {
   assignAddressesAndIndices(*Asm);
 }
 
-void XCOFFWriter::recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
-                                   const MCFixup &Fixup, MCValue Target,
-                                   uint64_t &FixedValue) {
+void XCOFFWriter::recordRelocation(const MCFragment &F, const MCFixup &Fixup,
+                                   MCValue Target, uint64_t &FixedValue) {
   auto getIndex = [this](const MCSymbol *Sym,
                          const MCSectionXCOFF *ContainingCsect) {
     // If we could not find the symbol directly in SymbolIndexMap, this symbol
@@ -671,11 +670,11 @@ void XCOFFWriter::recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
   };
 
   auto getVirtualAddress =
-      [this, &Asm](const MCSymbol *Sym,
-                   const MCSectionXCOFF *ContainingSect) -> uint64_t {
+      [this](const MCSymbol *Sym,
+             const MCSectionXCOFF *ContainingSect) -> uint64_t {
     // A DWARF section.
     if (ContainingSect->isDwarfSect())
-      return Asm.getSymbolOffset(*Sym);
+      return Asm->getSymbolOffset(*Sym);
 
     // A csect.
     if (!Sym->isDefined())
@@ -683,12 +682,12 @@ void XCOFFWriter::recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
 
     // A label.
     assert(Sym->isDefined() && "not a valid object that has address!");
-    return SectionMap[ContainingSect]->Address + Asm.getSymbolOffset(*Sym);
+    return SectionMap[ContainingSect]->Address + Asm->getSymbolOffset(*Sym);
   };
 
   const MCSymbol *const SymA = Target.getAddSym();
 
-  MCAsmBackend &Backend = Asm.getBackend();
+  MCAsmBackend &Backend = Asm->getBackend();
   bool IsPCRel = Backend.getFixupKindInfo(Fixup.getKind()).Flags &
                  MCFixupKindInfo::FKF_IsPCRel;
 
@@ -701,11 +700,9 @@ void XCOFFWriter::recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
   assert(SectionMap.contains(SymASec) &&
          "Expected containing csect to exist in map.");
 
-  assert((Fixup.getOffset() <=
-          MaxRawDataSize - Asm.getFragmentOffset(*Fragment)) &&
+  assert((Fixup.getOffset() <= MaxRawDataSize - Asm->getFragmentOffset(F)) &&
          "Fragment offset + fixup offset is overflowed.");
-  uint32_t FixupOffsetInCsect =
-      Asm.getFragmentOffset(*Fragment) + Fixup.getOffset();
+  uint32_t FixupOffsetInCsect = Asm->getFragmentOffset(F) + Fixup.getOffset();
 
   const uint32_t Index = getIndex(SymA, SymASec);
   if (Type == XCOFF::RelocationType::R_POS ||
@@ -756,7 +753,7 @@ void XCOFFWriter::recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
       FixedValue = TOCEntryOffset;
     }
   } else if (Type == XCOFF::RelocationType::R_RBR) {
-    MCSectionXCOFF *ParentSec = cast<MCSectionXCOFF>(Fragment->getParent());
+    MCSectionXCOFF *ParentSec = cast<MCSectionXCOFF>(F.getParent());
     assert((SymASec->getMappingClass() == XCOFF::XMC_PR &&
             ParentSec->getMappingClass() == XCOFF::XMC_PR) &&
            "Only XMC_PR csect may have the R_RBR relocation.");
@@ -777,7 +774,7 @@ void XCOFFWriter::recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
   }
 
   XCOFFRelocation Reloc = {Index, FixupOffsetInCsect, SignAndSize, Type};
-  MCSectionXCOFF *RelocationSec = cast<MCSectionXCOFF>(Fragment->getParent());
+  MCSectionXCOFF *RelocationSec = cast<MCSectionXCOFF>(F.getParent());
   assert(SectionMap.contains(RelocationSec) &&
          "Expected containing csect to exist in map.");
   SectionMap[RelocationSec]->Relocations.push_back(Reloc);

diff  --git a/llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp b/llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp
index 9bed6930c2c4f..41341387b42c2 100644
--- a/llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp
+++ b/llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp
@@ -380,7 +380,7 @@ bool AVRAsmBackend::addReloc(const MCFragment &F, const MCFixup &Fixup,
       IsResolved = false;
   }
   if (!IsResolved)
-    Asm->getWriter().recordRelocation(*Asm, &F, Fixup, Target, FixedValue);
+    Asm->getWriter().recordRelocation(F, Fixup, Target, FixedValue);
   return IsResolved;
 }
 

diff  --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
index 8e01199da173b..7d529ed06f302 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
@@ -237,7 +237,7 @@ bool LoongArchAsmBackend::shouldInsertFixupForCodeAlign(MCAssembler &Asm,
   MCValue Value = MaxBytesToEmit >= InsertedNopBytes
                       ? MCValue::get(InsertedNopBytes)
                       : createExtendedValue();
-  Asm.getWriter().recordRelocation(Asm, &AF, Fixup, Value, FixedValue);
+  Asm.getWriter().recordRelocation(AF, Fixup, Value, FixedValue);
 
   return true;
 }
@@ -486,8 +486,8 @@ bool LoongArchAsmBackend::addReloc(const MCFragment &F, const MCFixup &Fixup,
     MCValue B = MCValue::get(Target.getSubSym());
     auto FA = MCFixup::create(Fixup.getOffset(), nullptr, std::get<0>(FK));
     auto FB = MCFixup::create(Fixup.getOffset(), nullptr, std::get<1>(FK));
-    Asm->getWriter().recordRelocation(*Asm, &F, FA, A, FixedValueA);
-    Asm->getWriter().recordRelocation(*Asm, &F, FB, B, FixedValueB);
+    Asm->getWriter().recordRelocation(F, FA, A, FixedValueA);
+    Asm->getWriter().recordRelocation(F, FB, B, FixedValueB);
     FixedValue = FixedValueA - FixedValueB;
     return false;
   }
@@ -497,7 +497,7 @@ bool LoongArchAsmBackend::addReloc(const MCFragment &F, const MCFixup &Fixup,
   // append a RELAX relocation.
   if (Fixup.isLinkerRelaxable()) {
     auto FA = MCFixup::create(Fixup.getOffset(), nullptr, ELF::R_LARCH_RELAX);
-    Asm->getWriter().recordRelocation(*Asm, &F, FA, MCValue::get(nullptr),
+    Asm->getWriter().recordRelocation(F, FA, MCValue::get(nullptr),
                                       FixedValueA);
   }
 

diff  --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
index b17de5520025d..9950c644f9365 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
@@ -649,8 +649,8 @@ bool RISCVAsmBackend::addReloc(const MCFragment &F, const MCFixup &Fixup,
     MCValue B = MCValue::get(Target.getSubSym());
     auto FA = MCFixup::create(Fixup.getOffset(), nullptr, TA);
     auto FB = MCFixup::create(Fixup.getOffset(), nullptr, TB);
-    Asm->getWriter().recordRelocation(*Asm, &F, FA, A, FixedValueA);
-    Asm->getWriter().recordRelocation(*Asm, &F, FB, B, FixedValueB);
+    Asm->getWriter().recordRelocation(F, FA, A, FixedValueA);
+    Asm->getWriter().recordRelocation(F, FB, B, FixedValueB);
     FixedValue = FixedValueA - FixedValueB;
     return false;
   }
@@ -666,7 +666,7 @@ bool RISCVAsmBackend::addReloc(const MCFragment &F, const MCFixup &Fixup,
 
   if (Fixup.isLinkerRelaxable()) {
     auto FA = MCFixup::create(Fixup.getOffset(), nullptr, ELF::R_RISCV_RELAX);
-    Asm->getWriter().recordRelocation(*Asm, &F, FA, MCValue::get(nullptr),
+    Asm->getWriter().recordRelocation(F, FA, MCValue::get(nullptr),
                                       FixedValueA);
   }
 
@@ -750,9 +750,7 @@ bool RISCVAsmBackend::shouldInsertFixupForCodeAlign(MCAssembler &Asm,
 
   uint64_t FixedValue = 0;
   MCValue NopBytes = MCValue::get(Count);
-
-  Asm.getWriter().recordRelocation(Asm, &AF, Fixup, NopBytes, FixedValue);
-
+  Asm.getWriter().recordRelocation(AF, Fixup, NopBytes, FixedValue);
   return true;
 }
 


        


More information about the llvm-commits mailing list