diff options
| -rw-r--r-- | llvm/include/llvm/MC/ELFObjectWriter.h | 53 | ||||
| -rw-r--r-- | llvm/include/llvm/MC/MCObjectWriter.h | 8 | ||||
| -rw-r--r-- | llvm/include/llvm/MC/MachObjectWriter.h | 50 | ||||
| -rw-r--r-- | llvm/lib/MC/ELFObjectWriter.cpp | 218 | ||||
| -rw-r--r-- | llvm/lib/MC/MachObjectWriter.cpp | 72 | ||||
| -rw-r--r-- | llvm/lib/Target/ARM/ARMAsmBackend.cpp | 15 | ||||
| -rw-r--r-- | llvm/lib/Target/MBlaze/MBlazeAsmBackend.cpp | 10 | ||||
| -rw-r--r-- | llvm/lib/Target/X86/X86AsmBackend.cpp | 28 | 
8 files changed, 131 insertions, 323 deletions
diff --git a/llvm/include/llvm/MC/ELFObjectWriter.h b/llvm/include/llvm/MC/ELFObjectWriter.h deleted file mode 100644 index ce52c50ab0e..00000000000 --- a/llvm/include/llvm/MC/ELFObjectWriter.h +++ /dev/null @@ -1,53 +0,0 @@ -//===-- llvm/MC/ELFObjectWriter.h - ELF File Writer ---------*- C++ -*-===// -// -//                     The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_MC_ELFOBJECTWRITER_H -#define LLVM_MC_ELFOBJECTWRITER_H - -#include "llvm/ADT/Triple.h" -#include "llvm/MC/MCObjectWriter.h" -#include "llvm/Support/raw_ostream.h" -#include <cassert> - -namespace llvm { -class MCAsmFixup; -class MCAssembler; -class MCFragment; -class MCValue; -class raw_ostream; - -class ELFObjectWriter : public MCObjectWriter { -  void *Impl; - -public: -  ELFObjectWriter(raw_ostream &OS, bool Is64Bit, Triple::OSType OSType,  -                  uint16_t EMachine, bool IsLittleEndian = true, -                  bool HasRelocationAddend = true); - -  virtual ~ELFObjectWriter(); - -  virtual void ExecutePostLayoutBinding(MCAssembler &Asm); - -  virtual void RecordRelocation(const MCAssembler &Asm, -                                const MCAsmLayout &Layout, -                                const MCFragment *Fragment, -                                const MCFixup &Fixup, MCValue Target, -                                uint64_t &FixedValue); - -  virtual bool IsFixupFullyResolved(const MCAssembler &Asm, -                                    const MCValue Target, -                                    bool IsPCRel, -                                    const MCFragment *DF) const; - -  virtual void WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout); -}; - -} // End llvm namespace - -#endif diff --git a/llvm/include/llvm/MC/MCObjectWriter.h b/llvm/include/llvm/MC/MCObjectWriter.h index 6814cb537bf..77ab6abed20 100644 --- a/llvm/include/llvm/MC/MCObjectWriter.h +++ b/llvm/include/llvm/MC/MCObjectWriter.h @@ -10,6 +10,7 @@  #ifndef LLVM_MC_MCOBJECTWRITER_H  #define LLVM_MC_MCOBJECTWRITER_H +#include "llvm/ADT/Triple.h"  #include "llvm/Support/raw_ostream.h"  #include "llvm/System/DataTypes.h"  #include <cassert> @@ -177,6 +178,13 @@ public:    static void EncodeULEB128(uint64_t Value, raw_ostream &OS);  }; +MCObjectWriter *createMachObjectWriter(raw_ostream &OS, bool is64Bit, +                                       uint32_t CPUType, uint32_t CPUSubtype, +                                       bool IsLittleEndian); +MCObjectWriter *createELFObjectWriter(raw_ostream &OS, bool is64Bit, +                                      Triple::OSType OSType, uint16_t EMachine, +                                      bool IsLittleEndian, +                                      bool HasRelocationAddend);  MCObjectWriter *createWinCOFFObjectWriter(raw_ostream &OS, bool is64Bit);  } // End llvm namespace diff --git a/llvm/include/llvm/MC/MachObjectWriter.h b/llvm/include/llvm/MC/MachObjectWriter.h deleted file mode 100644 index 01f7aaffd50..00000000000 --- a/llvm/include/llvm/MC/MachObjectWriter.h +++ /dev/null @@ -1,50 +0,0 @@ -//===-- llvm/MC/MachObjectWriter.h - Mach-O File Writer ---------*- C++ -*-===// -// -//                     The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_MC_MACHOBJECTWRITER_H -#define LLVM_MC_MACHOBJECTWRITER_H - -#include "llvm/MC/MCObjectWriter.h" -#include "llvm/Support/raw_ostream.h" -#include <cassert> - -namespace llvm { -class MCAssembler; -class MCFragment; -class MCFixup; -class MCValue; -class raw_ostream; - -class MachObjectWriter : public MCObjectWriter { -  void *Impl; - -public: -  MachObjectWriter(raw_ostream &OS, bool Is64Bit, uint32_t CPUType, -                   uint32_t CPUSubtype, bool IsLittleEndian = true); -  virtual ~MachObjectWriter(); - -  virtual void ExecutePostLayoutBinding(MCAssembler &Asm); - -  virtual void RecordRelocation(const MCAssembler &Asm, -                                const MCAsmLayout &Layout, -                                const MCFragment *Fragment, -                                const MCFixup &Fixup, MCValue Target, -                                uint64_t &FixedValue); - -  virtual bool IsFixupFullyResolved(const MCAssembler &Asm, -                                    const MCValue Target, -                                    bool IsPCRel, -                                    const MCFragment *DF) const; - -  virtual void WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout); -}; - -} // End llvm namespace - -#endif diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp index 10600a5acda..e019e185272 100644 --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -11,7 +11,6 @@  //  //===----------------------------------------------------------------------===// -#include "llvm/MC/ELFObjectWriter.h"  #include "llvm/ADT/SmallPtrSet.h"  #include "llvm/ADT/STLExtras.h"  #include "llvm/ADT/StringMap.h" @@ -99,8 +98,7 @@ static bool RelocNeedsGOT(MCSymbolRefExpr::VariantKind Variant) {  }  namespace { - -  class ELFObjectWriterImpl { +  class ELFObjectWriter : public MCObjectWriter {      /*static bool isFixupKindX86RIPRel(unsigned Kind) {        return Kind == X86::reloc_riprel_4byte ||          Kind == X86::reloc_riprel_4byte_movq_load; @@ -167,10 +165,6 @@ namespace {      bool NeedsSymtabShndx; -    ELFObjectWriter *Writer; - -    raw_ostream &OS; -      unsigned Is64Bit : 1;      bool HasRelocationAddend; @@ -189,29 +183,20 @@ namespace {      unsigned ShstrtabIndex;    public: -    ELFObjectWriterImpl(ELFObjectWriter *_Writer, bool _Is64Bit, -                        uint16_t _EMachine, bool _HasRelAddend, -                        Triple::OSType _OSType) -      : NeedsGOT(false), NeedsSymtabShndx(false), Writer(_Writer), -        OS(Writer->getStream()), +    ELFObjectWriter(raw_ostream &_OS, bool _Is64Bit, bool IsLittleEndian, +                    uint16_t _EMachine, bool _HasRelAddend, +                    Triple::OSType _OSType) +      : MCObjectWriter(_OS, IsLittleEndian), +        NeedsGOT(false), NeedsSymtabShndx(false),          Is64Bit(_Is64Bit), HasRelocationAddend(_HasRelAddend),          OSType(_OSType), EMachine(_EMachine) {      } - -    void Write8(uint8_t Value) { Writer->Write8(Value); } -    void Write16(uint16_t Value) { Writer->Write16(Value); } -    void Write32(uint32_t Value) { Writer->Write32(Value); } -    //void Write64(uint64_t Value) { Writer->Write64(Value); } -    void WriteZeros(unsigned N) { Writer->WriteZeros(N); } -    //void WriteBytes(StringRef Str, unsigned ZeroFillSize = 0) { -    //  Writer->WriteBytes(Str, ZeroFillSize); -    //} - +        void WriteWord(uint64_t W) {        if (Is64Bit) -        Writer->Write64(W); +        Write64(W);        else -        Writer->Write32(W); +        Write32(W);      }      void StringLE16(char *buf, uint16_t Value) { @@ -252,7 +237,7 @@ namespace {      void String16(MCDataFragment &F, uint16_t Value) {        char buf[2]; -      if (Writer->isLittleEndian()) +      if (isLittleEndian())          StringLE16(buf, Value);        else          StringBE16(buf, Value); @@ -261,7 +246,7 @@ namespace {      void String32(MCDataFragment &F, uint32_t Value) {        char buf[4]; -      if (Writer->isLittleEndian()) +      if (isLittleEndian())          StringLE32(buf, Value);        else          StringBE32(buf, Value); @@ -270,7 +255,7 @@ namespace {      void String64(MCDataFragment &F, uint64_t Value) {        char buf[8]; -      if (Writer->isLittleEndian()) +      if (isLittleEndian())          StringLE64(buf, Value);        else          StringBE64(buf, Value); @@ -357,8 +342,8 @@ namespace {  }  // Emit the ELF header. -void ELFObjectWriterImpl::WriteHeader(uint64_t SectionDataSize, -                                      unsigned NumberOfSections) { +void ELFObjectWriter::WriteHeader(uint64_t SectionDataSize, +                                  unsigned NumberOfSections) {    // ELF Header    // ----------    // @@ -375,7 +360,7 @@ void ELFObjectWriterImpl::WriteHeader(uint64_t SectionDataSize,    Write8(Is64Bit ? ELF::ELFCLASS64 : ELF::ELFCLASS32); // e_ident[EI_CLASS]    // e_ident[EI_DATA] -  Write8(Writer->isLittleEndian() ? ELF::ELFDATA2LSB : ELF::ELFDATA2MSB); +  Write8(isLittleEndian() ? ELF::ELFDATA2LSB : ELF::ELFDATA2MSB);    Write8(ELF::EV_CURRENT);        // e_ident[EI_VERSION]    // e_ident[EI_OSABI] @@ -423,13 +408,13 @@ void ELFObjectWriterImpl::WriteHeader(uint64_t SectionDataSize,      Write16(ShstrtabIndex);  } -void ELFObjectWriterImpl::WriteSymbolEntry(MCDataFragment *SymtabF, -                                           MCDataFragment *ShndxF, -                                           uint64_t name, -                                           uint8_t info, uint64_t value, -                                           uint64_t size, uint8_t other, -                                           uint32_t shndx, -                                           bool Reserved) { +void ELFObjectWriter::WriteSymbolEntry(MCDataFragment *SymtabF, +                                       MCDataFragment *ShndxF, +                                       uint64_t name, +                                       uint8_t info, uint64_t value, +                                       uint64_t size, uint8_t other, +                                       uint32_t shndx, +                                       bool Reserved) {    if (ShndxF) {      if (shndx >= ELF::SHN_LORESERVE && !Reserved)        String32(*ShndxF, shndx); @@ -497,7 +482,7 @@ static const MCSymbol &AliasedSymbol(const MCSymbol &Symbol) {    return *S;  } -void ELFObjectWriterImpl::ExecutePostLayoutBinding(MCAssembler &Asm) { +void ELFObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm) {    // The presence of symbol versions causes undefined symbols and    // versions declared with @@@ to be renamed. @@ -543,10 +528,10 @@ void ELFObjectWriterImpl::ExecutePostLayoutBinding(MCAssembler &Asm) {    }  } -void ELFObjectWriterImpl::WriteSymbol(MCDataFragment *SymtabF, -                                      MCDataFragment *ShndxF, -                                      ELFSymbolData &MSD, -                                      const MCAsmLayout &Layout) { +void ELFObjectWriter::WriteSymbol(MCDataFragment *SymtabF, +                                  MCDataFragment *ShndxF, +                                  ELFSymbolData &MSD, +                                  const MCAsmLayout &Layout) {    MCSymbolData &OrigData = *MSD.SymbolData;    MCSymbolData &Data =      Layout.getAssembler().getSymbolData(AliasedSymbol(OrigData.getSymbol())); @@ -590,10 +575,10 @@ void ELFObjectWriterImpl::WriteSymbol(MCDataFragment *SymtabF,                     Size, Other, MSD.SectionIndex, IsReserved);  } -void ELFObjectWriterImpl::WriteSymbolTable(MCDataFragment *SymtabF, -                                           MCDataFragment *ShndxF, -                                           const MCAssembler &Asm, -                                           const MCAsmLayout &Layout, +void ELFObjectWriter::WriteSymbolTable(MCDataFragment *SymtabF, +                                       MCDataFragment *ShndxF, +                                       const MCAssembler &Asm, +                                       const MCAsmLayout &Layout,                                       const SectionIndexMapTy &SectionIndexMap) {    // The string table must be emitted first because we need the index    // into the string table for all the symbol names. @@ -679,12 +664,12 @@ static bool ShouldRelocOnSymbol(const MCSymbolData &SD,  }  // FIXME: this is currently X86/X86_64 only -void ELFObjectWriterImpl::RecordRelocation(const MCAssembler &Asm, -                                           const MCAsmLayout &Layout, -                                           const MCFragment *Fragment, -                                           const MCFixup &Fixup, -                                           MCValue Target, -                                           uint64_t &FixedValue) { +void ELFObjectWriter::RecordRelocation(const MCAssembler &Asm, +                                       const MCAsmLayout &Layout, +                                       const MCFragment *Fragment, +                                       const MCFixup &Fixup, +                                       MCValue Target, +                                       uint64_t &FixedValue) {    int64_t Addend = 0;    int Index = 0;    int64_t Value = Target.getConstant(); @@ -886,8 +871,8 @@ void ELFObjectWriterImpl::RecordRelocation(const MCAssembler &Asm,  }  uint64_t -ELFObjectWriterImpl::getSymbolIndexInSymbolTable(const MCAssembler &Asm, -                                                 const MCSymbol *S) { +ELFObjectWriter::getSymbolIndexInSymbolTable(const MCAssembler &Asm, +                                             const MCSymbol *S) {    MCSymbolData &SD = Asm.getSymbolData(*S);    // Local symbol. @@ -938,8 +923,8 @@ static bool isLocal(const MCSymbolData &Data) {    return true;  } -void ELFObjectWriterImpl::ComputeIndexMap(MCAssembler &Asm, -                                          SectionIndexMapTy &SectionIndexMap) { +void ELFObjectWriter::ComputeIndexMap(MCAssembler &Asm, +                                      SectionIndexMapTy &SectionIndexMap) {    unsigned Index = 1;    for (MCAssembler::iterator it = Asm.begin(),           ie = Asm.end(); it != ie; ++it) { @@ -960,7 +945,7 @@ void ELFObjectWriterImpl::ComputeIndexMap(MCAssembler &Asm,    }  } -void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm, +void ELFObjectWriter::ComputeSymbolTable(MCAssembler &Asm,                                       const SectionIndexMapTy &SectionIndexMap) {    // FIXME: Is this the correct place to do this?    if (NeedsGOT) { @@ -1057,8 +1042,8 @@ void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm,      UndefinedSymbolData[i].SymbolData->setIndex(Index++);  } -void ELFObjectWriterImpl::WriteRelocation(MCAssembler &Asm, MCAsmLayout &Layout, -                                          const MCSectionData &SD) { +void ELFObjectWriter::WriteRelocation(MCAssembler &Asm, MCAsmLayout &Layout, +                                      const MCSectionData &SD) {    if (!Relocations[&SD].empty()) {      MCContext &Ctx = Asm.getContext();      const MCSectionELF *RelaSection; @@ -1087,16 +1072,16 @@ void ELFObjectWriterImpl::WriteRelocation(MCAssembler &Asm, MCAsmLayout &Layout,      WriteRelocationsFragment(Asm, F, &SD); -    Asm.AddSectionToTheEnd(*Writer, RelaSD, Layout); +    Asm.AddSectionToTheEnd(*this, RelaSD, Layout);    }  } -void ELFObjectWriterImpl::WriteSecHdrEntry(uint32_t Name, uint32_t Type, -                                           uint64_t Flags, uint64_t Address, -                                           uint64_t Offset, uint64_t Size, -                                           uint32_t Link, uint32_t Info, -                                           uint64_t Alignment, -                                           uint64_t EntrySize) { +void ELFObjectWriter::WriteSecHdrEntry(uint32_t Name, uint32_t Type, +                                       uint64_t Flags, uint64_t Address, +                                       uint64_t Offset, uint64_t Size, +                                       uint32_t Link, uint32_t Info, +                                       uint64_t Alignment, +                                       uint64_t EntrySize) {    Write32(Name);        // sh_name: index into string table    Write32(Type);        // sh_type    WriteWord(Flags);     // sh_flags @@ -1109,9 +1094,9 @@ void ELFObjectWriterImpl::WriteSecHdrEntry(uint32_t Name, uint32_t Type,    WriteWord(EntrySize); // sh_entsize  } -void ELFObjectWriterImpl::WriteRelocationsFragment(const MCAssembler &Asm, -                                                   MCDataFragment *F, -                                                   const MCSectionData *SD) { +void ELFObjectWriter::WriteRelocationsFragment(const MCAssembler &Asm, +                                               MCDataFragment *F, +                                               const MCSectionData *SD) {    std::vector<ELFRelocationEntry> &Relocs = Relocations[SD];    // sort by the r_offset just like gnu as does    array_pod_sort(Relocs.begin(), Relocs.end()); @@ -1145,8 +1130,8 @@ void ELFObjectWriterImpl::WriteRelocationsFragment(const MCAssembler &Asm,    }  } -void ELFObjectWriterImpl::CreateMetadataSections(MCAssembler &Asm, -                                                 MCAsmLayout &Layout, +void ELFObjectWriter::CreateMetadataSections(MCAssembler &Asm, +                                             MCAsmLayout &Layout,                                      const SectionIndexMapTy &SectionIndexMap) {    MCContext &Ctx = Asm.getContext();    MCDataFragment *F; @@ -1193,14 +1178,14 @@ void ELFObjectWriterImpl::CreateMetadataSections(MCAssembler &Asm,    MCDataFragment *ShndxF = NULL;    if (NeedsSymtabShndx) {      ShndxF = new MCDataFragment(SymtabShndxSD); -    Asm.AddSectionToTheEnd(*Writer, *SymtabShndxSD, Layout); +    Asm.AddSectionToTheEnd(*this, *SymtabShndxSD, Layout);    }    WriteSymbolTable(F, ShndxF, Asm, Layout, SectionIndexMap); -  Asm.AddSectionToTheEnd(*Writer, SymtabSD, Layout); +  Asm.AddSectionToTheEnd(*this, SymtabSD, Layout);    F = new MCDataFragment(&StrtabSD);    F->getContents().append(StringTable.begin(), StringTable.end()); -  Asm.AddSectionToTheEnd(*Writer, StrtabSD, Layout); +  Asm.AddSectionToTheEnd(*this, StrtabSD, Layout);    F = new MCDataFragment(&ShstrtabSD); @@ -1233,13 +1218,13 @@ void ELFObjectWriterImpl::CreateMetadataSections(MCAssembler &Asm,      F->getContents() += '\x00';    } -  Asm.AddSectionToTheEnd(*Writer, ShstrtabSD, Layout); +  Asm.AddSectionToTheEnd(*this, ShstrtabSD, Layout);  } -bool ELFObjectWriterImpl::IsFixupFullyResolved(const MCAssembler &Asm, -                                               const MCValue Target, -                                               bool IsPCRel, -                                               const MCFragment *DF) const { +bool ELFObjectWriter::IsFixupFullyResolved(const MCAssembler &Asm, +                                           const MCValue Target, +                                           bool IsPCRel, +                                           const MCFragment *DF) const {    // If this is a PCrel relocation, find the section this fixup value is    // relative to.    const MCSection *BaseSection = 0; @@ -1270,9 +1255,9 @@ bool ELFObjectWriterImpl::IsFixupFullyResolved(const MCAssembler &Asm,    return !SectionB && BaseSection == SectionA;  } -void ELFObjectWriterImpl::CreateGroupSections(MCAssembler &Asm, -                                              MCAsmLayout &Layout, -                                              GroupMapTy &GroupMap) { +void ELFObjectWriter::CreateGroupSections(MCAssembler &Asm, +                                          MCAsmLayout &Layout, +                                          GroupMapTy &GroupMap) {    typedef DenseMap<const MCSymbol*, const MCSectionELF*> RevGroupMapTy;    // Build the groups    RevGroupMapTy Groups; @@ -1316,16 +1301,16 @@ void ELFObjectWriterImpl::CreateGroupSections(MCAssembler &Asm,         i != e; ++i) {      const MCSectionELF *Group = i->second;      MCSectionData &Data = Asm.getOrCreateSectionData(*Group); -    Asm.AddSectionToTheEnd(*Writer, Data, Layout); +    Asm.AddSectionToTheEnd(*this, Data, Layout);    }  } -void ELFObjectWriterImpl::WriteSection(MCAssembler &Asm, -                                       const SectionIndexMapTy &SectionIndexMap, -                                       uint32_t GroupSymbolIndex, -                                       uint64_t Offset, uint64_t Size, -                                       uint64_t Alignment, -                                       const MCSectionELF &Section) { +void ELFObjectWriter::WriteSection(MCAssembler &Asm, +                                   const SectionIndexMapTy &SectionIndexMap, +                                   uint32_t GroupSymbolIndex, +                                   uint64_t Offset, uint64_t Size, +                                   uint64_t Alignment, +                                   const MCSectionELF &Section) {    uint64_t sh_link = 0;    uint64_t sh_info = 0; @@ -1390,9 +1375,8 @@ void ELFObjectWriterImpl::WriteSection(MCAssembler &Asm,                     Alignment, Section.getEntrySize());  } -void ELFObjectWriterImpl::WriteObject(MCAssembler &Asm, -                                      const MCAsmLayout &Layout) { - +void ELFObjectWriter::WriteObject(MCAssembler &Asm, +                                  const MCAsmLayout &Layout) {    GroupMapTy GroupMap;    CreateGroupSections(Asm, const_cast<MCAsmLayout&>(Layout), GroupMap); @@ -1460,7 +1444,7 @@ void ELFObjectWriterImpl::WriteObject(MCAssembler &Asm,      FileOff += Layout.getSectionFileSize(&SD); -    Asm.WriteSectionData(&SD, Layout, Writer); +    Asm.WriteSectionData(&SD, Layout, this);    }    uint64_t Padding = OffsetToAlignment(FileOff, NaturalAlignment); @@ -1492,44 +1476,12 @@ void ELFObjectWriterImpl::WriteObject(MCAssembler &Asm,    }  } -ELFObjectWriter::ELFObjectWriter(raw_ostream &OS, -                                 bool Is64Bit, -                                 Triple::OSType OSType, -                                 uint16_t EMachine, -                                 bool IsLittleEndian, -                                 bool HasRelocationAddend) -  : MCObjectWriter(OS, IsLittleEndian) -{ -  Impl = new ELFObjectWriterImpl(this, Is64Bit, EMachine, -                                 HasRelocationAddend, OSType); -} - -ELFObjectWriter::~ELFObjectWriter() { -  delete (ELFObjectWriterImpl*) Impl; -} - -void ELFObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm) { -  ((ELFObjectWriterImpl*) Impl)->ExecutePostLayoutBinding(Asm); -} - -void ELFObjectWriter::RecordRelocation(const MCAssembler &Asm, -                                       const MCAsmLayout &Layout, -                                       const MCFragment *Fragment, -                                       const MCFixup &Fixup, MCValue Target, -                                       uint64_t &FixedValue) { -  ((ELFObjectWriterImpl*) Impl)->RecordRelocation(Asm, Layout, Fragment, Fixup, -                                                  Target, FixedValue); -} - -bool ELFObjectWriter::IsFixupFullyResolved(const MCAssembler &Asm, -                                           const MCValue Target, -                                           bool IsPCRel, -                                           const MCFragment *DF) const { -  return ((ELFObjectWriterImpl*) Impl)->IsFixupFullyResolved(Asm, Target, -                                                             IsPCRel, DF); -} - -void ELFObjectWriter::WriteObject(MCAssembler &Asm, -                                  const MCAsmLayout &Layout) { -  ((ELFObjectWriterImpl*) Impl)->WriteObject(Asm, Layout); +MCObjectWriter *llvm::createELFObjectWriter(raw_ostream &OS, +                                            bool Is64Bit, +                                            Triple::OSType OSType, +                                            uint16_t EMachine, +                                            bool IsLittleEndian, +                                            bool HasRelocationAddend) { +  return new ELFObjectWriter(OS, Is64Bit, IsLittleEndian, EMachine, +                             HasRelocationAddend, OSType);  } diff --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp index fc711258f85..41c11fba1d0 100644 --- a/llvm/lib/MC/MachObjectWriter.cpp +++ b/llvm/lib/MC/MachObjectWriter.cpp @@ -7,7 +7,6 @@  //  //===----------------------------------------------------------------------===// -#include "llvm/MC/MachObjectWriter.h"  #include "llvm/ADT/StringMap.h"  #include "llvm/ADT/Twine.h"  #include "llvm/MC/MCAssembler.h" @@ -159,7 +158,7 @@ static bool isScatteredFixupFullyResolvedSimple(const MCAssembler &Asm,  namespace { -class MachObjectWriterImpl { +class MachObjectWriter : public MCObjectWriter {    // See <mach-o/loader.h>.    enum {      Header_Magic32 = 0xFEEDFACE, @@ -284,29 +283,17 @@ class MachObjectWriterImpl {    /// @} -  MachObjectWriter *Writer; - -  raw_ostream &OS; -    unsigned Is64Bit : 1;    uint32_t CPUType;    uint32_t CPUSubtype;  public: -  MachObjectWriterImpl(MachObjectWriter *_Writer, bool _Is64Bit, -                       uint32_t _CPUType, uint32_t _CPUSubtype) -    : Writer(_Writer), OS(Writer->getStream()), Is64Bit(_Is64Bit), -      CPUType(_CPUType), CPUSubtype(_CPUSubtype) { -  } - -  void Write8(uint8_t Value) { Writer->Write8(Value); } -  void Write16(uint16_t Value) { Writer->Write16(Value); } -  void Write32(uint32_t Value) { Writer->Write32(Value); } -  void Write64(uint64_t Value) { Writer->Write64(Value); } -  void WriteZeros(unsigned N) { Writer->WriteZeros(N); } -  void WriteBytes(StringRef Str, unsigned ZeroFillSize = 0) { -    Writer->WriteBytes(Str, ZeroFillSize); +  MachObjectWriter(raw_ostream &_OS, +                   bool _Is64Bit, uint32_t _CPUType, uint32_t _CPUSubtype, +                   bool _IsLittleEndian) +    : MCObjectWriter(_OS, _IsLittleEndian), +      Is64Bit(_Is64Bit), CPUType(_CPUType), CPUSubtype(_CPUSubtype) {    }    void WriteHeader(unsigned NumLoadCommands, unsigned LoadCommandsSize, @@ -1170,7 +1157,7 @@ public:      return true;    } -  void WriteObject(const MCAssembler &Asm, const MCAsmLayout &Layout) { +  void WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout) {      unsigned NumSections = Asm.size();      // The section data starts after the header, the segment load command (and @@ -1271,7 +1258,7 @@ public:      // Write the actual section data.      for (MCAssembler::const_iterator it = Asm.begin(),             ie = Asm.end(); it != ie; ++it) -      Asm.WriteSectionData(it, Layout, Writer); +      Asm.WriteSectionData(it, Layout, this);      // Write the extra padding.      WriteZeros(SectionDataPadding); @@ -1331,42 +1318,9 @@ public:  } -MachObjectWriter::MachObjectWriter(raw_ostream &OS, -                                   bool Is64Bit, -                                   uint32_t CPUType, -                                   uint32_t CPUSubtype, -                                   bool IsLittleEndian) -  : MCObjectWriter(OS, IsLittleEndian) -{ -  Impl = new MachObjectWriterImpl(this, Is64Bit, CPUType, CPUSubtype); -} - -MachObjectWriter::~MachObjectWriter() { -  delete (MachObjectWriterImpl*) Impl; -} - -void MachObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm) { -  ((MachObjectWriterImpl*) Impl)->ExecutePostLayoutBinding(Asm); -} - -void MachObjectWriter::RecordRelocation(const MCAssembler &Asm, -                                        const MCAsmLayout &Layout, -                                        const MCFragment *Fragment, -                                        const MCFixup &Fixup, MCValue Target, -                                        uint64_t &FixedValue) { -  ((MachObjectWriterImpl*) Impl)->RecordRelocation(Asm, Layout, Fragment, Fixup, -                                                   Target, FixedValue); -} - -bool MachObjectWriter::IsFixupFullyResolved(const MCAssembler &Asm, -                                           const MCValue Target, -                                           bool IsPCRel, -                                           const MCFragment *DF) const { -  return ((MachObjectWriterImpl*) Impl)->IsFixupFullyResolved(Asm, Target, -                                                              IsPCRel, DF); -} - -void MachObjectWriter::WriteObject(MCAssembler &Asm, -                                   const MCAsmLayout &Layout) { -  ((MachObjectWriterImpl*) Impl)->WriteObject(Asm, Layout); +MCObjectWriter *llvm::createMachObjectWriter(raw_ostream &OS, bool is64Bit, +                                             uint32_t CPUType, +                                             uint32_t CPUSubtype, +                                             bool IsLittleEndian) { +  return new MachObjectWriter(OS, is64Bit, CPUType, CPUSubtype, IsLittleEndian);  } diff --git a/llvm/lib/Target/ARM/ARMAsmBackend.cpp b/llvm/lib/Target/ARM/ARMAsmBackend.cpp index d5a27592da0..86b1e069a7c 100644 --- a/llvm/lib/Target/ARM/ARMAsmBackend.cpp +++ b/llvm/lib/Target/ARM/ARMAsmBackend.cpp @@ -11,14 +11,12 @@  #include "ARM.h"  #include "ARMFixupKinds.h"  #include "llvm/ADT/Twine.h" -#include "llvm/MC/ELFObjectWriter.h"  #include "llvm/MC/MCAssembler.h"  #include "llvm/MC/MCExpr.h"  #include "llvm/MC/MCObjectFormat.h"  #include "llvm/MC/MCObjectWriter.h"  #include "llvm/MC/MCSectionELF.h"  #include "llvm/MC/MCSectionMachO.h" -#include "llvm/MC/MachObjectWriter.h"  #include "llvm/Support/ELF.h"  #include "llvm/Support/MachO.h"  #include "llvm/Support/ErrorHandling.h" @@ -94,10 +92,10 @@ public:    }    MCObjectWriter *createObjectWriter(raw_ostream &OS) const { -    return new ELFObjectWriter(OS, /*Is64Bit=*/false, -                               OSType, ELF::EM_ARM, -                               /*IsLittleEndian=*/true, -                               /*HasRelocationAddend=*/false); +    return createELFObjectWriter(OS, /*Is64Bit=*/false, +                                 OSType, ELF::EM_ARM, +                                 /*IsLittleEndian=*/true, +                                 /*HasRelocationAddend=*/false);    }  }; @@ -133,8 +131,9 @@ public:    MCObjectWriter *createObjectWriter(raw_ostream &OS) const {      // FIXME: Subtarget info should be derived. Force v7 for now. -    return new MachObjectWriter(OS, /*Is64Bit=*/false, MachO::CPUTypeARM, -                                MachO::CPUSubType_ARM_V7); +    return createMachObjectWriter(OS, /*Is64Bit=*/false, MachO::CPUTypeARM, +                                  MachO::CPUSubType_ARM_V7, +                                  /*IsLittleEndian=*/true);    }    virtual bool doesSectionRequireSymbols(const MCSection &Section) const { diff --git a/llvm/lib/Target/MBlaze/MBlazeAsmBackend.cpp b/llvm/lib/Target/MBlaze/MBlazeAsmBackend.cpp index 91678096507..944ebf1f4be 100644 --- a/llvm/lib/Target/MBlaze/MBlazeAsmBackend.cpp +++ b/llvm/lib/Target/MBlaze/MBlazeAsmBackend.cpp @@ -11,14 +11,12 @@  #include "MBlaze.h"  #include "MBlazeFixupKinds.h"  #include "llvm/ADT/Twine.h" -#include "llvm/MC/ELFObjectWriter.h"  #include "llvm/MC/MCAssembler.h"  #include "llvm/MC/MCExpr.h"  #include "llvm/MC/MCObjectFormat.h"  #include "llvm/MC/MCObjectWriter.h"  #include "llvm/MC/MCSectionELF.h"  #include "llvm/MC/MCSectionMachO.h" -#include "llvm/MC/MachObjectWriter.h"  #include "llvm/Support/ELF.h"  #include "llvm/Support/ErrorHandling.h"  #include "llvm/Support/raw_ostream.h" @@ -104,10 +102,10 @@ public:    }    MCObjectWriter *createObjectWriter(raw_ostream &OS) const { -    return new ELFObjectWriter(OS, /*Is64Bit=*/false, -                               OSType, ELF::EM_MBLAZE, -                               /*IsLittleEndian=*/false, -                               /*HasRelocationAddend=*/true); +    return createELFObjectWriter(OS, /*Is64Bit=*/false, +                                 OSType, ELF::EM_MBLAZE, +                                 /*IsLittleEndian=*/false, +                                 /*HasRelocationAddend=*/true);    }  }; diff --git a/llvm/lib/Target/X86/X86AsmBackend.cpp b/llvm/lib/Target/X86/X86AsmBackend.cpp index 42643a395a3..a030196e1d7 100644 --- a/llvm/lib/Target/X86/X86AsmBackend.cpp +++ b/llvm/lib/Target/X86/X86AsmBackend.cpp @@ -11,7 +11,6 @@  #include "X86.h"  #include "X86FixupKinds.h"  #include "llvm/ADT/Twine.h" -#include "llvm/MC/ELFObjectWriter.h"  #include "llvm/MC/MCAssembler.h"  #include "llvm/MC/MCExpr.h"  #include "llvm/MC/MCObjectFormat.h" @@ -19,7 +18,6 @@  #include "llvm/MC/MCSectionCOFF.h"  #include "llvm/MC/MCSectionELF.h"  #include "llvm/MC/MCSectionMachO.h" -#include "llvm/MC/MachObjectWriter.h"  #include "llvm/Support/ELF.h"  #include "llvm/Support/MachO.h"  #include "llvm/Support/ErrorHandling.h" @@ -310,10 +308,10 @@ public:    }    MCObjectWriter *createObjectWriter(raw_ostream &OS) const { -    return new ELFObjectWriter(OS, /*Is64Bit=*/false, -                               OSType, ELF::EM_386, -                               /*IsLittleEndian=*/true, -                               /*HasRelocationAddend=*/false); +    return createELFObjectWriter(OS, /*Is64Bit=*/false, +                                 OSType, ELF::EM_386, +                                 /*IsLittleEndian=*/true, +                                 /*HasRelocationAddend=*/false);    }  }; @@ -327,10 +325,10 @@ public:    }    MCObjectWriter *createObjectWriter(raw_ostream &OS) const { -    return new ELFObjectWriter(OS, /*Is64Bit=*/true, -                               OSType, ELF::EM_X86_64, -                               /*IsLittleEndian=*/true, -                               /*HasRelocationAddend=*/true); +    return createELFObjectWriter(OS, /*Is64Bit=*/true, +                                 OSType, ELF::EM_X86_64, +                                 /*IsLittleEndian=*/true, +                                 /*HasRelocationAddend=*/true);    }  }; @@ -397,8 +395,9 @@ public:    }    MCObjectWriter *createObjectWriter(raw_ostream &OS) const { -    return new MachObjectWriter(OS, /*Is64Bit=*/false, MachO::CPUTypeI386, -                                MachO::CPUSubType_I386_ALL); +    return createMachObjectWriter(OS, /*Is64Bit=*/false, MachO::CPUTypeI386, +                                  MachO::CPUSubType_I386_ALL, +                                  /*IsLittleEndian=*/true);    }  }; @@ -414,8 +413,9 @@ public:    }    MCObjectWriter *createObjectWriter(raw_ostream &OS) const { -    return new MachObjectWriter(OS, /*Is64Bit=*/true, MachO::CPUTypeX86_64, -                                MachO::CPUSubType_I386_ALL); +    return createMachObjectWriter(OS, /*Is64Bit=*/true, MachO::CPUTypeX86_64, +                                  MachO::CPUSubType_I386_ALL, +                                  /*IsLittleEndian=*/true);    }    virtual bool doesSectionRequireSymbols(const MCSection &Section) const {  | 

