[llvm] 7687261 - ELFObjectWriter: Remove MCAssembler * arguments

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat May 24 20:01:04 PDT 2025


Author: Fangrui Song
Date: 2025-05-24T20:01:00-07:00
New Revision: 768726163730dda5bb490a5e88d4463ab5d3d231

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

LOG: ELFObjectWriter: Remove MCAssembler * arguments

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCELFObjectWriter.h
    llvm/lib/MC/ELFObjectWriter.cpp
    llvm/lib/MC/MCELFObjectTargetWriter.cpp
    llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCELFObjectWriter.h b/llvm/include/llvm/MC/MCELFObjectWriter.h
index 5a83beccffab9..1fa1afa5aaa1b 100644
--- a/llvm/include/llvm/MC/MCELFObjectWriter.h
+++ b/llvm/include/llvm/MC/MCELFObjectWriter.h
@@ -91,8 +91,7 @@ class MCELFObjectTargetWriter : public MCObjectTargetWriter {
   virtual bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
                                        unsigned Type) const;
 
-  virtual void sortRelocs(const MCAssembler &Asm,
-                          std::vector<ELFRelocationEntry> &Relocs);
+  virtual void sortRelocs(std::vector<ELFRelocationEntry> &Relocs);
 
   /// \name Accessors
   /// @{

diff  --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 4e73b11b97306..57418486c25f9 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -120,9 +120,8 @@ struct ELFWriter {
     DwoOnly,
   } Mode;
 
-  static uint64_t symbolValue(const MCAssembler &Asm, const MCSymbol &Sym);
-  static bool isInSymtab(const MCAssembler &Asm, const MCSymbolELF &Symbol,
-                         bool Used, bool Renamed);
+  uint64_t symbolValue(const MCSymbol &Sym);
+  bool isInSymtab(const MCSymbolELF &Symbol, bool Used, bool Renamed);
 
   /// Helper struct for containing some precomputed information on symbols.
   struct ELFSymbolData {
@@ -181,7 +180,7 @@ struct ELFWriter {
     W.write(Val);
   }
 
-  void writeHeader(const MCAssembler &Asm);
+  void writeHeader();
 
   void writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
                    ELFSymbolData &MSD);
