From e68f90355c15c276c0f92a7c1cef6db4c9b89237 Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Tue, 29 Jan 2013 22:03:39 +0000 Subject: [PATCH] [ELF] Chop the ELF prefix off of most things. llvm-svn: 173838 --- lld/include/lld/ReaderWriter/ELFTargetInfo.h | 13 +-- lld/lib/ReaderWriter/ELF/{AtomsELF.h => Atoms.h} | 64 +++++----- lld/lib/ReaderWriter/ELF/CMakeLists.txt | 4 +- lld/lib/ReaderWriter/ELF/{ELFChunk.h => Chunk.h} | 26 +++-- .../ELF/{DefaultELFLayout.h => DefaultLayout.h} | 95 ++++++++------- ...ltELFTargetHandler.h => DefaultTargetHandler.h} | 35 +++--- lld/lib/ReaderWriter/ELF/ELFTargetInfo.cpp | 12 +- lld/lib/ReaderWriter/ELF/ExecutableAtoms.h | 36 +++--- lld/lib/ReaderWriter/ELF/{FileELF.h => File.h} | 40 ++++--- .../ELF/{ELFHeaderChunks.h => HeaderChunks.h} | 66 +++++------ .../X86_64ELFTarget.h => Hexagon/HexagonTarget.h} | 4 +- ...{HexagonELFTargetInfo.h => HexagonTargetInfo.h} | 10 +- lld/lib/ReaderWriter/ELF/{ELFLayout.h => Layout.h} | 26 ++--- .../ELF/PPC/{PPCELFTarget.h => PPCTarget.h} | 5 +- .../PPC/{PPCELFTargetInfo.h => PPCTargetInfo.h} | 10 +- .../ReaderWriter/ELF/{ReaderELF.cpp => Reader.cpp} | 41 ++++--- .../ELF/{ELFSectionChunks.h => SectionChunks.h} | 83 +++++++------ .../ELF/{ELFSegmentChunks.h => SegmentChunks.h} | 34 +++--- .../ELF/{ELFTargetHandler.h => TargetHandler.h} | 41 ++++--- .../ELF/{ELFTargetLayout.h => TargetLayout.h} | 14 +-- .../ReaderWriter/ELF/{ELFTargets.h => Targets.h} | 10 +- .../ReaderWriter/ELF/{WriterELF.cpp => Writer.cpp} | 130 ++++++++++----------- lld/lib/ReaderWriter/ELF/{ELFWriter.h => Writer.h} | 19 ++- .../ELF/X86/{X86ELFTarget.h => X86Target.h} | 5 +- .../X86/{X86ELFTargetInfo.h => X86TargetInfo.h} | 23 ++-- .../HexagonELFTarget.h => X86_64/X86_64Target.h} | 5 +- .../ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp | 12 +- .../{X86_64ELFTargetInfo.h => X86_64TargetInfo.h} | 12 +- 28 files changed, 434 insertions(+), 441 deletions(-) rename lld/lib/ReaderWriter/ELF/{AtomsELF.h => Atoms.h} (88%) rename lld/lib/ReaderWriter/ELF/{ELFChunk.h => Chunk.h} (84%) rename lld/lib/ReaderWriter/ELF/{DefaultELFLayout.h => DefaultLayout.h} (89%) rename lld/lib/ReaderWriter/ELF/{DefaultELFTargetHandler.h => DefaultTargetHandler.h} (65%) rename lld/lib/ReaderWriter/ELF/{FileELF.h => File.h} (94%) rename lld/lib/ReaderWriter/ELF/{ELFHeaderChunks.h => HeaderChunks.h} (81%) rename lld/lib/ReaderWriter/ELF/{X86_64/X86_64ELFTarget.h => Hexagon/HexagonTarget.h} (69%) rename lld/lib/ReaderWriter/ELF/Hexagon/{HexagonELFTargetInfo.h => HexagonTargetInfo.h} (72%) rename lld/lib/ReaderWriter/ELF/{ELFLayout.h => Layout.h} (76%) rename lld/lib/ReaderWriter/ELF/PPC/{PPCELFTarget.h => PPCTarget.h} (69%) rename lld/lib/ReaderWriter/ELF/PPC/{PPCELFTargetInfo.h => PPCTargetInfo.h} (77%) rename lld/lib/ReaderWriter/ELF/{ReaderELF.cpp => Reader.cpp} (80%) rename lld/lib/ReaderWriter/ELF/{ELFSectionChunks.h => SectionChunks.h} (91%) rename lld/lib/ReaderWriter/ELF/{ELFSegmentChunks.h => SegmentChunks.h} (95%) rename lld/lib/ReaderWriter/ELF/{ELFTargetHandler.h => TargetHandler.h} (82%) rename lld/lib/ReaderWriter/ELF/{ELFTargetLayout.h => TargetLayout.h} (85%) rename lld/lib/ReaderWriter/ELF/{ELFTargets.h => Targets.h} (64%) rename lld/lib/ReaderWriter/ELF/{WriterELF.cpp => Writer.cpp} (72%) rename lld/lib/ReaderWriter/ELF/{ELFWriter.h => Writer.h} (68%) rename lld/lib/ReaderWriter/ELF/X86/{X86ELFTarget.h => X86Target.h} (69%) rename lld/lib/ReaderWriter/ELF/X86/{X86ELFTargetInfo.h => X86TargetInfo.h} (60%) rename lld/lib/ReaderWriter/ELF/{Hexagon/HexagonELFTarget.h => X86_64/X86_64Target.h} (68%) rename lld/lib/ReaderWriter/ELF/X86_64/{X86_64ELFTargetInfo.h => X86_64TargetInfo.h} (80%) diff --git a/lld/include/lld/ReaderWriter/ELFTargetInfo.h b/lld/include/lld/ReaderWriter/ELFTargetInfo.h index ee1631b..078ea1b 100644 --- a/lld/include/lld/ReaderWriter/ELFTargetInfo.h +++ b/lld/include/lld/ReaderWriter/ELFTargetInfo.h @@ -21,11 +21,11 @@ namespace lld { class DefinedAtom; class Reference; -namespace elf { template class ELFTargetHandler; } +namespace elf { template class TargetHandler; } -class ELFTargetHandlerBase { +class TargetHandlerBase { public: - virtual ~ELFTargetHandlerBase() {} + virtual ~TargetHandlerBase() {} }; class ELFTargetInfo : public TargetInfo { @@ -47,13 +47,12 @@ public: static std::unique_ptr create(const LinkerOptions &lo); template - lld::elf::ELFTargetHandler &getTargetHandler() const { - return static_cast< - lld::elf::ELFTargetHandler &>(*_targetHandler.get()); + lld::elf::TargetHandler &getTargetHandler() const { + return static_cast &>(*_targetHandler.get()); } protected: - std::unique_ptr _targetHandler; + std::unique_ptr _targetHandler; }; } // end namespace lld diff --git a/lld/lib/ReaderWriter/ELF/AtomsELF.h b/lld/lib/ReaderWriter/ELF/Atoms.h similarity index 88% rename from lld/lib/ReaderWriter/ELF/AtomsELF.h rename to lld/lib/ReaderWriter/ELF/Atoms.h index e35358b..cd6a1c9 100644 --- a/lld/lib/ReaderWriter/ELF/AtomsELF.h +++ b/lld/lib/ReaderWriter/ELF/Atoms.h @@ -1,4 +1,4 @@ -//===- lib/ReaderWriter/ELF/AtomELF.h -------------------------------------===// +//===- lib/ReaderWriter/ELF/Atoms.h ---------------------------------------===// // // The LLVM Linker // @@ -7,10 +7,10 @@ // //===----------------------------------------------------------------------===// -#ifndef LLD_READER_WRITER_ELF_ATOMS_ELF_H -#define LLD_READER_WRITER_ELF_ATOMS_ELF_H +#ifndef LLD_READER_WRITER_ELF_ATOMS_H +#define LLD_READER_WRITER_ELF_ATOMS_H -#include "ELFTargetHandler.h" +#include "TargetHandler.h" #include "lld/Core/LLVM.h" @@ -20,10 +20,10 @@ #include namespace lld { +namespace elf { +template class ELFFile; +template class TargetAtomHandler; -template class FileELF; - -namespace elf { template class ELFTargetAtomHandler; } /// \brief Relocation References: Defined Atoms may contain references that will /// need to be patched before the executable is written. template class ELFReference LLVM_FINAL : public Reference { @@ -93,12 +93,12 @@ class ELFAbsoluteAtom LLVM_FINAL : public AbsoluteAtom { typedef llvm::object::Elf_Sym_Impl Elf_Sym; public: - ELFAbsoluteAtom(const FileELF &file, llvm::StringRef name, + ELFAbsoluteAtom(const ELFFile &file, StringRef name, const Elf_Sym *symbol, uint64_t value) : _owningFile(file), _name(name), _symbol(symbol), _value(value) { } - virtual const class FileELF &file() const { + virtual const class ELFFile &file() const { return _owningFile; } virtual Scope scope() const { if (_symbol->st_other == llvm::ELF::STV_HIDDEN) @@ -109,7 +109,7 @@ public: return scopeGlobal; } - virtual llvm::StringRef name() const { + virtual StringRef name() const { return _name; } @@ -118,8 +118,8 @@ public: } private: - const FileELF &_owningFile; - llvm::StringRef _name; + const ELFFile &_owningFile; + StringRef _name; const Elf_Sym *_symbol; uint64_t _value; }; @@ -127,19 +127,19 @@ private: /// \brief ELFUndefinedAtom: These atoms store undefined symbols and are place /// holders that will be replaced by defined atoms later in the linking process. template -class ELFUndefinedAtom LLVM_FINAL : public UndefinedAtom { +class ELFUndefinedAtom LLVM_FINAL : public lld::UndefinedAtom { typedef llvm::object::Elf_Sym_Impl Elf_Sym; public: - ELFUndefinedAtom(const FileELF &file, llvm::StringRef name, + ELFUndefinedAtom(const ELFFile &file, StringRef name, const Elf_Sym *symbol) : _owningFile(file), _name(name), _symbol(symbol) {} - virtual const class FileELF &file() const { + virtual const class ELFFile &file() const { return _owningFile; } - virtual llvm::StringRef name() const { + virtual StringRef name() const { return _name; } @@ -154,8 +154,8 @@ public: } private: - const FileELF &_owningFile; - llvm::StringRef _name; + const ELFFile &_owningFile; + StringRef _name; const Elf_Sym *_symbol; }; @@ -167,9 +167,9 @@ class ELFDefinedAtom LLVM_FINAL : public DefinedAtom { typedef llvm::object::Elf_Shdr_Impl Elf_Shdr; public: - ELFDefinedAtom(const FileELF &file, - llvm::StringRef symbolName, - llvm::StringRef sectionName, + ELFDefinedAtom(const ELFFile &file, + StringRef symbolName, + StringRef sectionName, const Elf_Sym *symbol, const Elf_Shdr *section, llvm::ArrayRef contentData, @@ -190,11 +190,11 @@ public: _ordinal = ++orderNumber; } - virtual const class FileELF &file() const { + virtual const class ELFFile &file() const { return _owningFile; } - virtual llvm::StringRef name() const { + virtual StringRef name() const { return _symbolName; } @@ -246,10 +246,10 @@ public: _symbol->st_shndx < llvm::ELF::SHN_HIPROC) { const ELFTargetInfo &eti = (_owningFile.getTargetInfo()); - elf::ELFTargetHandler &elfTargetHandler = + TargetHandler &TargetHandler = eti.getTargetHandler(); - elf::ELFTargetAtomHandler &elfAtomHandler = - elfTargetHandler.targetAtomHandler(); + TargetAtomHandler &elfAtomHandler = + TargetHandler.targetAtomHandler(); return elfAtomHandler.contentType(this); } @@ -315,7 +315,7 @@ public: return sectionCustomRequired; } - virtual llvm::StringRef customSectionName() const { + virtual StringRef customSectionName() const { if ((contentType() == typeZeroFill) || (_symbol->st_shndx == llvm::ELF::SHN_COMMON)) return ".bss"; @@ -418,9 +418,9 @@ public: private: - const FileELF &_owningFile; - llvm::StringRef _symbolName; - llvm::StringRef _sectionName; + const ELFFile &_owningFile; + StringRef _symbolName; + StringRef _sectionName; const Elf_Sym *_symbol; const Elf_Shdr *_section; /// \brief Holds the bits that make up the atom. @@ -432,5 +432,7 @@ private: std::vector*> & _referenceList; }; -} // namespace lld +} // end namespace elf +} // end namespace lld + #endif diff --git a/lld/lib/ReaderWriter/ELF/CMakeLists.txt b/lld/lib/ReaderWriter/ELF/CMakeLists.txt index ba10c66..05deea1 100644 --- a/lld/lib/ReaderWriter/ELF/CMakeLists.txt +++ b/lld/lib/ReaderWriter/ELF/CMakeLists.txt @@ -2,9 +2,9 @@ add_lld_library(lldELF ELFTargetInfo.cpp HexagonReference.cpp PPCReference.cpp - ReaderELF.cpp + Reader.cpp ReferenceKinds.cpp - WriterELF.cpp + Writer.cpp X86Reference.cpp X86_64Reference.cpp ) diff --git a/lld/lib/ReaderWriter/ELF/ELFChunk.h b/lld/lib/ReaderWriter/ELF/Chunk.h similarity index 84% rename from lld/lib/ReaderWriter/ELF/ELFChunk.h rename to lld/lib/ReaderWriter/ELF/Chunk.h index cfed0ec7..3128183 100644 --- a/lld/lib/ReaderWriter/ELF/ELFChunk.h +++ b/lld/lib/ReaderWriter/ELF/Chunk.h @@ -1,4 +1,4 @@ -//===- lib/ReaderWriter/ELF/ELFChunks.h ---------------------------------===// +//===- lib/ReaderWriter/ELF/Chunks.h --------------------------------------===// // // The LLVM Linker // @@ -7,8 +7,10 @@ // //===----------------------------------------------------------------------===// -#ifndef LLD_READER_WRITER_ELF_CHUNKS_H_ -#define LLD_READER_WRITER_ELF_CHUNKS_H_ +#ifndef LLD_READER_WRITER_ELF_CHUNKS_H +#define LLD_READER_WRITER_ELF_CHUNKS_H + +#include "lld/Core/LLVM.h" #include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/StringRef.h" @@ -32,13 +34,13 @@ public: /// \brief Describes the type of Chunk enum Kind { - K_ELFHeader, // ELF Header - K_ELFProgramHeader, // Program Header + K_Header, // ELF Header + K_ProgramHeader, // Program Header K_ELFSegment, // Segment K_ELFSection, // Section - K_ELFSectionHeader // Section header + K_SectionHeader // Section header }; - Chunk(llvm::StringRef name, Kind kind, const ELFTargetInfo &ti) + Chunk(StringRef name, Kind kind, const ELFTargetInfo &ti) : _name(name), _kind(kind), _fsize(0), _msize(0), _align2(0), _order(0), _ordinal(1), _start(0), _fileoffset(0), _targetInfo(ti) { } @@ -48,7 +50,7 @@ public: return false; } // The name of the chunk - llvm::StringRef name() const { return _name; } + StringRef name() const { return _name; } // Kind of chunk Kind kind() const { return _kind; } uint64_t fileSize() const { return _fsize; } @@ -76,7 +78,7 @@ public: virtual void finalize() = 0; protected: - llvm::StringRef _name; + StringRef _name; Kind _kind; uint64_t _fsize; uint64_t _msize; @@ -88,7 +90,7 @@ protected: const ELFTargetInfo &_targetInfo; }; -} // elf -} // lld +} // end namespace elf +} // end namespace lld -#endif // LLD_READER_WRITER_ELF_CHUNKS_H_ +#endif diff --git a/lld/lib/ReaderWriter/ELF/DefaultELFLayout.h b/lld/lib/ReaderWriter/ELF/DefaultLayout.h similarity index 89% rename from lld/lib/ReaderWriter/ELF/DefaultELFLayout.h rename to lld/lib/ReaderWriter/ELF/DefaultLayout.h index cd05d2c..090271e 100644 --- a/lld/lib/ReaderWriter/ELF/DefaultELFLayout.h +++ b/lld/lib/ReaderWriter/ELF/DefaultLayout.h @@ -1,4 +1,4 @@ -//===- lib/ReaderWriter/ELF/DefaultELFLayout.h ---------------------------===// +//===- lib/ReaderWriter/ELF/DefaultLayout.h -------------------------------===// // // The LLVM Linker // @@ -7,14 +7,14 @@ // //===----------------------------------------------------------------------===// -#ifndef LLD_READER_WRITER_DEFAULT_ELF_LAYOUT_H_ -#define LLD_READER_WRITER_DEFAULT_ELF_LAYOUT_H_ +#ifndef LLD_READER_WRITER_ELF_DEFAULT_LAYOUT_H +#define LLD_READER_WRITER_ELF_DEFAULT_LAYOUT_H -#include "ELFChunk.h" -#include "ELFHeaderChunks.h" -#include "ELFLayout.h" -#include "ELFSectionChunks.h" -#include "ELFSegmentChunks.h" +#include "Chunk.h" +#include "HeaderChunks.h" +#include "Layout.h" +#include "SectionChunks.h" +#include "SegmentChunks.h" #include "lld/Core/LinkerOptions.h" @@ -32,16 +32,14 @@ #include #include -/// \brief The DefaultELFLayout class is used by the Writer to arrange -/// sections and segments in the order determined by the target ELF -/// format. The writer creates a single instance of the DefaultELFLayout -/// class - namespace lld { namespace elf { - +/// \brief The DefaultLayout class is used by the Writer to arrange +/// sections and segments in the order determined by the target ELF +/// format. The writer creates a single instance of the DefaultLayout +/// class template -class DefaultELFLayout : public ELFLayout { +class DefaultLayout : public Layout { public: // The order in which the sections appear in the output file @@ -163,7 +161,7 @@ public: typedef typename std::vector::iterator AbsoluteAtomIterT; - DefaultELFLayout(const ELFTargetInfo &ti) : _targetInfo(ti) {} + DefaultLayout(const ELFTargetInfo &ti) : _targetInfo(ti) {} /// \brief Return the section order for a input section virtual SectionOrder getSectionOrder @@ -176,7 +174,7 @@ public: const int32_t contentType); /// \brief Gets the segment for a output section - virtual ELFLayout::SegmentType getSegmentType(Section *section) const; + virtual Layout::SegmentType getSegmentType(Section *section) const; /// \brief Returns true/false depending on whether the section has a Output // segment or not @@ -230,11 +228,11 @@ public: return false; } - inline void setELFHeader(ELFHeader *e) { - _elfHeader = e; + inline void setHeader(Header *e) { + _header = e; } - inline void setProgramHeader(ELFProgramHeader *p) { + inline void setProgramHeader(ProgramHeader *p) { _programHeader = p; } @@ -244,19 +242,19 @@ public: inline range segments() { return _segments; } - inline ELFHeader *elfHeader() { - return _elfHeader; + inline Header *getHeader() { + return _header; } - inline ELFProgramHeader *elfProgramHeader() { + inline ProgramHeader *getProgramHeader() { return _programHeader; } - ELFRelocationTable *getRelocationTable() { + RelocationTable *getRelocationTable() { // Only create the relocation table if it is needed. if (!_relocationTable) { _relocationTable = new (_allocator) - ELFRelocationTable(_targetInfo, ".rela.plt", ORDER_REL); + RelocationTable(_targetInfo, ".rela.plt", ORDER_REL); addSection(_relocationTable); } return _relocationTable; @@ -269,17 +267,17 @@ private: std::vector *> _sections; std::vector *> _segments; std::vector *> _mergedSections; - ELFHeader *_elfHeader; - ELFProgramHeader *_programHeader; - ELFRelocationTable *_relocationTable; + Header *_header; + ProgramHeader *_programHeader; + RelocationTable *_relocationTable; std::vector _absoluteAtoms; llvm::BumpPtrAllocator _allocator; const ELFTargetInfo &_targetInfo; }; template -ELFLayout::SectionOrder -DefaultELFLayout::getSectionOrder(const StringRef name, +Layout::SectionOrder +DefaultLayout::getSectionOrder(const StringRef name, int32_t contentType, int32_t contentPermissions) { @@ -322,7 +320,7 @@ DefaultELFLayout::getSectionOrder(const StringRef name, /// \brief This maps the input sections to the output section names template StringRef -DefaultELFLayout::getSectionName(const StringRef name, +DefaultLayout::getSectionName(const StringRef name, const int32_t contentType) { if (contentType == DefinedAtom::typeZeroFill) return ".bss"; @@ -335,8 +333,8 @@ DefaultELFLayout::getSectionName(const StringRef name, /// \brief Gets the segment for a output section template -ELFLayout::SegmentType -DefaultELFLayout::getSegmentType(Section *section) const { +Layout::SegmentType +DefaultLayout::getSegmentType(Section *section) const { switch(section->order()) { case ORDER_INTERP: return llvm::ELF::PT_INTERP; @@ -379,7 +377,7 @@ DefaultELFLayout::getSegmentType(Section *section) const { template bool -DefaultELFLayout::hasOutputSegment(Section *section) { +DefaultLayout::hasOutputSegment(Section *section) { switch(section->order()) { case ORDER_INTERP: case ORDER_HASH: @@ -412,13 +410,13 @@ DefaultELFLayout::hasOutputSegment(Section *section) { template error_code -DefaultELFLayout::addAtom(const Atom *atom) { +DefaultLayout::addAtom(const Atom *atom) { if (const DefinedAtom *definedAtom = dyn_cast(atom)) { const StringRef sectionName = getSectionName( definedAtom->customSectionName(), definedAtom->contentType()); - const lld::DefinedAtom::ContentPermissions permissions = + const DefinedAtom::ContentPermissions permissions = definedAtom->permissions(); - const lld::DefinedAtom::ContentType contentType = + const DefinedAtom::ContentType contentType = definedAtom->contentType(); const SectionKey sectionKey(sectionName, permissions); Section *section; @@ -453,7 +451,7 @@ DefaultELFLayout::addAtom(const Atom *atom) { /// Merge sections with the same name into a MergedSections template void -DefaultELFLayout::mergeSimiliarSections() { +DefaultLayout::mergeSimiliarSections() { MergedSections *mergedSection; for (auto &si : _sections) { @@ -476,7 +474,7 @@ DefaultELFLayout::mergeSimiliarSections() { template void -DefaultELFLayout::assignSectionsToSegments() { +DefaultLayout::assignSectionsToSegments() { // sort the sections by their order as defined by the layout std::stable_sort(_sections.begin(), _sections.end(), [](Chunk *A, Chunk *B) { @@ -524,7 +522,7 @@ DefaultELFLayout::assignSectionsToSegments() { template void -DefaultELFLayout::assignFileOffsets() { +DefaultLayout::assignFileOffsets() { std::sort(_segments.begin(), _segments.end(), Segment::compareSegments); int ordinal = 0; @@ -541,7 +539,7 @@ DefaultELFLayout::assignFileOffsets() { template void -DefaultELFLayout::assignVirtualAddress() { +DefaultLayout::assignVirtualAddress() { if (_segments.empty()) return; @@ -553,7 +551,7 @@ DefaultELFLayout::assignVirtualAddress() { // at runtime. To do this we simply prepend them to the first Segment and // let the layout logic take care of it. _segments[0]->prepend(_programHeader); - _segments[0]->prepend(_elfHeader); + _segments[0]->prepend(_header); bool newSegmentHeaderAdded = true; while (true) { @@ -589,7 +587,7 @@ DefaultELFLayout::assignVirtualAddress() { // Fix the offsets of all the atoms within a section for (auto &si : _sections) { section = dyn_cast>(si); - if (section && DefaultELFLayout::hasOutputSegment(section)) + if (section && DefaultLayout::hasOutputSegment(section)) section->assignOffsets(section->fileOffset()); } // Set the size of the merged Sections @@ -632,7 +630,7 @@ DefaultELFLayout::assignVirtualAddress() { template void -DefaultELFLayout::assignOffsetsForMiscSections() { +DefaultLayout::assignOffsetsForMiscSections() { uint64_t fileoffset = 0; uint64_t size = 0; for (auto si : _segments) { @@ -643,7 +641,7 @@ DefaultELFLayout::assignOffsetsForMiscSections() { Section *section; for (auto si : _sections) { section = dyn_cast>(si); - if (section && DefaultELFLayout::hasOutputSegment(section)) + if (section && DefaultLayout::hasOutputSegment(section)) continue; fileoffset = llvm::RoundUpToAlignment(fileoffset, si->align2()); si->setFileOffset(fileoffset); @@ -651,8 +649,7 @@ DefaultELFLayout::assignOffsetsForMiscSections() { fileoffset += si->fileSize(); } } +} // end namespace elf +} // end namespace lld -} // elf -} // lld - -#endif // LLD_READER_WRITER_DEFAULT_ELF_LAYOUT_H_ +#endif diff --git a/lld/lib/ReaderWriter/ELF/DefaultELFTargetHandler.h b/lld/lib/ReaderWriter/ELF/DefaultTargetHandler.h similarity index 65% rename from lld/lib/ReaderWriter/ELF/DefaultELFTargetHandler.h rename to lld/lib/ReaderWriter/ELF/DefaultTargetHandler.h index acbe55f..938b80f 100644 --- a/lld/lib/ReaderWriter/ELF/DefaultELFTargetHandler.h +++ b/lld/lib/ReaderWriter/ELF/DefaultTargetHandler.h @@ -1,4 +1,4 @@ -//===- lib/ReaderWriter/ELF/DefaultELFTargetHandler.h ---------------------===// +//===- lib/ReaderWriter/ELF/DefaultTargetHandler.h ------------------------===// // // The LLVM Linker // @@ -6,11 +6,12 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef LLD_READER_WRITER_DEFAULT_ELF_TARGETHANDLER_H -#define LLD_READER_WRITER_DEFAULT_ELF_TARGETHANDLER_H -#include "DefaultELFLayout.h" -#include "ELFTargetHandler.h" +#ifndef LLD_READER_WRITER_ELF_DEFAULT_TARGETHANDLER_H +#define LLD_READER_WRITER_ELF_DEFAULT_TARGETHANDLER_H + +#include "DefaultLayout.h" +#include "TargetHandler.h" #include "lld/Core/LinkerOptions.h" #include "lld/ReaderWriter/ELFTargetInfo.h" @@ -20,28 +21,27 @@ namespace lld { namespace elf { - template -class DefaultELFTargetHandler : public ELFTargetHandler { +class DefaultTargetHandler : public TargetHandler { public: - DefaultELFTargetHandler(ELFTargetInfo &targetInfo) - : ELFTargetHandler(targetInfo) { + DefaultTargetHandler(ELFTargetInfo &targetInfo) + : TargetHandler(targetInfo) { } - bool doesOverrideELFHeader() { return false; } + bool doesOverrideHeader() { return false; } - void setELFHeaderInfo(ELFHeader *elfHeader) { + void setHeaderInfo(Header *Header) { llvm_unreachable("Target should provide implementation for function "); } - /// ELFTargetLayout - ELFTargetLayout &targetLayout() { + /// TargetLayout + TargetLayout &targetLayout() { llvm_unreachable("Target should provide implementation for function "); } - /// ELFTargetAtomHandler - ELFTargetAtomHandler &targetAtomHandler() { + /// TargetAtomHandler + TargetAtomHandler &targetAtomHandler() { llvm_unreachable("Target should provide implementation for function "); } @@ -61,8 +61,7 @@ public: /// symbols over to small data, this would also be used void allocateCommons() {} }; - -} // elf -} // lld +} // end namespace elf +} // end namespace lld #endif diff --git a/lld/lib/ReaderWriter/ELF/ELFTargetInfo.cpp b/lld/lib/ReaderWriter/ELF/ELFTargetInfo.cpp index 97526aa..68aa19b 100644 --- a/lld/lib/ReaderWriter/ELF/ELFTargetInfo.cpp +++ b/lld/lib/ReaderWriter/ELF/ELFTargetInfo.cpp @@ -9,8 +9,8 @@ #include "lld/ReaderWriter/ELFTargetInfo.h" -#include "ELFTargetHandler.h" -#include "ELFTargets.h" +#include "TargetHandler.h" +#include "Targets.h" #include "lld/Core/LinkerOptions.h" @@ -55,15 +55,15 @@ uint16_t ELFTargetInfo::getOutputMachine() const { std::unique_ptr ELFTargetInfo::create(const LinkerOptions &lo) { switch (llvm::Triple(llvm::Triple::normalize(lo._target)).getArch()) { case llvm::Triple::x86: - return std::unique_ptr(new lld::elf::X86ELFTargetInfo(lo)); + return std::unique_ptr(new lld::elf::X86TargetInfo(lo)); case llvm::Triple::x86_64: return std::unique_ptr< - ELFTargetInfo>(new lld::elf::X86_64ELFTargetInfo(lo)); + ELFTargetInfo>(new lld::elf::X86_64TargetInfo(lo)); case llvm::Triple::hexagon: return std::unique_ptr< - ELFTargetInfo>(new lld::elf::HexagonELFTargetInfo(lo)); + ELFTargetInfo>(new lld::elf::HexagonTargetInfo(lo)); case llvm::Triple::ppc: - return std::unique_ptr(new lld::elf::PPCELFTargetInfo(lo)); + return std::unique_ptr(new lld::elf::PPCTargetInfo(lo)); default: return std::unique_ptr(); } diff --git a/lld/lib/ReaderWriter/ELF/ExecutableAtoms.h b/lld/lib/ReaderWriter/ELF/ExecutableAtoms.h index 3276bb4..525d360 100644 --- a/lld/lib/ReaderWriter/ELF/ExecutableAtoms.h +++ b/lld/lib/ReaderWriter/ELF/ExecutableAtoms.h @@ -1,4 +1,4 @@ -//===- lib/ReaderWriter/ELF/ExecutableAtoms.h ----------------------------===// +//===- lib/ReaderWriter/ELF/ExecutableAtoms.h -----------------------------===// // // The LLVM Linker // @@ -7,11 +7,11 @@ // //===----------------------------------------------------------------------===// -#ifndef LLD_READER_WRITER_ELF_EXECUTABLE_ATOM_H_ -#define LLD_READER_WRITER_ELF_EXECUTABLE_ATOM_H_ +#ifndef LLD_READER_WRITER_ELF_EXECUTABLE_ATOM_H +#define LLD_READER_WRITER_ELF_EXECUTABLE_ATOM_H -#include "AtomsELF.h" -#include "FileELF.h" +#include "Atoms.h" +#include "File.h" #include "lld/Core/DefinedAtom.h" #include "lld/Core/File.h" @@ -21,16 +21,15 @@ namespace lld { namespace elf { - /// \brief All atoms are owned by a File. To add linker specific atoms /// the atoms need to be inserted to a file called (CRuntimeFile) which /// are basically additional symbols required by libc and other runtime /// libraries part of executing a program. This class provides support /// for adding absolute symbols and undefined symbols -template class CRuntimeFileELF : public FileELF { +template class CRuntimeFile : public ELFFile { public: typedef llvm::object::Elf_Sym_Impl Elf_Sym; - CRuntimeFileELF(const ELFTargetInfo &ti) : FileELF(ti, "C runtime") {} + CRuntimeFile(const ELFTargetInfo &ti) : ELFFile(ti, "C runtime") {} /// \brief add a global absolute atom void addAbsoluteAtom(const StringRef symbolName) { @@ -42,25 +41,21 @@ public: llvm::ELF::STT_OBJECT); symbol->st_other = llvm::ELF::STV_DEFAULT; symbol->st_size = 0; - auto *newAtom = new (_allocator.Allocate< - ELFAbsoluteAtom > ()) - ELFAbsoluteAtom( - *this, symbolName, symbol, -1); + auto *newAtom = + new (_allocator) ELFAbsoluteAtom(*this, symbolName, symbol, -1); _absoluteAtoms._atoms.push_back(newAtom); } /// \brief add an undefined atom void addUndefinedAtom(const StringRef symbolName) { - Elf_Sym *symbol = new(_allocator.Allocate()) Elf_Sym; + Elf_Sym *symbol = new (_allocator) Elf_Sym; symbol->st_name = 0; symbol->st_value = 0; symbol->st_shndx = llvm::ELF::SHN_UNDEF; symbol->st_other = llvm::ELF::STV_DEFAULT; symbol->st_size = 0; - auto *newAtom = new (_allocator.Allocate< - ELFUndefinedAtom > ()) - ELFUndefinedAtom( - *this, symbolName, symbol); + auto *newAtom = + new (_allocator) ELFUndefinedAtom(*this, symbolName, symbol); _undefinedAtoms._atoms.push_back(newAtom); } @@ -92,8 +87,7 @@ private: File::atom_collection_vector _sharedLibraryAtoms; File::atom_collection_vector _absoluteAtoms; }; +} // end namespace elf +} // end namespace lld -} // namespace elf -} // namespace lld - -#endif // LLD_READER_WRITER_ELF_EXECUTABLE_ATOM_H_ +#endif diff --git a/lld/lib/ReaderWriter/ELF/FileELF.h b/lld/lib/ReaderWriter/ELF/File.h similarity index 94% rename from lld/lib/ReaderWriter/ELF/FileELF.h rename to lld/lib/ReaderWriter/ELF/File.h index 7b66a78..7413cc4 100644 --- a/lld/lib/ReaderWriter/ELF/FileELF.h +++ b/lld/lib/ReaderWriter/ELF/File.h @@ -1,4 +1,4 @@ -//===- lib/ReaderWriter/ELF/FileELF.h ------------------------------------===// +//===- lib/ReaderWriter/ELF/File.h ----------------------------------------===// // // The LLVM Linker // @@ -6,14 +6,13 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -/// \brief Read a binary, find out based on the symbol table contents what kind -/// of symbol it is and create corresponding atoms for it -#ifndef LLD_READER_WRITER_FILE_ELF_H -#define LLD_READER_WRITER_FILE_ELF_H +#ifndef LLD_READER_WRITER_ELF_FILE_H +#define LLD_READER_WRITER_ELF_FILE_H -#include "AtomsELF.h" +#include "Atoms.h" +#include "lld/Core/File.h" #include "lld/Core/Reference.h" #include "lld/ReaderWriter/ELFTargetInfo.h" #include "lld/ReaderWriter/ReaderArchive.h" @@ -39,19 +38,21 @@ #include namespace lld { - -template class FileELF : public File { +namespace elf { +/// \brief Read a binary, find out based on the symbol table contents what kind +/// of symbol it is and create corresponding atoms for it +template class ELFFile : public File { typedef llvm::object::Elf_Sym_Impl Elf_Sym; typedef llvm::object::Elf_Shdr_Impl Elf_Shdr; typedef llvm::object::Elf_Rel_Impl Elf_Rel; typedef llvm::object::Elf_Rel_Impl Elf_Rela; public: - FileELF(const ELFTargetInfo &ti, const StringRef name) + ELFFile(const ELFTargetInfo &ti, const StringRef name) : File(name), _elfTargetInfo(ti) { } - FileELF(const ELFTargetInfo &ti, std::unique_ptr MB, + ELFFile(const ELFTargetInfo &ti, std::unique_ptr MB, llvm::error_code &EC) : File(MB->getBufferIdentifier()), _elfTargetInfo(ti) { static uint32_t lastOrdinal = 0; @@ -87,7 +88,7 @@ public: const Elf_Shdr *section = _objFile->getElfSection(sit); if (section->sh_type == llvm::ELF::SHT_RELA) { - llvm::StringRef sectionName; + StringRef sectionName; if ((EC = _objFile->getSectionName(section, sectionName))) return; // Get rid of the leading .rela so Atoms can use their own section @@ -104,7 +105,7 @@ public: } if (section->sh_type == llvm::ELF::SHT_REL) { - llvm::StringRef sectionName; + StringRef sectionName; if ((EC = _objFile->getSectionName(section, sectionName))) return; // Get rid of the leading .rel so Atoms can use their own section @@ -136,7 +137,7 @@ public: const Elf_Shdr *section = _objFile->getElfSection(sit); const Elf_Sym *symbol = _objFile->getElfSymbol(it); - llvm::StringRef symbolName; + StringRef symbolName; if ((EC = _objFile->getSymbolName(section, symbol, symbolName))) return; @@ -185,13 +186,13 @@ public: if ((EC = _objFile->getSectionContents(i.first, sectionContents))) return; - llvm::StringRef sectionName; + StringRef sectionName; if ((EC = _objFile->getSectionName(i.first, sectionName))) return; // i.first is the section the symbol lives in for (auto si = symbols.begin(), se = symbols.end(); si != se; ++si) { - llvm::StringRef symbolName; + StringRef symbolName; if ((EC = _objFile->getSymbolName(i.first, *si, symbolName))) return; @@ -202,10 +203,10 @@ public: if (((*si)->st_shndx >= llvm::ELF::SHN_LOPROC) && ((*si)->st_shndx <= llvm::ELF::SHN_HIPROC)) { - elf::ELFTargetHandler &elfTargetHandler = + TargetHandler &TargetHandler = _elfTargetInfo.getTargetHandler(); - elf::ELFTargetAtomHandler &elfAtomHandler = - elfTargetHandler.targetAtomHandler(); + TargetAtomHandler &elfAtomHandler = + TargetHandler.targetAtomHandler(); c = elfAtomHandler.contentType(*si); if (c == DefinedAtom::typeZeroFill) @@ -331,6 +332,7 @@ private: llvm::BumpPtrAllocator _readerStorage; const ELFTargetInfo &_elfTargetInfo; }; -} // lld +} // end namespace elf +} // end namespace lld #endif diff --git a/lld/lib/ReaderWriter/ELF/ELFHeaderChunks.h b/lld/lib/ReaderWriter/ELF/HeaderChunks.h similarity index 81% rename from lld/lib/ReaderWriter/ELF/ELFHeaderChunks.h rename to lld/lib/ReaderWriter/ELF/HeaderChunks.h index 50f2dba..e2512b5 100644 --- a/lld/lib/ReaderWriter/ELF/ELFHeaderChunks.h +++ b/lld/lib/ReaderWriter/ELF/HeaderChunks.h @@ -1,4 +1,4 @@ -//===- lib/ReaderWriter/ELF/ELFHeaderChunks.h -----------------------------===// +//===- lib/ReaderWriter/ELF/HeaderChunks.h --------------------------------===// // // The LLVM Linker // @@ -7,10 +7,10 @@ // //===----------------------------------------------------------------------===// -#ifndef LLD_READER_WRITER_ELF_HEADER_CHUNKS_H_ -#define LLD_READER_WRITER_ELF_HEADER_CHUNKS_H_ +#ifndef LLD_READER_WRITER_ELF_HEADER_CHUNKS_H +#define LLD_READER_WRITER_ELF_HEADER_CHUNKS_H -#include "ELFSegmentChunks.h" +#include "SegmentChunks.h" #include "llvm/Object/ELF.h" #include "llvm/Support/Allocator.h" @@ -19,17 +19,16 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileOutputBuffer.h" -/// \brief An ELFHeader represents the Elf[32/64]_Ehdr structure at the +/// \brief An Header represents the Elf[32/64]_Ehdr structure at the /// start of an ELF executable file. namespace lld { namespace elf { - template -class ELFHeader : public Chunk { +class Header : public Chunk { public: typedef llvm::object::Elf_Ehdr_Impl Elf_Ehdr; - ELFHeader(const ELFTargetInfo &); + Header(const ELFTargetInfo &); void e_ident(int I, unsigned char C) { _eh.e_ident[I] = C; } void e_type(uint16_t type) { _eh.e_type = type; } @@ -48,7 +47,7 @@ public: uint64_t fileSize() { return sizeof (Elf_Ehdr); } static inline bool classof(const Chunk *c) { - return c->Kind() == Chunk::K_ELFHeader; + return c->Kind() == Chunk::K_Header; } void write(ELFWriter *writer, llvm::FileOutputBuffer &buffer); @@ -60,8 +59,8 @@ private: }; template -ELFHeader::ELFHeader(const ELFTargetInfo &ti) - : Chunk("elfhdr", Chunk::K_ELFHeader, ti) { +Header::Header(const ELFTargetInfo &ti) + : Chunk("elfhdr", Chunk::K_Header, ti) { this->_align2 = ELFT::Is64Bits ? 8 : 4; this->_fsize = sizeof(Elf_Ehdr); this->_msize = sizeof(Elf_Ehdr); @@ -75,16 +74,16 @@ ELFHeader::ELFHeader(const ELFTargetInfo &ti) } template -void ELFHeader::write(ELFWriter *writer, llvm::FileOutputBuffer &buffer) { +void Header::write(ELFWriter *writer, llvm::FileOutputBuffer &buffer) { uint8_t *chunkBuffer = buffer.getBufferStart(); uint8_t *atomContent = chunkBuffer + this->fileOffset(); memcpy(atomContent, &_eh, fileSize()); } -/// \brief An ELFProgramHeader represents the Elf[32/64]_Phdr structure at the +/// \brief An ProgramHeader represents the Elf[32/64]_Phdr structure at the /// start of an ELF executable file. template -class ELFProgramHeader : public Chunk { +class ProgramHeader : public Chunk { public: typedef llvm::object::Elf_Phdr_Impl Elf_Phdr; typedef typename std::vector::iterator PhIterT; @@ -110,8 +109,8 @@ public: uint64_t _flagsClear; }; - ELFProgramHeader(const ELFTargetInfo &ti) - : Chunk("elfphdr", Chunk::K_ELFProgramHeader, ti) { + ProgramHeader(const ELFTargetInfo &ti) + : Chunk("elfphdr", Chunk::K_ProgramHeader, ti) { this->_align2 = ELFT::Is64Bits ? 8 : 4; resetProgramHeaders(); } @@ -127,7 +126,7 @@ public: } static inline bool classof(const Chunk *c) { - return c->Kind() == Chunk::K_ELFProgramHeader; + return c->Kind() == Chunk::K_ProgramHeader; } void write(ELFWriter *writer, llvm::FileOutputBuffer &buffer); @@ -164,7 +163,7 @@ private: template bool -ELFProgramHeader::addSegment(Segment *segment) { +ProgramHeader::addSegment(Segment *segment) { Elf_Phdr *phdr = nullptr; bool ret = false; @@ -195,7 +194,7 @@ ELFProgramHeader::addSegment(Segment *segment) { } template -void ELFProgramHeader::write(ELFWriter *writer, +void ProgramHeader::write(ELFWriter *writer, llvm::FileOutputBuffer &buffer) { uint8_t *chunkBuffer = buffer.getBufferStart(); uint8_t *dest = chunkBuffer + this->fileOffset(); @@ -205,24 +204,24 @@ void ELFProgramHeader::write(ELFWriter *writer, } } -/// \brief An ELFSectionHeader represents the Elf[32/64]_Shdr structure +/// \brief An SectionHeader represents the Elf[32/64]_Shdr structure /// at the end of the file template -class ELFSectionHeader : public Chunk { +class SectionHeader : public Chunk { public: typedef llvm::object::Elf_Shdr_Impl Elf_Shdr; - ELFSectionHeader(const ELFTargetInfo &, int32_t order); + SectionHeader(const ELFTargetInfo &, int32_t order); void appendSection(MergedSections *section); void updateSection(Section *section); static inline bool classof(const Chunk *c) { - return c->getChunkKind() == Chunk::K_ELFSectionHeader; + return c->getChunkKind() == Chunk::K_SectionHeader; } - void setStringSection(ELFStringTable *s) { + void setStringSection(StringTable *s) { _stringSection = s; } @@ -243,14 +242,14 @@ public: } private: - ELFStringTable *_stringSection; + StringTable *_stringSection; std::vector _sectionInfo; llvm::BumpPtrAllocator _sectionAllocate; }; template -ELFSectionHeader::ELFSectionHeader(const ELFTargetInfo &ti, int32_t order) - : Chunk("shdr", Chunk::K_ELFSectionHeader, ti) { +SectionHeader::SectionHeader(const ELFTargetInfo &ti, int32_t order) + : Chunk("shdr", Chunk::K_SectionHeader, ti) { this->_fsize = 0; this->_align2 = 8; this->setOrder(order); @@ -263,7 +262,7 @@ ELFSectionHeader::ELFSectionHeader(const ELFTargetInfo &ti, int32_t order) template void -ELFSectionHeader::appendSection(MergedSections *section) { +SectionHeader::appendSection(MergedSections *section) { Elf_Shdr *shdr = new (_sectionAllocate.Allocate()) Elf_Shdr; shdr->sh_name = _stringSection->addString(section->name()); shdr->sh_type = section->type(); @@ -280,7 +279,7 @@ ELFSectionHeader::appendSection(MergedSections *section) { template void -ELFSectionHeader::updateSection(Section *section) { +SectionHeader::updateSection(Section *section) { Elf_Shdr *shdr = _sectionInfo[section->ordinal()]; shdr->sh_type = section->type(); shdr->sh_flags = section->flags(); @@ -294,7 +293,7 @@ ELFSectionHeader::updateSection(Section *section) { } template -void ELFSectionHeader::write(ELFWriter *writer, +void SectionHeader::write(ELFWriter *writer, llvm::FileOutputBuffer &buffer) { uint8_t *chunkBuffer = buffer.getBufferStart(); uint8_t *dest = chunkBuffer + this->fileOffset(); @@ -304,8 +303,7 @@ void ELFSectionHeader::write(ELFWriter *writer, } _stringSection->write(writer, buffer); } +} // end namespace elf +} // end namespace lld -} // elf -} // lld - -#endif // LLD_READER_WRITER_ELF_HEADER_CHUNKS_H_ +#endif diff --git a/lld/lib/ReaderWriter/ELF/X86_64/X86_64ELFTarget.h b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTarget.h similarity index 69% rename from lld/lib/ReaderWriter/ELF/X86_64/X86_64ELFTarget.h rename to lld/lib/ReaderWriter/ELF/Hexagon/HexagonTarget.h index 383cfaf..8d7e610 100644 --- a/lld/lib/ReaderWriter/ELF/X86_64/X86_64ELFTarget.h +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTarget.h @@ -1,4 +1,4 @@ -//===- lib/ReaderWriter/ELF/Hexagon/X86ELFTarget.h -----------------------===// +//===- lib/ReaderWriter/ELF/Hexagon/HexagonTarget.h -----------------------===// // // The LLVM Linker // @@ -7,4 +7,4 @@ // //===----------------------------------------------------------------------===// -#include "X86_64ELFTargetInfo.h" +#include "HexagonTargetInfo.h" diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFTargetInfo.h b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h similarity index 72% rename from lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFTargetInfo.h rename to lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h index 7201a89..b5dfeb8 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFTargetInfo.h +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h @@ -15,15 +15,15 @@ #include "llvm/Object/ELF.h" #include "llvm/Support/ELF.h" -#include "DefaultELFTargetHandler.h" +#include "DefaultTargetHandler.h" namespace lld { namespace elf { -class HexagonELFTargetInfo LLVM_FINAL : public ELFTargetInfo { +class HexagonTargetInfo LLVM_FINAL : public ELFTargetInfo { public: - HexagonELFTargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) { - _targetHandler = std::unique_ptr( - new DefaultELFTargetHandler( + new DefaultTargetHandler >(*this)); } diff --git a/lld/lib/ReaderWriter/ELF/ELFLayout.h b/lld/lib/ReaderWriter/ELF/Layout.h similarity index 76% rename from lld/lib/ReaderWriter/ELF/ELFLayout.h rename to lld/lib/ReaderWriter/ELF/Layout.h index 48754ab..5ff59ab 100644 --- a/lld/lib/ReaderWriter/ELF/ELFLayout.h +++ b/lld/lib/ReaderWriter/ELF/Layout.h @@ -1,4 +1,4 @@ -//===- lib/ReaderWriter/ELF/ELFLayout.h ---------------------------------===// +//===- lib/ReaderWriter/ELF/Layout.h --------------------------------------===// // // The LLVM Linker // @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLD_READER_WRITER_ELF_LAYOUT_H_ -#define LLD_READER_WRITER_ELF_LAYOUT_H_ +#ifndef LLD_READER_WRITER_ELF_LAYOUT_H +#define LLD_READER_WRITER_ELF_LAYOUT_H #include "lld/Core/DefinedAtom.h" @@ -20,12 +20,12 @@ namespace lld { namespace elf { -/// \brief The ELFLayout is an abstract class for managing the final layout for +/// \brief The Layout is an abstract class for managing the final layout for /// the kind of binaries(Shared Libraries / Relocatables / Executables 0 /// Each architecture (Hexagon, PowerPC, MIPS) would have a concrete -/// subclass derived from ELFLayout for generating each binary thats +/// subclass derived from Layout for generating each binary thats // needed by the lld linker -class ELFLayout { +class Layout { public: typedef uint32_t SectionOrder; typedef uint32_t SegmentType; @@ -34,13 +34,13 @@ public: public: /// Return the order the section would appear in the output file virtual SectionOrder getSectionOrder - (const llvm::StringRef name, + (const StringRef name, int32_t contentType, int32_t contentPerm) = 0; /// append the Atom to the layout and create appropriate sections virtual error_code addAtom(const Atom *atom) = 0; /// find the Atom Address in the current layout - virtual bool findAtomAddrByName(const llvm::StringRef name, + virtual bool findAtomAddrByName(const StringRef name, uint64_t &addr) = 0; /// associates a section to a segment virtual void assignSectionsToSegments() = 0; @@ -50,9 +50,9 @@ public: virtual void assignFileOffsets() = 0; public: - ELFLayout() {} + Layout() {} - virtual ~ELFLayout() { } + virtual ~Layout() { } }; struct AtomLayout { @@ -66,7 +66,7 @@ struct AtomLayout { uint64_t _fileOffset; uint64_t _virtualAddr; }; -} // lld -} // elf +} // end namespace elf +} // end namespace lld -#endif // LLD_READER_WRITER_ELF_LAYOUT_H_ +#endif diff --git a/lld/lib/ReaderWriter/ELF/PPC/PPCELFTarget.h b/lld/lib/ReaderWriter/ELF/PPC/PPCTarget.h similarity index 69% rename from lld/lib/ReaderWriter/ELF/PPC/PPCELFTarget.h rename to lld/lib/ReaderWriter/ELF/PPC/PPCTarget.h index 7805190..56bbdc9 100644 --- a/lld/lib/ReaderWriter/ELF/PPC/PPCELFTarget.h +++ b/lld/lib/ReaderWriter/ELF/PPC/PPCTarget.h @@ -1,4 +1,4 @@ -//===- lib/ReaderWriter/ELF/PPC/PPCELFTarget.h ---------------------------===// +//===- lib/ReaderWriter/ELF/PPC/PPCTarget.h -------------------------------===// // // The LLVM Linker // @@ -6,4 +6,5 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#include "PPCELFTargetInfo.h" + +#include "PPCTargetInfo.h" diff --git a/lld/lib/ReaderWriter/ELF/PPC/PPCELFTargetInfo.h b/lld/lib/ReaderWriter/ELF/PPC/PPCTargetInfo.h similarity index 77% rename from lld/lib/ReaderWriter/ELF/PPC/PPCELFTargetInfo.h rename to lld/lib/ReaderWriter/ELF/PPC/PPCTargetInfo.h index 9a6cb83..23f6487 100644 --- a/lld/lib/ReaderWriter/ELF/PPC/PPCELFTargetInfo.h +++ b/lld/lib/ReaderWriter/ELF/PPC/PPCTargetInfo.h @@ -15,15 +15,15 @@ #include "llvm/Object/ELF.h" #include "llvm/Support/ELF.h" -#include "DefaultELFTargetHandler.h" +#include "DefaultTargetHandler.h" namespace lld { namespace elf { -class PPCELFTargetInfo LLVM_FINAL : public ELFTargetInfo { +class PPCTargetInfo LLVM_FINAL : public ELFTargetInfo { public: - PPCELFTargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) { - _targetHandler = std::unique_ptr( - new DefaultELFTargetHandler< + PPCTargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) { + _targetHandler = std::unique_ptr( + new DefaultTargetHandler< llvm::object::ELFType >(*this)); } diff --git a/lld/lib/ReaderWriter/ELF/ReaderELF.cpp b/lld/lib/ReaderWriter/ELF/Reader.cpp similarity index 80% rename from lld/lib/ReaderWriter/ELF/ReaderELF.cpp rename to lld/lib/ReaderWriter/ELF/Reader.cpp index 3439b96..9ab57df 100644 --- a/lld/lib/ReaderWriter/ELF/ReaderELF.cpp +++ b/lld/lib/ReaderWriter/ELF/Reader.cpp @@ -1,4 +1,4 @@ -//===- lib/ReaderWriter/ELF/ReaderELF.cpp ---------------------------------===// +//===- lib/ReaderWriter/ELF/Reader.cpp ------------------------------------===// // // The LLVM Linker // @@ -15,8 +15,8 @@ #include "lld/ReaderWriter/Reader.h" -#include "AtomsELF.h" -#include "FileELF.h" +#include "Atoms.h" +#include "File.h" #include "lld/Core/Reference.h" #include "lld/ReaderWriter/ELFTargetInfo.h" @@ -43,17 +43,17 @@ #include #include -using namespace lld; using llvm::support::endianness; using namespace llvm::object; -namespace { -/// \brief A reader object that will instantiate correct FileELF by examining the +namespace lld { +namespace elf { +/// \brief A reader object that will instantiate correct File by examining the /// memory buffer for ELF class and bit width -class ReaderELF : public Reader { +class ELFReader : public Reader { public: - ReaderELF(const ELFTargetInfo &ti, std::function read) - : Reader(ti), _elfTargetInfo(ti), _readerArchive(ti, read) { + ELFReader(const ELFTargetInfo &ti, std::function read) + : lld::Reader(ti), _elfTargetInfo(ti), _readerArchive(ti, read) { } error_code parseFile(std::unique_ptr mb, @@ -71,46 +71,46 @@ public: case llvm::sys::ELF_Relocatable_FileType: { std::pair Ident = getElfArchType(&*mb); std::unique_ptr f; - // Instantiate the correct FileELF template instance based on the Ident + // Instantiate the correct File template instance based on the Ident // pair. Once the File is created we push the file to the vector of files // already created during parser's life. if (Ident.first == llvm::ELF::ELFCLASS32 && Ident.second == llvm::ELF::ELFDATA2LSB) { if (MaxAlignment >= 4) - f.reset(new FileELF >( + f.reset(new ELFFile >( _elfTargetInfo, std::move(mb), ec)); else if (MaxAlignment >= 2) - f.reset(new FileELF >( + f.reset(new ELFFile >( _elfTargetInfo, std::move(mb), ec)); else llvm_unreachable("Invalid alignment for ELF file!"); } else if (Ident.first == llvm::ELF::ELFCLASS32 && Ident.second == llvm::ELF::ELFDATA2MSB) { if (MaxAlignment >= 4) - f.reset(new FileELF >( + f.reset(new ELFFile >( _elfTargetInfo, std::move(mb), ec)); else if (MaxAlignment >= 2) - f.reset(new FileELF >( + f.reset(new ELFFile >( _elfTargetInfo, std::move(mb), ec)); else llvm_unreachable("Invalid alignment for ELF file!"); } else if (Ident.first == llvm::ELF::ELFCLASS64 && Ident.second == llvm::ELF::ELFDATA2MSB) { if (MaxAlignment >= 8) - f.reset(new FileELF >( + f.reset(new ELFFile >( _elfTargetInfo, std::move(mb), ec)); else if (MaxAlignment >= 2) - f.reset(new FileELF >( + f.reset(new ELFFile >( _elfTargetInfo, std::move(mb), ec)); else llvm_unreachable("Invalid alignment for ELF file!"); } else if (Ident.first == llvm::ELF::ELFCLASS64 && Ident.second == llvm::ELF::ELFDATA2LSB) { if (MaxAlignment >= 8) - f.reset(new FileELF >( + f.reset(new ELFFile >( _elfTargetInfo, std::move(mb), ec)); else if (MaxAlignment >= 2) - f.reset(new FileELF >( + f.reset(new ELFFile >( _elfTargetInfo, std::move(mb), ec)); else llvm_unreachable("Invalid alignment for ELF file!"); @@ -137,11 +137,10 @@ private: const ELFTargetInfo &_elfTargetInfo; ReaderArchive _readerArchive; }; -} // end anon namespace. +} // end namespace elf -namespace lld { std::unique_ptr createReaderELF(const ELFTargetInfo &eti, std::function read) { - return std::unique_ptr(new ReaderELF(eti, std::move(read))); + return std::unique_ptr(new elf::ELFReader(eti, std::move(read))); } } // end namespace lld diff --git a/lld/lib/ReaderWriter/ELF/ELFSectionChunks.h b/lld/lib/ReaderWriter/ELF/SectionChunks.h similarity index 91% rename from lld/lib/ReaderWriter/ELF/ELFSectionChunks.h rename to lld/lib/ReaderWriter/ELF/SectionChunks.h index 0a645ad..ffb38c5 100644 --- a/lld/lib/ReaderWriter/ELF/ELFSectionChunks.h +++ b/lld/lib/ReaderWriter/ELF/SectionChunks.h @@ -1,4 +1,4 @@ -//===- lib/ReaderWriter/ELF/ELFSectionChunks.h -----------------------------===// +//===- lib/ReaderWriter/ELF/SectionChunks.h -------------------------------===// // // The LLVM Linker // @@ -7,13 +7,13 @@ // //===----------------------------------------------------------------------===// -#ifndef LLD_READER_WRITER_ELF_SECTION_CHUNKS_H_ -#define LLD_READER_WRITER_ELF_SECTION_CHUNKS_H_ +#ifndef LLD_READER_WRITER_ELF_SECTION_CHUNKS_H +#define LLD_READER_WRITER_ELF_SECTION_CHUNKS_H -#include "ELFChunk.h" -#include "ELFLayout.h" -#include "ELFTargetHandler.h" -#include "ELFWriter.h" +#include "Chunk.h" +#include "Layout.h" +#include "TargetHandler.h" +#include "Writer.h" #include "lld/Core/DefinedAtom.h" #include "lld/Core/range.h" @@ -45,7 +45,7 @@ public: }; // Create a section object, the section is set to the default type if the // caller doesnot set it - Section(const ELFTargetInfo &, const llvm::StringRef sectionName, + Section(const ELFTargetInfo &, const StringRef sectionName, const int32_t contentType, const int32_t contentPermissions, const int32_t order, const SectionKind kind = K_Default); @@ -83,7 +83,7 @@ public: /// \brief Find the Atom address given a name, this is needed to to properly /// apply relocation. The section class calls this to find the atom address /// to fix the relocation - inline bool findAtomAddrByName(const llvm::StringRef name, uint64_t &addr) { + inline bool findAtomAddrByName(const StringRef name, uint64_t &addr) { for (auto ai : _atoms) { if (ai._atom->name() == name) { addr = ai._virtualAddr; @@ -113,7 +113,7 @@ public: /// \brief convert the segment type to a String for diagnostics /// and printing purposes - llvm::StringRef segmentKindToStr() const; + StringRef segmentKindToStr() const; /// \brief Return the raw flags, we need this to sort segments inline int64_t atomflags() const { @@ -143,7 +143,7 @@ public: } /// \brief Records the segmentType, that this section belongs to - inline void setSegment(const ELFLayout::SegmentType segmentType) { + inline void setSegment(const Layout::SegmentType segmentType) { _segmentType = segmentType; } @@ -168,7 +168,7 @@ protected: int32_t _contentPermissions; SectionKind _sectionKind; std::vector _atoms; - ELFLayout::SegmentType _segmentType; + Layout::SegmentType _segmentType; int64_t _entSize; int64_t _shInfo; int64_t _link; @@ -382,7 +382,7 @@ public: // Iterators typedef typename std::vector *>::iterator ChunkIter; - MergedSections(llvm::StringRef name); + MergedSections(StringRef name); // Appends a section into the list of sections that are part of this Merged // Section @@ -422,7 +422,7 @@ public: // The below functions returns the properties of the MergeSection inline bool hasSegment() const { return _hasSegment; } - inline llvm::StringRef name() const { return _name; } + inline StringRef name() const { return _name; } inline int64_t shinfo() const { return _shInfo; } @@ -449,7 +449,7 @@ public: inline uint64_t memSize() { return _memSize; } private: - llvm::StringRef _name; + StringRef _name; bool _hasSegment; uint64_t _ordinal; int64_t _flags; @@ -504,26 +504,26 @@ MergedSections::appendSection(Chunk *c) { /// \brief The class represents the ELF String Table template -class ELFStringTable : public Section { +class StringTable : public Section { public: - ELFStringTable(const ELFTargetInfo &, const char *str, int32_t order); + StringTable(const ELFTargetInfo &, const char *str, int32_t order); static inline bool classof(const Chunk *c) { return c->kind() == Section::K_StringTable; } - uint64_t addString(const llvm::StringRef symname); + uint64_t addString(const StringRef symname); void write(ELFWriter *writer, llvm::FileOutputBuffer &buffer); inline void finalize() { } private: - std::vector _strings; + std::vector _strings; }; template -ELFStringTable::ELFStringTable(const ELFTargetInfo &ti, const char *str, +StringTable::StringTable(const ELFTargetInfo &ti, const char *str, int32_t order) : Section(ti, str, llvm::ELF::SHT_STRTAB, DefinedAtom::perm___, order, Section::K_StringTable) { @@ -537,7 +537,7 @@ ELFStringTable::ELFStringTable(const ELFTargetInfo &ti, const char *str, template uint64_t -ELFStringTable::addString(const StringRef symname) { +StringTable::addString(const StringRef symname) { _strings.push_back(symname); uint64_t offset = this->_fsize; this->_fsize += symname.size() + 1; @@ -545,7 +545,7 @@ ELFStringTable::addString(const StringRef symname) { } template -void ELFStringTable::write(ELFWriter *writer, +void StringTable::write(ELFWriter *writer, llvm::FileOutputBuffer &buffer) { uint8_t *chunkBuffer = buffer.getBufferStart(); uint8_t *dest = chunkBuffer + this->fileOffset(); @@ -557,13 +557,13 @@ void ELFStringTable::write(ELFWriter *writer, } } -/// \brief The ELFSymbolTable class represents the symbol table in a ELF file +/// \brief The SymbolTable class represents the symbol table in a ELF file template -class ELFSymbolTable : public Section { +class SymbolTable : public Section { public: typedef llvm::object::Elf_Sym_Impl Elf_Sym; - ELFSymbolTable(const ELFTargetInfo &ti, const char *str, int32_t order); + SymbolTable(const ELFTargetInfo &ti, const char *str, int32_t order); void addSymbol(const Atom *atom, int32_t sectionIndex, uint64_t addr = 0); @@ -575,12 +575,12 @@ public: return c->kind() == Section::K_SymbolTable; } - inline void setStringSection(ELFStringTable *s) { + inline void setStringSection(StringTable *s) { _stringSection = s; } private: - ELFStringTable *_stringSection; + StringTable *_stringSection; std::vector _symbolTable; llvm::BumpPtrAllocator _symbolAllocate; int64_t _link; @@ -588,7 +588,7 @@ private: /// ELF Symbol Table template -ELFSymbolTable::ELFSymbolTable(const ELFTargetInfo &ti, const char *str, +SymbolTable::SymbolTable(const ELFTargetInfo &ti, const char *str, int32_t order) : Section(ti, str, llvm::ELF::SHT_SYMTAB, 0, order, Section::K_SymbolTable) { @@ -603,7 +603,7 @@ ELFSymbolTable::ELFSymbolTable(const ELFTargetInfo &ti, const char *str, template void -ELFSymbolTable::addSymbol(const Atom *atom, +SymbolTable::addSymbol(const Atom *atom, int32_t sectionIndex, uint64_t addr) { Elf_Sym *symbol = new(_symbolAllocate.Allocate()) Elf_Sym; @@ -615,9 +615,9 @@ ELFSymbolTable::addSymbol(const Atom *atom, symbol->st_other = llvm::ELF::STV_DEFAULT; if (const DefinedAtom *da = dyn_cast(atom)){ symbol->st_size = da->size(); - lld::DefinedAtom::ContentType ct; + DefinedAtom::ContentType ct; switch (ct = da->contentType()){ - case DefinedAtom::typeCode: + case DefinedAtom::typeCode: case DefinedAtom::typeStub: symbol->st_value = addr; type = llvm::ELF::STT_FUNC; @@ -626,13 +626,13 @@ ELFSymbolTable::addSymbol(const Atom *atom, symbol->st_value = addr; type = llvm::ELF::STT_GNU_IFUNC; break; - case DefinedAtom::typeData: - case DefinedAtom::typeConstant: + case DefinedAtom::typeData: + case DefinedAtom::typeConstant: case DefinedAtom::typeGOT: symbol->st_value = addr; type = llvm::ELF::STT_OBJECT; break; - case DefinedAtom::typeZeroFill: + case DefinedAtom::typeZeroFill: type = llvm::ELF::STT_OBJECT; symbol->st_value = addr; break; @@ -671,7 +671,7 @@ ELFSymbolTable::addSymbol(const Atom *atom, template void -ELFSymbolTable::finalize() { +SymbolTable::finalize() { // sh_info should be one greater than last symbol with STB_LOCAL binding // we sort the symbol table to keep all local symbols at the beginning std::stable_sort(_symbolTable.begin(), _symbolTable.end(), @@ -689,7 +689,7 @@ ELFSymbolTable::finalize() { } template -void ELFSymbolTable::write(ELFWriter *writer, +void SymbolTable::write(ELFWriter *writer, llvm::FileOutputBuffer &buffer) { uint8_t *chunkBuffer = buffer.getBufferStart(); uint8_t *dest = chunkBuffer + this->fileOffset(); @@ -699,11 +699,11 @@ void ELFSymbolTable::write(ELFWriter *writer, } } -template class ELFRelocationTable : public Section { +template class RelocationTable : public Section { public: typedef llvm::object::Elf_Rel_Impl Elf_Rela; - ELFRelocationTable(const ELFTargetInfo &ti, StringRef str, int32_t order) + RelocationTable(const ELFTargetInfo &ti, StringRef str, int32_t order) : Section(ti, str, llvm::ELF::SHT_RELA, DefinedAtom::permR__, order, Section::K_Default) { this->setOrder(order); @@ -738,8 +738,7 @@ public: private: std::vector> _relocs; }; +} // end namespace elf +} // end namespace lld -} // elf -} // lld - -#endif //LLD_READER_WRITER_ELF_SECTION_CHUNKS_H_ +#endif diff --git a/lld/lib/ReaderWriter/ELF/ELFSegmentChunks.h b/lld/lib/ReaderWriter/ELF/SegmentChunks.h similarity index 95% rename from lld/lib/ReaderWriter/ELF/ELFSegmentChunks.h rename to lld/lib/ReaderWriter/ELF/SegmentChunks.h index 849a62b..77a023a 100644 --- a/lld/lib/ReaderWriter/ELF/ELFSegmentChunks.h +++ b/lld/lib/ReaderWriter/ELF/SegmentChunks.h @@ -1,4 +1,4 @@ -//===- lib/ReaderWriter/ELF/ELFSegmentChunks.h -----------------------------===// +//===- lib/ReaderWriter/ELF/SegmentChunks.h -------------------------------===// // // The LLVM Linker // @@ -7,13 +7,13 @@ // //===----------------------------------------------------------------------===// -#ifndef LLD_READER_WRITER_ELF_SEGMENT_CHUNKS_H_ -#define LLD_READER_WRITER_ELF_SEGMENT_CHUNKS_H_ +#ifndef LLD_READER_WRITER_ELF_SEGMENT_CHUNKS_H +#define LLD_READER_WRITER_ELF_SEGMENT_CHUNKS_H -#include "ELFChunk.h" -#include "ELFLayout.h" -#include "ELFSectionChunks.h" -#include "ELFWriter.h" +#include "Chunk.h" +#include "Layout.h" +#include "SectionChunks.h" +#include "Writer.h" #include "lld/Core/range.h" #include "lld/ReaderWriter/Writer.h" @@ -28,11 +28,10 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileOutputBuffer.h" -/// \brief A segment can be divided into segment slices -/// depending on how the segments can be split namespace lld { namespace elf { - +/// \brief A segment can be divided into segment slices +/// depending on how the segments can be split template class SegmentSlice { public: @@ -110,7 +109,7 @@ public: typedef typename std::vector *>::iterator SectionIter; Segment(const ELFTargetInfo &ti, const StringRef name, - const ELFLayout::SegmentType type); + const Layout::SegmentType type); /// append a section to a segment void append(Section *section); @@ -163,7 +162,7 @@ public: return _sections.size(); } - inline ELFLayout::SegmentType segmentType() { return _segmentType; } + inline Layout::SegmentType segmentType() { return _segmentType; } inline int pageSize() const { return this->_targetInfo.getPageSize(); } @@ -189,7 +188,7 @@ protected: /// \brief Section or some other chunk type. std::vector *> _sections; std::vector *> _segmentSlices; - ELFLayout::SegmentType _segmentType; + Layout::SegmentType _segmentType; int64_t _flags; int64_t _atomflags; llvm::BumpPtrAllocator _segmentAllocate; @@ -197,7 +196,7 @@ protected: template Segment::Segment(const ELFTargetInfo &ti, const StringRef name, - const ELFLayout::SegmentType type) + const Layout::SegmentType type) : Chunk(name, Chunk::K_ELFSegment, ti), _segmentType(type), _flags(0), _atomflags(0) { this->_align2 = 0; @@ -367,8 +366,7 @@ Segment::flags() const { fl |= llvm::ELF::PF_X; return fl; } +} // end namespace elf +} // end namespace lld -} // elf -} // lld - -#endif // LLD_READER_WRITER_ELF_SEGMENT_CHUNKS_H_ +#endif diff --git a/lld/lib/ReaderWriter/ELF/ELFTargetHandler.h b/lld/lib/ReaderWriter/ELF/TargetHandler.h similarity index 82% rename from lld/lib/ReaderWriter/ELF/ELFTargetHandler.h rename to lld/lib/ReaderWriter/ELF/TargetHandler.h index 196f143..45afb94 100644 --- a/lld/lib/ReaderWriter/ELF/ELFTargetHandler.h +++ b/lld/lib/ReaderWriter/ELF/TargetHandler.h @@ -1,4 +1,4 @@ -//===- lib/ReaderWriter/ELF/ELFTargetHandler.h -----------------------------===// +//===- lib/ReaderWriter/ELF/TargetHandler.h -------------------------------===// // // The LLVM Linker // @@ -13,8 +13,8 @@ /// //===----------------------------------------------------------------------===// -#ifndef LLD_READER_WRITER_ELF_TARGETHANDLER_H -#define LLD_READER_WRITER_ELF_TARGETHANDLER_H +#ifndef LLD_READER_WRITER_ELF_TARGET_HANDLER_H +#define LLD_READER_WRITER_ELF_TARGET_HANDLER_H #include "lld/Core/InputFiles.h" #include "lld/Core/LinkerOptions.h" @@ -29,21 +29,21 @@ #include namespace lld { -template class ELFDefinedAtom; namespace elf { -template class ELFTargetLayout; -template class ELFHeader; +template class ELFDefinedAtom; +template class Header; template class Section; +template class TargetLayout; /// \brief The target registers a set of handlers for overriding target specific /// attributes for a DefinedAtom. The Reader uses this class to query for the /// type of atom and its permissions -template class ELFTargetAtomHandler { +template class TargetAtomHandler { public: typedef llvm::object::Elf_Sym_Impl Elf_Sym; virtual DefinedAtom::ContentType contentType( - const lld::ELFDefinedAtom *atom) const { + const ELFDefinedAtom *atom) const { return atom->contentType(); } @@ -52,17 +52,17 @@ public: } virtual DefinedAtom::ContentPermissions contentPermissions( - const lld::ELFDefinedAtom *atom) const { + const ELFDefinedAtom *atom) const { return atom->permissions(); } }; /// \brief An interface to override functions that are provided by the /// the default ELF Layout -template class ELFTargetHandler : public ELFTargetHandlerBase { +template class TargetHandler : public TargetHandlerBase { public: - ELFTargetHandler(ELFTargetInfo &targetInfo) : _targetInfo(targetInfo) {} + TargetHandler(ELFTargetInfo &targetInfo) : _targetInfo(targetInfo) {} /// Register a Target, so that the target backend may choose on how to merge /// individual atoms within the section, this is a way to control output order @@ -91,16 +91,16 @@ public: /// If the target overrides ELF header information, this API would /// return true, so that the target can set all fields specific to /// that target - virtual bool doesOverrideELFHeader() = 0; + virtual bool doesOverrideHeader() = 0; /// Set the ELF Header information - virtual void setELFHeaderInfo(ELFHeader *elfHeader) = 0; + virtual void setHeaderInfo(Header *Header) = 0; - /// ELFTargetLayout - virtual ELFTargetLayout &targetLayout() = 0; + /// TargetLayout + virtual TargetLayout &targetLayout() = 0; - /// ELFTargetAtomHandler - virtual ELFTargetAtomHandler &targetAtomHandler() = 0; + /// TargetAtomHandler + virtual TargetAtomHandler &targetAtomHandler() = 0; /// Create a set of Default target sections that a target might needj virtual void createDefaultSections() = 0; @@ -150,8 +150,7 @@ protected: const ELFTargetInfo &_targetInfo; RegisteredTargetSectionMapT _registeredTargetSections; }; +} // end namespace elf +} // end namespace lld -} // elf -} // lld - -#endif // LLD_READER_WRITER_ELF_TARGETHANDLER_H +#endif diff --git a/lld/lib/ReaderWriter/ELF/ELFTargetLayout.h b/lld/lib/ReaderWriter/ELF/TargetLayout.h similarity index 85% rename from lld/lib/ReaderWriter/ELF/ELFTargetLayout.h rename to lld/lib/ReaderWriter/ELF/TargetLayout.h index 5416c02..e4f17b8 100644 --- a/lld/lib/ReaderWriter/ELF/ELFTargetLayout.h +++ b/lld/lib/ReaderWriter/ELF/TargetLayout.h @@ -1,4 +1,4 @@ -//===- lib/ReaderWriter/ELF/ELFTargetLayout.h -----------------------------===// +//===- lib/ReaderWriter/ELF/TargetLayout.h --------------------------------===// // // The LLVM Linker // @@ -10,18 +10,18 @@ #ifndef LLD_READER_WRITER_ELF_TARGET_LAYOUT_H #define LLD_READER_WRITER_ELF_TARGET_LAYOUT_H -#include "DefaultELFLayout.h" +#include "DefaultLayout.h" #include "lld/Core/LLVM.h" namespace lld { namespace elf { -/// \brief The target can override certain functions in the DefaultELFLayout +/// \brief The target can override certain functions in the DefaultLayout /// class so that the order, the name of the section and the segment type could /// be changed in the final layout -template class ELFTargetLayout : public DefaultELFLayout { +template class TargetLayout : public DefaultLayout { public: - ELFTargetLayout(ELFTargetInfo &targetInfo) + TargetLayout(ELFTargetInfo &targetInfo) : DefaultELFLayout(targetInfo) { } @@ -42,12 +42,12 @@ public: /// The target may want to override the section order that has been /// set by the DefaultLayout - virtual ELFLayout::SectionOrder getSectionOrder( + virtual Layout::SectionOrder getSectionOrder( const StringRef name, int32_t contentType, int32_t contentPermissions) = 0; /// The target can set the segment type for a Section - virtual ELFLayout::SegmentType segmentType(Section *section) const = 0; + virtual Layout::SegmentType segmentType(Section *section) const = 0; /// Returns true/false depending on whether the section has a Output // segment or not diff --git a/lld/lib/ReaderWriter/ELF/ELFTargets.h b/lld/lib/ReaderWriter/ELF/Targets.h similarity index 64% rename from lld/lib/ReaderWriter/ELF/ELFTargets.h rename to lld/lib/ReaderWriter/ELF/Targets.h index d87be82..8b2ec9e 100644 --- a/lld/lib/ReaderWriter/ELF/ELFTargets.h +++ b/lld/lib/ReaderWriter/ELF/Targets.h @@ -1,4 +1,4 @@ -//===- lib/ReaderWriter/ELF/ELFTargets.h ----------------------------------===// +//===- lib/ReaderWriter/ELF/Targets.h -------------------------------------===// // // The LLVM Linker // @@ -10,9 +10,9 @@ #ifndef LLD_READER_WRITER_ELF_TARGETS_H #define LLD_READER_WRITER_ELF_TARGETS_H -#include "Hexagon/HexagonELFTarget.h" -#include "PPC/PPCELFTarget.h" -#include "X86/X86ELFTarget.h" -#include "X86_64/X86_64ELFTarget.h" +#include "Hexagon/HexagonTarget.h" +#include "PPC/PPCTarget.h" +#include "X86/X86Target.h" +#include "X86_64/X86_64Target.h" #endif diff --git a/lld/lib/ReaderWriter/ELF/WriterELF.cpp b/lld/lib/ReaderWriter/ELF/Writer.cpp similarity index 72% rename from lld/lib/ReaderWriter/ELF/WriterELF.cpp rename to lld/lib/ReaderWriter/ELF/Writer.cpp index f9d70bd..2318cd8 100644 --- a/lld/lib/ReaderWriter/ELF/WriterELF.cpp +++ b/lld/lib/ReaderWriter/ELF/Writer.cpp @@ -9,7 +9,7 @@ #include "lld/ReaderWriter/Writer.h" -#include "DefaultELFLayout.h" +#include "DefaultLayout.h" #include "ExecutableAtoms.h" #include "lld/ReaderWriter/ELFTargetInfo.h" @@ -19,28 +19,28 @@ using namespace llvm::object; namespace lld { namespace elf { template -class ELFExecutableWriter; +class ExecutableWriter; //===----------------------------------------------------------------------===// -// ELFExecutableWriter Class +// ExecutableWriter Class //===----------------------------------------------------------------------===// template -class ELFExecutableWriter : public ELFWriter { +class ExecutableWriter : public ELFWriter { public: typedef Elf_Shdr_Impl Elf_Shdr; typedef Elf_Sym_Impl Elf_Sym; - ELFExecutableWriter(const ELFTargetInfo &ti); + ExecutableWriter(const ELFTargetInfo &ti); private: // build the sections that need to be created - void buildChunks(const lld::File &file); - virtual error_code writeFile(const lld::File &File, StringRef path); + void buildChunks(const File &file); + virtual error_code writeFile(const File &File, StringRef path); void buildAtomToAddressMap(); void buildSymbolTable (); void buildSectionHeaderTable(); void assignSectionsWithNoSegments(); - void addAbsoluteUndefinedSymbols(const lld::File &File); + void addAbsoluteUndefinedSymbols(const File &File); void addDefaultAtoms(); void addFiles(InputFiles&); void finalizeDefaultAtomValues(); @@ -59,30 +59,30 @@ private: std::unique_ptr _referenceKindHandler; AtomToAddress _atomToAddressMap; llvm::BumpPtrAllocator _chunkAllocate; - DefaultELFLayout *_layout; - ELFHeader *_elfHeader; - ELFProgramHeader *_programHeader; - ELFSymbolTable * _symtab; - ELFStringTable *_strtab; - ELFStringTable *_shstrtab; - ELFSectionHeader *_shdrtab; - CRuntimeFileELF _runtimeFile; + DefaultLayout *_layout; + Header *_Header; + ProgramHeader *_programHeader; + SymbolTable * _symtab; + StringTable *_strtab; + StringTable *_shstrtab; + SectionHeader *_shdrtab; + CRuntimeFile _runtimeFile; }; //===----------------------------------------------------------------------===// -// ELFExecutableWriter +// ExecutableWriter //===----------------------------------------------------------------------===// template -ELFExecutableWriter::ELFExecutableWriter(const ELFTargetInfo &ti) +ExecutableWriter::ExecutableWriter(const ELFTargetInfo &ti) : _targetInfo(ti) , _referenceKindHandler(KindHandler::makeHandler( ti.getTriple().getArch(), ti.isLittleEndian())) , _runtimeFile(ti) { - _layout = new DefaultELFLayout(ti); + _layout = new DefaultLayout(ti); } template -void ELFExecutableWriter::buildChunks(const lld::File &file){ +void ExecutableWriter::buildChunks(const File &file){ for (const DefinedAtom *definedAtom : file.defined() ) { _layout->addAtom(definedAtom); } @@ -93,7 +93,7 @@ void ELFExecutableWriter::buildChunks(const lld::File &file){ } template -void ELFExecutableWriter::buildSymbolTable () { +void ExecutableWriter::buildSymbolTable () { for (auto sec : _layout->sections()) if (auto section = dyn_cast>(sec)) for (const auto &atom : section->atoms()) @@ -102,7 +102,7 @@ void ELFExecutableWriter::buildSymbolTable () { template void -ELFExecutableWriter::addAbsoluteUndefinedSymbols(const lld::File &file) { +ExecutableWriter::addAbsoluteUndefinedSymbols(const File &file) { // add all the absolute symbols that the layout contains to the output symbol // table for (auto &atom : _layout->absoluteAtoms()) @@ -112,7 +112,7 @@ ELFExecutableWriter::addAbsoluteUndefinedSymbols(const lld::File &file) { } template -void ELFExecutableWriter::buildAtomToAddressMap () { +void ExecutableWriter::buildAtomToAddressMap () { for (auto sec : _layout->sections()) if (auto section = dyn_cast>(sec)) for (const auto &atom : section->atoms()) @@ -123,7 +123,7 @@ void ELFExecutableWriter::buildAtomToAddressMap () { } template -void ELFExecutableWriter::buildSectionHeaderTable() { +void ExecutableWriter::buildSectionHeaderTable() { for (auto mergedSec : _layout->mergedSections()) { if (mergedSec->kind() != Chunk::K_ELFSection) continue; @@ -133,7 +133,7 @@ void ELFExecutableWriter::buildSectionHeaderTable() { } template -void ELFExecutableWriter::assignSectionsWithNoSegments() { +void ExecutableWriter::assignSectionsWithNoSegments() { for (auto mergedSec : _layout->mergedSections()) { if (mergedSec->kind() != Chunk::K_ELFSection) continue; @@ -143,14 +143,14 @@ void ELFExecutableWriter::assignSectionsWithNoSegments() { _layout->assignOffsetsForMiscSections(); for (auto sec : _layout->sections()) if (auto section = dyn_cast>(sec)) - if (!DefaultELFLayout::hasOutputSegment(section)) + if (!DefaultLayout::hasOutputSegment(section)) _shdrtab->updateSection(section); } /// \brief Add absolute symbols by default. These are linker added /// absolute symbols template -void ELFExecutableWriter::addDefaultAtoms() { +void ExecutableWriter::addDefaultAtoms() { _runtimeFile.addUndefinedAtom(_targetInfo.getEntry()); _runtimeFile.addAbsoluteAtom("__bss_start"); _runtimeFile.addAbsoluteAtom("__bss_end"); @@ -164,7 +164,7 @@ void ELFExecutableWriter::addDefaultAtoms() { /// \brief Hook in lld to add CRuntime file template -void ELFExecutableWriter::addFiles(InputFiles &inputFiles) { +void ExecutableWriter::addFiles(InputFiles &inputFiles) { addDefaultAtoms(); inputFiles.prependFile(_runtimeFile); } @@ -172,7 +172,7 @@ void ELFExecutableWriter::addFiles(InputFiles &inputFiles) { /// Finalize the value of all the absolute symbols that we /// created template -void ELFExecutableWriter::finalizeDefaultAtomValues() { +void ExecutableWriter::finalizeDefaultAtomValues() { auto bssStartAtomIter = _layout->findAbsoluteAtom("__bss_start"); auto bssEndAtomIter = _layout->findAbsoluteAtom("__bss_end"); auto underScoreEndAtomIter = _layout->findAbsoluteAtom("_end"); @@ -182,8 +182,8 @@ void ELFExecutableWriter::finalizeDefaultAtomValues() { auto realIpltStartIter = _layout->findAbsoluteAtom("__rela_iplt_start"); auto realIpltEndIter = _layout->findAbsoluteAtom("__rela_iplt_end"); - auto startEnd = [&](typename DefaultELFLayout::AbsoluteAtomIterT start, - typename DefaultELFLayout::AbsoluteAtomIterT end, + auto startEnd = [&](typename DefaultLayout::AbsoluteAtomIterT start, + typename DefaultLayout::AbsoluteAtomIterT end, StringRef sec) -> void { auto section = _layout->findOutputSection(sec); if (section) { @@ -218,7 +218,7 @@ void ELFExecutableWriter::finalizeDefaultAtomValues() { template error_code -ELFExecutableWriter::writeFile(const lld::File &file, StringRef path) { +ExecutableWriter::writeFile(const File &file, StringRef path) { buildChunks(file); // Create the default sections like the symbol table, string table, and the // section string table @@ -260,31 +260,31 @@ ELFExecutableWriter::writeFile(const lld::File &file, StringRef path) { if (ec) return ec; - _elfHeader->e_ident(ELF::EI_CLASS, _targetInfo.is64Bits() ? ELF::ELFCLASS64 + _Header->e_ident(ELF::EI_CLASS, _targetInfo.is64Bits() ? ELF::ELFCLASS64 : ELF::ELFCLASS32); - _elfHeader->e_ident(ELF::EI_DATA, _targetInfo.isLittleEndian() + _Header->e_ident(ELF::EI_DATA, _targetInfo.isLittleEndian() ? ELF::ELFDATA2LSB : ELF::ELFDATA2MSB); - _elfHeader->e_ident(ELF::EI_VERSION, 1); - _elfHeader->e_ident(ELF::EI_OSABI, 0); - _elfHeader->e_type(_targetInfo.getOutputType()); - _elfHeader->e_machine(_targetInfo.getOutputMachine()); - _elfHeader->e_version(1); - _elfHeader->e_entry(0ULL); - _elfHeader->e_phoff(_programHeader->fileOffset()); - _elfHeader->e_shoff(_shdrtab->fileOffset()); - _elfHeader->e_phentsize(_programHeader->entsize()); - _elfHeader->e_phnum(_programHeader->numHeaders()); - _elfHeader->e_shentsize(_shdrtab->entsize()); - _elfHeader->e_shnum(_shdrtab->numHeaders()); - _elfHeader->e_shstrndx(_shstrtab->ordinal()); + _Header->e_ident(ELF::EI_VERSION, 1); + _Header->e_ident(ELF::EI_OSABI, 0); + _Header->e_type(_targetInfo.getOutputType()); + _Header->e_machine(_targetInfo.getOutputMachine()); + _Header->e_version(1); + _Header->e_entry(0ULL); + _Header->e_phoff(_programHeader->fileOffset()); + _Header->e_shoff(_shdrtab->fileOffset()); + _Header->e_phentsize(_programHeader->entsize()); + _Header->e_phnum(_programHeader->numHeaders()); + _Header->e_shentsize(_shdrtab->entsize()); + _Header->e_shnum(_shdrtab->numHeaders()); + _Header->e_shstrndx(_shstrtab->ordinal()); uint64_t virtualAddr = 0; _layout->findAtomAddrByName(_targetInfo.getEntry(), virtualAddr); - _elfHeader->e_entry(virtualAddr); + _Header->e_entry(virtualAddr); // HACK: We have to write out the header and program header here even though // they are a member of a segment because only sections are written in the // following loop. - _elfHeader->write(this, *buffer); + _Header->write(this, *buffer); _programHeader->write(this, *buffer); for (auto section : _layout->sections()) @@ -294,20 +294,20 @@ ELFExecutableWriter::writeFile(const lld::File &file, StringRef path) { } template -void ELFExecutableWriter::createDefaultSections() { - _elfHeader = new ELFHeader(_targetInfo); - _programHeader = new ELFProgramHeader(_targetInfo); - _layout->setELFHeader(_elfHeader); +void ExecutableWriter::createDefaultSections() { + _Header = new Header(_targetInfo); + _programHeader = new ProgramHeader(_targetInfo); + _layout->setHeader(_Header); _layout->setProgramHeader(_programHeader); - _symtab = new ELFSymbolTable< - ELFT>(_targetInfo, ".symtab", DefaultELFLayout::ORDER_SYMBOL_TABLE); - _strtab = new ELFStringTable< - ELFT>(_targetInfo, ".strtab", DefaultELFLayout::ORDER_STRING_TABLE); - _shstrtab = new ELFStringTable( - _targetInfo, ".shstrtab", DefaultELFLayout::ORDER_SECTION_STRINGS); - _shdrtab = new ELFSectionHeader< - ELFT>(_targetInfo, DefaultELFLayout::ORDER_SECTION_HEADERS); + _symtab = new SymbolTable< + ELFT>(_targetInfo, ".symtab", DefaultLayout::ORDER_SYMBOL_TABLE); + _strtab = new StringTable< + ELFT>(_targetInfo, ".strtab", DefaultLayout::ORDER_STRING_TABLE); + _shstrtab = new StringTable( + _targetInfo, ".shstrtab", DefaultLayout::ORDER_SECTION_STRINGS); + _shdrtab = new SectionHeader< + ELFT>(_targetInfo, DefaultLayout::ORDER_SECTION_HEADERS); _layout->addSection(_symtab); _layout->addSection(_strtab); _layout->addSection(_shstrtab); @@ -325,16 +325,16 @@ std::unique_ptr createWriterELF(const ELFTargetInfo &TI) { if (!TI.is64Bits() && TI.isLittleEndian()) return std::unique_ptr(new - elf::ELFExecutableWriter>(TI)); + elf::ExecutableWriter>(TI)); else if (TI.is64Bits() && TI.isLittleEndian()) return std::unique_ptr(new - elf::ELFExecutableWriter>(TI)); + elf::ExecutableWriter>(TI)); else if (!TI.is64Bits() && !TI.isLittleEndian()) return std::unique_ptr(new - elf::ELFExecutableWriter>(TI)); + elf::ExecutableWriter>(TI)); else if (TI.is64Bits() && !TI.isLittleEndian()) return std::unique_ptr(new - elf::ELFExecutableWriter>(TI)); + elf::ExecutableWriter>(TI)); llvm_unreachable("Invalid Options!"); } diff --git a/lld/lib/ReaderWriter/ELF/ELFWriter.h b/lld/lib/ReaderWriter/ELF/Writer.h similarity index 68% rename from lld/lib/ReaderWriter/ELF/ELFWriter.h rename to lld/lib/ReaderWriter/ELF/Writer.h index 44e5471..b621856 100644 --- a/lld/lib/ReaderWriter/ELF/ELFWriter.h +++ b/lld/lib/ReaderWriter/ELF/Writer.h @@ -1,4 +1,4 @@ -//===- lib/ReaderWriter/ELF/ELFWriter.h ---------------------------------===// +//===- lib/ReaderWriter/ELF/Writer.h --------------------------------------===// // // The LLVM Linker // @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLD_READER_WRITER_ELF_WRITER_H_ -#define LLD_READER_WRITER_ELF_WRITER_H_ +#ifndef LLD_READER_WRITER_ELF_WRITER_H +#define LLD_READER_WRITER_ELF_WRITER_H #include "ReferenceKinds.h" @@ -18,7 +18,7 @@ namespace lld { namespace elf { -/// \brief The ELFWriter class is a base class for the linker to write +/// \brief The Writer class is a base class for the linker to write /// various kinds of ELF files. class ELFWriter : public Writer { public: @@ -27,10 +27,10 @@ public: public: /// \brief builds the chunks that needs to be written to the output /// ELF file - virtual void buildChunks(const lld::File &file) = 0; + virtual void buildChunks(const File &file) = 0; /// \brief Writes the chunks into the output file specified by path - virtual error_code writeFile(const lld::File &File, StringRef path) = 0; + virtual error_code writeFile(const File &File, StringRef path) = 0; /// \brief Get the virtual address of \p atom after layout. virtual uint64_t addressOfAtom(const Atom *atom) = 0; @@ -38,8 +38,7 @@ public: /// \brief Return the processing function to apply Relocations virtual KindHandler *kindHandler() = 0; }; +} // end namespace elf +} // end namespace lld -} // elf -} // lld - -#endif // LLD_READER_WRITER_ELF_WRITER_H_ +#endif diff --git a/lld/lib/ReaderWriter/ELF/X86/X86ELFTarget.h b/lld/lib/ReaderWriter/ELF/X86/X86Target.h similarity index 69% rename from lld/lib/ReaderWriter/ELF/X86/X86ELFTarget.h rename to lld/lib/ReaderWriter/ELF/X86/X86Target.h index 30a0cdd..bc5c016 100644 --- a/lld/lib/ReaderWriter/ELF/X86/X86ELFTarget.h +++ b/lld/lib/ReaderWriter/ELF/X86/X86Target.h @@ -1,4 +1,4 @@ -//===- lib/ReaderWriter/ELF/Hexagon/X86ELFTarget.h -----------------------===// +//===- lib/ReaderWriter/ELF/X86/X86Target.h -------------------------------===// // // The LLVM Linker // @@ -6,4 +6,5 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#include "X86ELFTargetInfo.h" + +#include "X86TargetInfo.h" diff --git a/lld/lib/ReaderWriter/ELF/X86/X86ELFTargetInfo.h b/lld/lib/ReaderWriter/ELF/X86/X86TargetInfo.h similarity index 60% rename from lld/lib/ReaderWriter/ELF/X86/X86ELFTargetInfo.h rename to lld/lib/ReaderWriter/ELF/X86/X86TargetInfo.h index 071e075..7036daa 100644 --- a/lld/lib/ReaderWriter/ELF/X86/X86ELFTargetInfo.h +++ b/lld/lib/ReaderWriter/ELF/X86/X86TargetInfo.h @@ -1,4 +1,4 @@ -//===- lib/ReaderWriter/ELF/Hexagon/X86TargetInfo.h -----------------------===// +//===- lib/ReaderWriter/ELF/X86/X86TargetInfo.h ---------------------------===// // // The LLVM Linker // @@ -10,25 +10,26 @@ #ifndef LLD_READER_WRITER_ELF_X86_TARGETINFO_H #define LLD_READER_WRITER_ELF_X86_TARGETINFO_H -#include "lld/ReaderWriter/ELFTargetInfo.h" +#include "DefaultTargetHandler.h" + #include "lld/Core/LinkerOptions.h" +#include "lld/ReaderWriter/ELFTargetInfo.h" + #include "llvm/Object/ELF.h" #include "llvm/Support/ELF.h" -#include "DefaultELFTargetHandler.h" - namespace lld { namespace elf { -class X86ELFTargetInfo LLVM_FINAL : public ELFTargetInfo { +class X86TargetInfo LLVM_FINAL : public ELFTargetInfo { public: - X86ELFTargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) { - _targetHandler = std::unique_ptr( - new DefaultELFTargetHandler( + new DefaultTargetHandler >(*this)); } virtual uint64_t getPageSize() const { return 0x1000; } }; -} // elf -} // lld -#endif // LLD_READER_WRITER_ELF_X86_TARGETINFO_H +} // end namespace elf +} // end namespace lld +#endif diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFTarget.h b/lld/lib/ReaderWriter/ELF/X86_64/X86_64Target.h similarity index 68% rename from lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFTarget.h rename to lld/lib/ReaderWriter/ELF/X86_64/X86_64Target.h index 28b9245a..17f42c9 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFTarget.h +++ b/lld/lib/ReaderWriter/ELF/X86_64/X86_64Target.h @@ -1,4 +1,4 @@ -//===- lib/ReaderWriter/ELF/Hexagon/HexagonELFTarget.h ---------------------===// +//===- lib/ReaderWriter/ELF/Hexagon/X86Target.h ---------------------------===// // // The LLVM Linker // @@ -6,4 +6,5 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#include "HexagonELFTargetInfo.h" + +#include "X86_64TargetInfo.h" diff --git a/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp b/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp index c3d5856..11f47f4 100644 --- a/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp +++ b/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp @@ -1,4 +1,4 @@ -//===- lib/ReaderWriter/ELF/X86_64/X86_64ELFTargetInfo.cpp ----------------===// +//===- lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp -------------------===// // // The LLVM Linker // @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "X86_64ELFTargetInfo.h" +#include "X86_64TargetInfo.h" #include "lld/Core/File.h" #include "lld/Core/Pass.h" @@ -128,13 +128,14 @@ private: }; } // end anon namespace -void elf::X86_64ELFTargetInfo::addPasses(PassManager &pm) const { +void elf::X86_64TargetInfo::addPasses(PassManager &pm) const { pm.add(std::unique_ptr(new PLTPass(*this))); } #define LLD_CASE(name) .Case(#name, llvm::ELF::name) -ErrorOr elf::X86_64ELFTargetInfo::relocKindFromString(StringRef str) const { +ErrorOr elf::X86_64TargetInfo::relocKindFromString( + StringRef str) const { int32_t ret = llvm::StringSwitch(str) LLD_CASE(R_X86_64_NONE) LLD_CASE(R_X86_64_64) @@ -185,7 +186,8 @@ ErrorOr elf::X86_64ELFTargetInfo::relocKindFromString(StringRef str) co #define LLD_CASE(name) case llvm::ELF::name: return std::string(#name); -ErrorOr elf::X86_64ELFTargetInfo::stringFromRelocKind(int32_t kind) const { +ErrorOr elf::X86_64TargetInfo::stringFromRelocKind( + int32_t kind) const { switch (kind) { LLD_CASE(R_X86_64_NONE) LLD_CASE(R_X86_64_64) diff --git a/lld/lib/ReaderWriter/ELF/X86_64/X86_64ELFTargetInfo.h b/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.h similarity index 80% rename from lld/lib/ReaderWriter/ELF/X86_64/X86_64ELFTargetInfo.h rename to lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.h index 98cc43f..dccc750 100644 --- a/lld/lib/ReaderWriter/ELF/X86_64/X86_64ELFTargetInfo.h +++ b/lld/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.h @@ -1,4 +1,4 @@ -//===- lib/ReaderWriter/ELF/Hexagon/X86_64TargetInfo.h -----------------------===// +//===- lib/ReaderWriter/ELF/Hexagon/X86_64TargetInfo.h --------------------===// // // The LLVM Linker // @@ -10,7 +10,7 @@ #ifndef LLD_READER_WRITER_ELF_X86_64_TARGETINFO_H #define LLD_READER_WRITER_ELF_X86_64_TARGETINFO_H -#include "DefaultELFTargetHandler.h" +#include "DefaultTargetHandler.h" #include "lld/Core/LinkerOptions.h" #include "lld/ReaderWriter/ELFTargetInfo.h" @@ -20,11 +20,11 @@ namespace lld { namespace elf { -class X86_64ELFTargetInfo LLVM_FINAL : public ELFTargetInfo { +class X86_64TargetInfo LLVM_FINAL : public ELFTargetInfo { public: - X86_64ELFTargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) { - _targetHandler = std::unique_ptr( - new DefaultELFTargetHandler( + new DefaultTargetHandler >(*this)); } -- 2.7.4