[llvm] d78d030 - [MC] Export llvm::XCOFFObjectwriter and access it from MCXCOFFStreamer

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 26 12:26:16 PDT 2024


Author: Fangrui Song
Date: 2024-10-26T12:26:11-07:00
New Revision: d78d030b31bb3bde822115fd9d26ab887f890203

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

LOG: [MC] Export llvm::XCOFFObjectwriter and access it from MCXCOFFStreamer

Similar to commit 9539a7796094ff5fb59d9c685140ea2e214b945c for
WinCOFFObjectWriter.

Close #100412

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCXCOFFObjectWriter.h
    llvm/include/llvm/MC/MCXCOFFStreamer.h
    llvm/lib/MC/MCXCOFFStreamer.cpp
    llvm/lib/MC/XCOFFObjectWriter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCXCOFFObjectWriter.h b/llvm/include/llvm/MC/MCXCOFFObjectWriter.h
index c0e32a70172d88..968d938a654981 100644
--- a/llvm/include/llvm/MC/MCXCOFFObjectWriter.h
+++ b/llvm/include/llvm/MC/MCXCOFFObjectWriter.h
@@ -39,19 +39,18 @@ class MCXCOFFObjectTargetWriter : public MCObjectTargetWriter {
   bool Is64Bit;
 };
 
+class XCOFFObjectWriter : public MCObjectWriter {
+public:
+  virtual void addExceptionEntry(const MCSymbol *Symbol, const MCSymbol *Trap,
+                                 unsigned LanguageCode, unsigned ReasonCode,
+                                 unsigned FunctionSize, bool hasDebug) = 0;
+  virtual void addCInfoSymEntry(StringRef Name, StringRef Metadata) = 0;
+};
+
 std::unique_ptr<MCObjectWriter>
 createXCOFFObjectWriter(std::unique_ptr<MCXCOFFObjectTargetWriter> MOTW,
                         raw_pwrite_stream &OS);
 
-namespace XCOFF {
-void addExceptionEntry(MCObjectWriter &Writer, const MCSymbol *Symbol,
-                       const MCSymbol *Trap, unsigned LanguageCode,
-                       unsigned ReasonCode, unsigned FunctionSize,
-                       bool hasDebug);
-void addCInfoSymEntry(MCObjectWriter &Writer, StringRef Name,
-                      StringRef Metadata);
-} // namespace XCOFF
-
 } // end namespace llvm
 
 #endif // LLVM_MC_MCXCOFFOBJECTWRITER_H