@@ -193,16 +192,16 @@ struct ELFWriter {
   ///
   /// \param Asm - The assembler.
   /// \param RevGroupMap - Maps a signature symbol to the group section.
-  void computeSymbolTable(MCAssembler &Asm, const RevGroupMapTy &RevGroupMap);
+  void computeSymbolTable(const RevGroupMapTy &RevGroupMap);
 
   void writeAddrsigSection();
 
   MCSectionELF *createRelocationSection(MCContext &Ctx,
                                         const MCSectionELF &Sec);
 
-  void writeSectionHeaders(const MCAssembler &Asm);
+  void writeSectionHeaders();
 
-  void writeSectionData(const MCAssembler &Asm, MCSection &Sec);
+  void writeSectionData(MCSection &Sec);
 
   void writeSectionHeaderEntry(uint32_t Name, uint32_t Type, uint64_t Flags,
                                uint64_t Address, uint64_t Offset, uint64_t Size,
@@ -285,7 +284,7 @@ bool ELFWriter::is64Bit() const {
 }
 
 // Emit the ELF header.
-void ELFWriter::writeHeader(const MCAssembler &Asm) {
+void ELFWriter::writeHeader() {
   // ELF Header
   // ----------
   //
@@ -346,7 +345,7 @@ void ELFWriter::writeHeader(const MCAssembler &Asm) {
   W.write<uint16_t>(StringTableIndex);
 }
 
-uint64_t ELFWriter::symbolValue(const MCAssembler &Asm, const MCSymbol &Sym) {
+uint64_t ELFWriter::symbolValue(const MCSymbol &Sym) {
   if (Sym.isCommon())
     return Sym.getCommonAlignment()->value();
 
@@ -433,7 +432,7 @@ void ELFWriter::writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
   uint8_t Visibility = Symbol.getVisibility();
   uint8_t Other = Symbol.getOther() | Visibility;
 
-  uint64_t Value = symbolValue(Asm, *MSD.Symbol);
+  uint64_t Value = symbolValue(*MSD.Symbol);
   uint64_t Size = 0;
 
   const MCExpr *ESize = MSD.Symbol->getSize();
@@ -470,8 +469,7 @@ void ELFWriter::writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
                      IsReserved);
 }
 
-bool ELFWriter::isInSymtab(const MCAssembler &Asm, const MCSymbolELF &Symbol,
-                           bool Used, bool Renamed) {
+bool ELFWriter::isInSymtab(const MCSymbolELF &Symbol, bool Used, bool Renamed) {
   if (Symbol.isVariable()) {
     const MCExpr *Expr = Symbol.getVariableValue();
     // Target Expressions that are always inlined do not appear in the symtab
@@ -505,8 +503,7 @@ bool ELFWriter::isInSymtab(const MCAssembler &Asm, const MCSymbolELF &Symbol,
   return true;
 }
 
-void ELFWriter::computeSymbolTable(MCAssembler &Asm,
-                                   const RevGroupMapTy &RevGroupMap) {
+void ELFWriter::computeSymbolTable(const RevGroupMapTy &RevGroupMap) {
   MCContext &Ctx = Asm.getContext();
   SymbolTableWriter Writer(*this, is64Bit());
 
@@ -537,7 +534,7 @@ void ELFWriter::computeSymbolTable(MCAssembler &Asm,
     bool WeakrefUsed = Symbol.isWeakrefUsedInReloc();
     bool isSignature = Symbol.isSignature();
 
-    if (!isInSymtab(Asm, Symbol, Used || WeakrefUsed || isSignature,
+    if (!isInSymtab(Symbol, Used || WeakrefUsed || isSignature,
                     OWriter.Renames.count(&Symbol)))
       continue;
 
@@ -747,7 +744,7 @@ bool ELFWriter::maybeWriteCompression(
   return true;
 }
 
-void ELFWriter::writeSectionData(const MCAssembler &Asm, MCSection &Sec) {
+void ELFWriter::writeSectionData(MCSection &Sec) {
   MCSectionELF &Section = static_cast<MCSectionELF &>(Sec);
   StringRef SectionName = Section.getName();
   auto &Ctx = Asm.getContext();
@@ -828,7 +825,7 @@ void ELFWriter::writeRelocations(const MCSectionELF &Sec) {
   const bool Rela = OWriter.usesRela(TO, Sec);
 
   // Sort the relocation entries. MIPS needs this.
-  OWriter.TargetObjectWriter->sortRelocs(Asm, Relocs);
+  OWriter.TargetObjectWriter->sortRelocs(Relocs);
 
   if (OWriter.TargetObjectWriter->getEMachine() == ELF::EM_MIPS) {
     for (const ELFRelocationEntry &Entry : Relocs) {
@@ -946,7 +943,7 @@ void ELFWriter::writeSectionHeader(uint32_t GroupSymbolIndex, uint64_t Offset,
                           Section.getEntrySize());
 }
 
-void ELFWriter::writeSectionHeaders(const MCAssembler &Asm) {
+void ELFWriter::writeSectionHeaders() {
   uint64_t Start = W.OS.tell();
   const unsigned NumSections = SectionTable.size();
 
@@ -1028,7 +1025,7 @@ uint64_t ELFWriter::writeObject() {
   RevGroupMapTy RevGroupMap;
 
   // Write out the ELF header ...
-  writeHeader(Asm);
+  writeHeader();
 
   stats::ELFHeaderBytes += W.OS.tell() - StartOffset;
 
@@ -1048,7 +1045,7 @@ uint64_t ELFWriter::writeObject() {
     const uint64_t SecStart = align(Section.getAlign());
 
     const MCSymbolELF *SignatureSymbol = Section.getGroup();
-    writeSectionData(Asm, Section);
+    writeSectionData(Section);
 
     uint64_t SecEnd = W.OS.tell();
     Section.setOffsets(SecStart, SecEnd);
@@ -1108,7 +1105,7 @@ uint64_t ELFWriter::writeObject() {
     }
 
     // Compute symbol table information.
-    computeSymbolTable(Asm, RevGroupMap);
+    computeSymbolTable(RevGroupMap);
 
     for (MCSectionELF *RelSection : Relocations) {
       // Remember the offset into the file for this section.
@@ -1137,7 +1134,7 @@ uint64_t ELFWriter::writeObject() {
   const uint64_t SectionHeaderOffset = align(is64Bit() ? Align(8) : Align(4));
 
   // ... then the section header table ...
-  writeSectionHeaders(Asm);
+  writeSectionHeaders();
 
   uint16_t NumSections = support::endian::byte_swap<uint16_t>(
       (SectionTable.size() + 1 >= ELF::SHN_LORESERVE) ? (uint16_t)ELF::SHN_UNDEF

diff  --git a/llvm/lib/MC/MCELFObjectTargetWriter.cpp b/llvm/lib/MC/MCELFObjectTargetWriter.cpp
index 49cca57d3aaa3..39894d3736f14 100644
--- a/llvm/lib/MC/MCELFObjectTargetWriter.cpp
+++ b/llvm/lib/MC/MCELFObjectTargetWriter.cpp
@@ -23,7 +23,5 @@ bool MCELFObjectTargetWriter::needsRelocateWithSymbol(const MCValue &,
   return false;
 }
 
-void
-MCELFObjectTargetWriter::sortRelocs(const MCAssembler &Asm,
-                                    std::vector<ELFRelocationEntry> &Relocs) {
-}
+void MCELFObjectTargetWriter::sortRelocs(
+    std::vector<ELFRelocationEntry> &Relocs) {}

diff  --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
index 83073e4243414..9e2646a457b56 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
@@ -52,8 +52,7 @@ class MipsELFObjectWriter : public MCELFObjectTargetWriter {
                         const MCFixup &Fixup, bool IsPCRel) const override;
   bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
                                unsigned Type) const override;
-  void sortRelocs(const MCAssembler &Asm,
-                  std::vector<ELFRelocationEntry> &Relocs) override;
+  void sortRelocs(std::vector<ELFRelocationEntry> &Relocs) override;
 };
 
 /// The possible results of the Predicate function used by find_best.
@@ -381,8 +380,7 @@ unsigned MipsELFObjectWriter::getRelocType(MCContext &Ctx,
 /// It should also be noted that this function is not affected by whether
 /// the symbol was kept or rewritten into a section-relative equivalent. We
 /// always match using the expressions from the source.
-void MipsELFObjectWriter::sortRelocs(const MCAssembler &Asm,
-                                     std::vector<ELFRelocationEntry> &Relocs) {
+void MipsELFObjectWriter::sortRelocs(std::vector<ELFRelocationEntry> &Relocs) {
   // We do not need to sort the relocation table for RELA relocations which
   // N32/N64 uses as the relocation addend contains the value we require,
   // rather than it being split across a pair of relocations.


        


More information about the llvm-commits mailing list