diff  --git a/llvm/include/llvm/MC/MCXCOFFStreamer.h b/llvm/include/llvm/MC/MCXCOFFStreamer.h
index 8cae64fa33be05..3c7abfea85ecf5 100644
--- a/llvm/include/llvm/MC/MCXCOFFStreamer.h
+++ b/llvm/include/llvm/MC/MCXCOFFStreamer.h
@@ -12,6 +12,7 @@
 #include "llvm/MC/MCObjectStreamer.h"
 
 namespace llvm {
+class XCOFFObjectWriter;
 
 class MCXCOFFStreamer : public MCObjectStreamer {
 public:
@@ -19,6 +20,8 @@ class MCXCOFFStreamer : public MCObjectStreamer {
                   std::unique_ptr<MCObjectWriter> OW,
                   std::unique_ptr<MCCodeEmitter> Emitter);
 
+  XCOFFObjectWriter &getWriter();
+
   bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
   void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
                         Align ByteAlignment) override;

diff  --git a/llvm/lib/MC/MCXCOFFStreamer.cpp b/llvm/lib/MC/MCXCOFFStreamer.cpp
index 94aa1ebc8f9e11..f5b83f29352ca7 100644
--- a/llvm/lib/MC/MCXCOFFStreamer.cpp
+++ b/llvm/lib/MC/MCXCOFFStreamer.cpp
@@ -32,6 +32,10 @@ MCXCOFFStreamer::MCXCOFFStreamer(MCContext &Context,
     : MCObjectStreamer(Context, std::move(MAB), std::move(OW),
                        std::move(Emitter)) {}
 
+XCOFFObjectWriter &MCXCOFFStreamer::getWriter() {
+  return static_cast<XCOFFObjectWriter &>(getAssembler().getWriter());
+}
+
 bool MCXCOFFStreamer::emitSymbolAttribute(MCSymbol *Sym,
                                           MCSymbolAttr Attribute) {
   auto *Symbol = cast<MCSymbolXCOFF>(Sym);
@@ -109,14 +113,12 @@ void MCXCOFFStreamer::emitXCOFFExceptDirective(const MCSymbol *Symbol,
                                                unsigned Lang, unsigned Reason,
                                                unsigned FunctionSize,
                                                bool hasDebug) {
-  // TODO: Export XCOFFObjectWriter to llvm/MC/MCXCOFFObjectWriter.h and access
-  // it from MCXCOFFStreamer.
-  XCOFF::addExceptionEntry(getAssembler().getWriter(), Symbol, Trap, Lang,
-                           Reason, FunctionSize, hasDebug);
+  getWriter().addExceptionEntry(Symbol, Trap, Lang, Reason, FunctionSize,
+                                hasDebug);
 }
 
 void MCXCOFFStreamer::emitXCOFFCInfoSym(StringRef Name, StringRef Metadata) {
-  XCOFF::addCInfoSymEntry(getAssembler().getWriter(), Name, Metadata);
+  getWriter().addCInfoSymEntry(Name, Metadata);
 }
 
 void MCXCOFFStreamer::emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,

diff  --git a/llvm/lib/MC/XCOFFObjectWriter.cpp b/llvm/lib/MC/XCOFFObjectWriter.cpp
index c7f29c73eaac09..5d8f3dbdaadad5 100644
--- a/llvm/lib/MC/XCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/XCOFFObjectWriter.cpp
@@ -290,8 +290,7 @@ struct CInfoSymSectionEntry : public SectionEntry {
   }
 };
 
-class XCOFFObjectWriter : public MCObjectWriter {
-
+class XCOFFWriter final : public XCOFFObjectWriter {
   uint32_t SymbolTableEntryCount = 0;
   uint64_t SymbolTableOffset = 0;
   uint16_t SectionCount = 0;
@@ -433,8 +432,8 @@ class XCOFFObjectWriter : public MCObjectWriter {
   }
 
 public:
-  XCOFFObjectWriter(std::unique_ptr<MCXCOFFObjectTargetWriter> MOTW,
-                    raw_pwrite_stream &OS);
+  XCOFFWriter(std::unique_ptr<MCXCOFFObjectTargetWriter> MOTW,
+              raw_pwrite_stream &OS);
 
   void writeWord(uint64_t Word) {
     is64Bit() ? W.write<uint64_t>(Word) : W.write<uint32_t>(Word);
@@ -442,12 +441,12 @@ class XCOFFObjectWriter : public MCObjectWriter {
 
   void addExceptionEntry(const MCSymbol *Symbol, const MCSymbol *Trap,
                          unsigned LanguageCode, unsigned ReasonCode,
-                         unsigned FunctionSize, bool hasDebug);
-  void addCInfoSymEntry(StringRef Name, StringRef Metadata);
+                         unsigned FunctionSize, bool hasDebug) override;
+  void addCInfoSymEntry(StringRef Name, StringRef Metadata) override;
 };
 
-XCOFFObjectWriter::XCOFFObjectWriter(
-    std::unique_ptr<MCXCOFFObjectTargetWriter> MOTW, raw_pwrite_stream &OS)
+XCOFFWriter::XCOFFWriter(std::unique_ptr<MCXCOFFObjectTargetWriter> MOTW,
+                         raw_pwrite_stream &OS)
     : W(OS, llvm::endianness::big), TargetObjectWriter(std::move(MOTW)),
       Strings(StringTableBuilder::XCOFF),
       Text(".text", XCOFF::STYP_TEXT, /* IsVirtual */ false,
@@ -463,7 +462,7 @@ XCOFFObjectWriter::XCOFFObjectWriter(
       ExceptionSection(".except", XCOFF::STYP_EXCEPT),
       CInfoSymSection(".info", XCOFF::STYP_INFO) {}
 
-void XCOFFObjectWriter::reset() {
+void XCOFFWriter::reset() {
   // Clear the mappings we created.
   SymbolIndexMap.clear();
   SectionMap.clear();
@@ -479,7 +478,7 @@ void XCOFFObjectWriter::reset() {
   ExceptionSection.reset();
   CInfoSymSection.reset();
 
-  // Reset states in XCOFFObjectWriter.
+  // Reset states in XCOFFWriter.
   SymbolTableEntryCount = 0;
   SymbolTableOffset = 0;
   SectionCount = 0;
@@ -489,7 +488,7 @@ void XCOFFObjectWriter::reset() {
   MCObjectWriter::reset();
 }
 
-CsectGroup &XCOFFObjectWriter::getCsectGroup(const MCSectionXCOFF *MCSec) {
+CsectGroup &XCOFFWriter::getCsectGroup(const MCSectionXCOFF *MCSec) {
   switch (MCSec->getMappingClass()) {
   case XCOFF::XMC_PR:
     assert(XCOFF::XTY_SD == MCSec->getCSectType() &&
@@ -556,7 +555,7 @@ static MCSectionXCOFF *getContainingCsect(const MCSymbolXCOFF *XSym) {
   return XSym->getRepresentedCsect();
 }
 
-void XCOFFObjectWriter::executePostLayoutBinding(MCAssembler &Asm) {
+void XCOFFWriter::executePostLayoutBinding(MCAssembler &Asm) {
   for (const auto &S : Asm) {
     const auto *MCSec = cast<const MCSectionXCOFF>(&S);
     assert(!SectionMap.contains(MCSec) && "Cannot add a section twice.");
@@ -657,10 +656,9 @@ void XCOFFObjectWriter::executePostLayoutBinding(MCAssembler &Asm) {
   assignAddressesAndIndices(Asm);
 }
 
-void XCOFFObjectWriter::recordRelocation(MCAssembler &Asm,
-                                         const MCFragment *Fragment,
-                                         const MCFixup &Fixup, MCValue Target,
-                                         uint64_t &FixedValue) {
+void XCOFFWriter::recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
+                                   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
@@ -812,7 +810,7 @@ void XCOFFObjectWriter::recordRelocation(MCAssembler &Asm,
   FixedValue -= getVirtualAddress(SymB, SymBSec);
 }
 
-void XCOFFObjectWriter::writeSections(const MCAssembler &Asm) {
+void XCOFFWriter::writeSections(const MCAssembler &Asm) {
   uint64_t CurrentAddressLocation = 0;
   for (const auto *Section : Sections)
     writeSectionForControlSectionEntry(Asm, *Section, CurrentAddressLocation);
@@ -824,7 +822,7 @@ void XCOFFObjectWriter::writeSections(const MCAssembler &Asm) {
                                       CurrentAddressLocation);
 }
 
-uint64_t XCOFFObjectWriter::writeObject(MCAssembler &Asm) {
+uint64_t XCOFFWriter::writeObject(MCAssembler &Asm) {
   // We always emit a timestamp of 0 for reproducibility, so ensure incremental
   // linking is not enabled, in case, like with Windows COFF, such a timestamp
   // is incompatible with incremental linking of XCOFF.
@@ -844,11 +842,11 @@ uint64_t XCOFFObjectWriter::writeObject(MCAssembler &Asm) {
   return W.OS.tell() - StartOffset;
 }
 
-bool XCOFFObjectWriter::nameShouldBeInStringTable(const StringRef &SymbolName) {
+bool XCOFFWriter::nameShouldBeInStringTable(const StringRef &SymbolName) {
   return SymbolName.size() > XCOFF::NameSize || is64Bit();
 }
 
-void XCOFFObjectWriter::writeSymbolName(const StringRef &SymbolName) {
+void XCOFFWriter::writeSymbolName(const StringRef &SymbolName) {
   // Magic, Offset or SymbolName.
   if (nameShouldBeInStringTable(SymbolName)) {
     W.write<int32_t>(0);
@@ -861,11 +859,10 @@ void XCOFFObjectWriter::writeSymbolName(const StringRef &SymbolName) {
   }
 }
 
-void XCOFFObjectWriter::writeSymbolEntry(StringRef SymbolName, uint64_t Value,
-                                         int16_t SectionNumber,
-                                         uint16_t SymbolType,
-                                         uint8_t StorageClass,
-                                         uint8_t NumberOfAuxEntries) {
+void XCOFFWriter::writeSymbolEntry(StringRef SymbolName, uint64_t Value,
+                                   int16_t SectionNumber, uint16_t SymbolType,
+                                   uint8_t StorageClass,
+                                   uint8_t NumberOfAuxEntries) {
   if (is64Bit()) {
     W.write<uint64_t>(Value);
     W.write<uint32_t>(Strings.getOffset(SymbolName));
@@ -879,9 +876,9 @@ void XCOFFObjectWriter::writeSymbolEntry(StringRef SymbolName, uint64_t Value,
   W.write<uint8_t>(NumberOfAuxEntries);
 }
 
-void XCOFFObjectWriter::writeSymbolAuxCsectEntry(uint64_t SectionOrLength,
-                                                 uint8_t SymbolAlignmentAndType,
-                                                 uint8_t StorageMappingClass) {
+void XCOFFWriter::writeSymbolAuxCsectEntry(uint64_t SectionOrLength,
+                                           uint8_t SymbolAlignmentAndType,
+                                           uint8_t StorageMappingClass) {
   W.write<uint32_t>(is64Bit() ? Lo_32(SectionOrLength) : SectionOrLength);
   W.write<uint32_t>(0); // ParameterHashIndex
   W.write<uint16_t>(0); // TypeChkSectNum
@@ -897,12 +894,12 @@ void XCOFFObjectWriter::writeSymbolAuxCsectEntry(uint64_t SectionOrLength,
   }
 }
 
-bool XCOFFObjectWriter::auxFileSymNameShouldBeInStringTable(
+bool XCOFFWriter::auxFileSymNameShouldBeInStringTable(
     const StringRef &SymbolName) {
   return SymbolName.size() > XCOFF::AuxFileEntNameSize;
 }
 
-void XCOFFObjectWriter::writeAuxFileSymName(const StringRef &SymbolName) {
+void XCOFFWriter::writeAuxFileSymName(const StringRef &SymbolName) {
   // Magic, Offset or SymbolName.
   if (auxFileSymNameShouldBeInStringTable(SymbolName)) {
     W.write<int32_t>(0);
@@ -916,8 +913,7 @@ void XCOFFObjectWriter::writeAuxFileSymName(const StringRef &SymbolName) {
   }
 }
 
-void XCOFFObjectWriter::writeSymbolAuxFileEntry(StringRef &Name,
-                                                uint8_t ftype) {
+void XCOFFWriter::writeSymbolAuxFileEntry(StringRef &Name, uint8_t ftype) {
   writeAuxFileSymName(Name);
   W.write<uint8_t>(ftype);
   W.OS.write_zeros(2);
@@ -927,8 +923,8 @@ void XCOFFObjectWriter::writeSymbolAuxFileEntry(StringRef &Name,
     W.OS.write_zeros(1);
 }
 
-void XCOFFObjectWriter::writeSymbolAuxDwarfEntry(
-    uint64_t LengthOfSectionPortion, uint64_t NumberOfRelocEnt) {
+void XCOFFWriter::writeSymbolAuxDwarfEntry(uint64_t LengthOfSectionPortion,
+                                           uint64_t NumberOfRelocEnt) {
   writeWord(LengthOfSectionPortion);
   if (!is64Bit())
     W.OS.write_zeros(4); // Reserved
@@ -941,7 +937,7 @@ void XCOFFObjectWriter::writeSymbolAuxDwarfEntry(
   }
 }
 
-void XCOFFObjectWriter::writeSymbolEntryForCsectMemberLabel(
+void XCOFFWriter::writeSymbolEntryForCsectMemberLabel(
     const Symbol &SymbolRef, const XCOFFSection &CSectionRef,
     int16_t SectionIndex, uint64_t SymbolOffset) {
   assert(SymbolOffset <= MaxRawDataSize - CSectionRef.Address &&
@@ -986,7 +982,7 @@ void XCOFFObjectWriter::writeSymbolEntryForCsectMemberLabel(
                            CSectionRef.MCSec->getMappingClass());
 }
 
-void XCOFFObjectWriter::writeSymbolEntryForDwarfSection(
+void XCOFFWriter::writeSymbolEntryForDwarfSection(
     const XCOFFSection &DwarfSectionRef, int16_t SectionIndex) {
   assert(DwarfSectionRef.MCSec->isDwarfSect() && "Not a DWARF section!");
 
@@ -996,7 +992,7 @@ void XCOFFObjectWriter::writeSymbolEntryForDwarfSection(
   writeSymbolAuxDwarfEntry(DwarfSectionRef.Size);
 }
 
-void XCOFFObjectWriter::writeSymbolEntryForControlSection(
+void XCOFFWriter::writeSymbolEntryForControlSection(
     const XCOFFSection &CSectionRef, int16_t SectionIndex,
     XCOFF::StorageClass StorageClass) {
   writeSymbolEntry(CSectionRef.getSymbolTableName(), CSectionRef.Address,
@@ -1006,10 +1002,10 @@ void XCOFFObjectWriter::writeSymbolEntryForControlSection(
                            CSectionRef.MCSec->getMappingClass());
 }
 
-void XCOFFObjectWriter::writeSymbolAuxFunctionEntry(uint32_t EntryOffset,
-                                                    uint32_t FunctionSize,
-                                                    uint64_t LineNumberPointer,
-                                                    uint32_t EndIndex) {
+void XCOFFWriter::writeSymbolAuxFunctionEntry(uint32_t EntryOffset,
+                                              uint32_t FunctionSize,
+                                              uint64_t LineNumberPointer,
+                                              uint32_t EndIndex) {
   if (is64Bit())
     writeWord(LineNumberPointer);
   else
@@ -1026,9 +1022,9 @@ void XCOFFObjectWriter::writeSymbolAuxFunctionEntry(uint32_t EntryOffset,
   }
 }
 
-void XCOFFObjectWriter::writeSymbolAuxExceptionEntry(uint64_t EntryOffset,
-                                                     uint32_t FunctionSize,
-                                                     uint32_t EndIndex) {
+void XCOFFWriter::writeSymbolAuxExceptionEntry(uint64_t EntryOffset,
+                                               uint32_t FunctionSize,
+                                               uint32_t EndIndex) {
   assert(is64Bit() && "Exception auxilliary entries are 64-bit only.");
   W.write<uint64_t>(EntryOffset);
   W.write<uint32_t>(FunctionSize);
@@ -1037,7 +1033,7 @@ void XCOFFObjectWriter::writeSymbolAuxExceptionEntry(uint64_t EntryOffset,
   W.write<uint8_t>(XCOFF::AUX_EXCEPT);
 }
 
-void XCOFFObjectWriter::writeFileHeader() {
+void XCOFFWriter::writeFileHeader() {
   W.write<uint16_t>(is64Bit() ? XCOFF::XCOFF64 : XCOFF::XCOFF32);
   W.write<uint16_t>(SectionCount);
   W.write<int32_t>(0); // TimeStamp
@@ -1053,7 +1049,7 @@ void XCOFFObjectWriter::writeFileHeader() {
   }
 }
 
-void XCOFFObjectWriter::writeAuxFileHeader() {
+void XCOFFWriter::writeAuxFileHeader() {
   if (!auxiliaryHeaderSize())
     return;
   W.write<uint16_t>(0); // Magic
@@ -1069,7 +1065,7 @@ void XCOFFObjectWriter::writeAuxFileHeader() {
   W.write<uint32_t>(Sections[1]->Address); // DataStartAddr
 }
 
-void XCOFFObjectWriter::writeSectionHeader(const SectionEntry *Sec) {
+void XCOFFWriter::writeSectionHeader(const SectionEntry *Sec) {
   bool IsDwarf = (Sec->Flags & XCOFF::STYP_DWARF) != 0;
   bool IsOvrflo = (Sec->Flags & XCOFF::STYP_OVRFLO) != 0;
   // Nothing to write for this Section.
@@ -1109,7 +1105,7 @@ void XCOFFObjectWriter::writeSectionHeader(const SectionEntry *Sec) {
   }
 }
 
-void XCOFFObjectWriter::writeSectionHeaderTable() {
+void XCOFFWriter::writeSectionHeaderTable() {
   for (const auto *CsectSec : Sections)
     writeSectionHeader(CsectSec);
   for (const auto &DwarfSec : DwarfSections)
@@ -1122,8 +1118,8 @@ void XCOFFObjectWriter::writeSectionHeaderTable() {
     writeSectionHeader(&CInfoSymSection);
 }
 
-void XCOFFObjectWriter::writeRelocation(XCOFFRelocation Reloc,
-                                        const XCOFFSection &Section) {
+void XCOFFWriter::writeRelocation(XCOFFRelocation Reloc,
+                                  const XCOFFSection &Section) {
   if (Section.MCSec->isCsect())
     writeWord(Section.Address + Reloc.FixupOffsetInCsect);
   else {
@@ -1136,7 +1132,7 @@ void XCOFFObjectWriter::writeRelocation(XCOFFRelocation Reloc,
   W.write<uint8_t>(Reloc.Type);
 }
 
-void XCOFFObjectWriter::writeRelocations() {
+void XCOFFWriter::writeRelocations() {
   for (const auto *Section : Sections) {
     if (Section->Index == SectionEntry::UninitializedIndex)
       // Nothing to write for this Section.
@@ -1158,7 +1154,7 @@ void XCOFFObjectWriter::writeRelocations() {
       writeRelocation(Reloc, *DwarfSection.DwarfSect);
 }
 
-void XCOFFObjectWriter::writeSymbolTable(MCAssembler &Asm) {
+void XCOFFWriter::writeSymbolTable(MCAssembler &Asm) {
   // Write C_FILE symbols.
   StringRef Vers = CompilerVersion;
 
@@ -1239,8 +1235,7 @@ void XCOFFObjectWriter::writeSymbolTable(MCAssembler &Asm) {
                                     DwarfSection.Index);
 }
 
-void XCOFFObjectWriter::finalizeRelocationInfo(SectionEntry *Sec,
-                                               uint64_t RelCount) {
+void XCOFFWriter::finalizeRelocationInfo(SectionEntry *Sec, uint64_t RelCount) {
   // Handles relocation field overflows in an XCOFF32 file. An XCOFF64 file
   // may not contain an overflow section header.
   if (!is64Bit() && (RelCount >= static_cast<uint32_t>(XCOFF::RelocOverflow))) {
@@ -1265,8 +1260,8 @@ void XCOFFObjectWriter::finalizeRelocationInfo(SectionEntry *Sec,
   }
 }
 
-void XCOFFObjectWriter::calcOffsetToRelocations(SectionEntry *Sec,
-                                                uint64_t &RawPointer) {
+void XCOFFWriter::calcOffsetToRelocations(SectionEntry *Sec,
+                                          uint64_t &RawPointer) {
   if (!Sec->RelocationCount)
     return;
 
@@ -1297,7 +1292,7 @@ void XCOFFObjectWriter::calcOffsetToRelocations(SectionEntry *Sec,
     report_fatal_error("Relocation data overflowed this object file.");
 }
 
-void XCOFFObjectWriter::finalizeSectionInfo() {
+void XCOFFWriter::finalizeSectionInfo() {
   for (auto *Section : Sections) {
     if (Section->Index == SectionEntry::UninitializedIndex)
       // Nothing to record for this Section.
@@ -1361,9 +1356,10 @@ void XCOFFObjectWriter::finalizeSectionInfo() {
     SymbolTableOffset = RawPointer;
 }
 
-void XCOFFObjectWriter::addExceptionEntry(
-    const MCSymbol *Symbol, const MCSymbol *Trap, unsigned LanguageCode,
-    unsigned ReasonCode, unsigned FunctionSize, bool hasDebug) {
+void XCOFFWriter::addExceptionEntry(const MCSymbol *Symbol,
+                                    const MCSymbol *Trap, unsigned LanguageCode,
+                                    unsigned ReasonCode, unsigned FunctionSize,
+                                    bool hasDebug) {
   // If a module had debug info, debugging is enabled and XCOFF emits the
   // exception auxilliary entry.
   if (hasDebug)
@@ -1383,7 +1379,7 @@ void XCOFFObjectWriter::addExceptionEntry(
       std::pair<const StringRef, ExceptionInfo>(Symbol->getName(), NewEntry));
 }
 
-unsigned XCOFFObjectWriter::getExceptionSectionSize() {
+unsigned XCOFFWriter::getExceptionSectionSize() {
   unsigned EntryNum = 0;
 
   for (const auto &TableEntry : ExceptionSection.ExceptionTable)
@@ -1395,7 +1391,7 @@ unsigned XCOFFObjectWriter::getExceptionSectionSize() {
                                : XCOFF::ExceptionSectionEntrySize32);
 }
 
-unsigned XCOFFObjectWriter::getExceptionOffset(const MCSymbol *Symbol) {
+unsigned XCOFFWriter::getExceptionOffset(const MCSymbol *Symbol) {
   unsigned EntryNum = 0;
   for (const auto &TableEntry : ExceptionSection.ExceptionTable) {
     if (Symbol == TableEntry.second.FunctionSymbol)
@@ -1406,13 +1402,13 @@ unsigned XCOFFObjectWriter::getExceptionOffset(const MCSymbol *Symbol) {
                                : XCOFF::ExceptionSectionEntrySize32);
 }
 
-void XCOFFObjectWriter::addCInfoSymEntry(StringRef Name, StringRef Metadata) {
+void XCOFFWriter::addCInfoSymEntry(StringRef Name, StringRef Metadata) {
   assert(!CInfoSymSection.Entry && "Multiple entries are not supported");
   CInfoSymSection.addEntry(
       std::make_unique<CInfoSymInfo>(Name.str(), Metadata.str()));
 }
 
-void XCOFFObjectWriter::assignAddressesAndIndices(MCAssembler &Asm) {
+void XCOFFWriter::assignAddressesAndIndices(MCAssembler &Asm) {
   // The symbol table starts with all the C_FILE symbols. Each C_FILE symbol
   // requires 1 or 2 auxiliary entries.
   uint32_t SymbolTableIndex =
@@ -1588,7 +1584,7 @@ void XCOFFObjectWriter::assignAddressesAndIndices(MCAssembler &Asm) {
   SymbolTableEntryCount = SymbolTableIndex;
 }
 
-void XCOFFObjectWriter::writeSectionForControlSectionEntry(
+void XCOFFWriter::writeSectionForControlSectionEntry(
     const MCAssembler &Asm, const CsectSectionEntry &CsectEntry,
     uint64_t &CurrentAddressLocation) {
   // Nothing to write for this Section.
@@ -1635,7 +1631,7 @@ void XCOFFObjectWriter::writeSectionForControlSectionEntry(
   }
 }
 
-void XCOFFObjectWriter::writeSectionForDwarfSectionEntry(
+void XCOFFWriter::writeSectionForDwarfSectionEntry(
     const MCAssembler &Asm, const DwarfSectionEntry &DwarfEntry,
     uint64_t &CurrentAddressLocation) {
   // There could be a gap (without corresponding zero padding) between
@@ -1663,7 +1659,7 @@ void XCOFFObjectWriter::writeSectionForDwarfSectionEntry(
   CurrentAddressLocation += TailPaddingSize;
 }
 
-void XCOFFObjectWriter::writeSectionForExceptionSectionEntry(
+void XCOFFWriter::writeSectionForExceptionSectionEntry(
     const MCAssembler &Asm, ExceptionSectionEntry &ExceptionEntry,
     uint64_t &CurrentAddressLocation) {
   for (const auto &TableEntry : ExceptionEntry.ExceptionTable) {
@@ -1685,7 +1681,7 @@ void XCOFFObjectWriter::writeSectionForExceptionSectionEntry(
   CurrentAddressLocation += getExceptionSectionSize();
 }
 
-void XCOFFObjectWriter::writeSectionForCInfoSymSectionEntry(
+void XCOFFWriter::writeSectionForCInfoSymSectionEntry(
     const MCAssembler &Asm, CInfoSymSectionEntry &CInfoSymEntry,
     uint64_t &CurrentAddressLocation) {
   if (!CInfoSymSection.Entry)
@@ -1737,20 +1733,5 @@ uint8_t getEncodedType(const MCSectionXCOFF *Sec) {
 std::unique_ptr<MCObjectWriter>
 llvm::createXCOFFObjectWriter(std::unique_ptr<MCXCOFFObjectTargetWriter> MOTW,
                               raw_pwrite_stream &OS) {
-  return std::make_unique<XCOFFObjectWriter>(std::move(MOTW), OS);
-}
-
-// TODO: Export XCOFFObjectWriter to llvm/MC/MCXCOFFObjectWriter.h and remove
-// the forwarders.
-void XCOFF::addExceptionEntry(MCObjectWriter &Writer, const MCSymbol *Symbol,
-                              const MCSymbol *Trap, unsigned LanguageCode,
-                              unsigned ReasonCode, unsigned FunctionSize,
-                              bool hasDebug) {
-  static_cast<XCOFFObjectWriter &>(Writer).addExceptionEntry(
-      Symbol, Trap, LanguageCode, ReasonCode, FunctionSize, hasDebug);
-}
-
-void XCOFF::addCInfoSymEntry(MCObjectWriter &Writer, StringRef Name,
-                             StringRef Metadata) {
-  static_cast<XCOFFObjectWriter &>(Writer).addCInfoSymEntry(Name, Metadata);
+  return std::make_unique<XCOFFWriter>(std::move(MOTW), OS);
 }


        


More information about the llvm-commits mailing list