[lld] r173838 - [ELF] Chop the ELF prefix off of most things.

Michael J. Spencer bigcheesegs at gmail.com
Tue Jan 29 14:03:40 PST 2013


Author: mspencer
Date: Tue Jan 29 16:03:39 2013
New Revision: 173838

URL: http://llvm.org/viewvc/llvm-project?rev=173838&view=rev
Log:
[ELF] Chop the ELF prefix off of most things.

Added:
    lld/trunk/lib/ReaderWriter/ELF/Atoms.h
      - copied, changed from r173824, lld/trunk/lib/ReaderWriter/ELF/AtomsELF.h
    lld/trunk/lib/ReaderWriter/ELF/Chunk.h
      - copied, changed from r173824, lld/trunk/lib/ReaderWriter/ELF/ELFChunk.h
    lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h
      - copied, changed from r173824, lld/trunk/lib/ReaderWriter/ELF/DefaultELFLayout.h
    lld/trunk/lib/ReaderWriter/ELF/DefaultTargetHandler.h
      - copied, changed from r173824, lld/trunk/lib/ReaderWriter/ELF/DefaultELFTargetHandler.h
    lld/trunk/lib/ReaderWriter/ELF/File.h
      - copied, changed from r173824, lld/trunk/lib/ReaderWriter/ELF/FileELF.h
    lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h
      - copied, changed from r173824, lld/trunk/lib/ReaderWriter/ELF/ELFHeaderChunks.h
    lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTarget.h
      - copied, changed from r173824, lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTarget.h
    lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h
      - copied, changed from r173824, lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTargetInfo.h
    lld/trunk/lib/ReaderWriter/ELF/Layout.h
      - copied, changed from r173824, lld/trunk/lib/ReaderWriter/ELF/ELFLayout.h
    lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTarget.h
      - copied, changed from r173824, lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTarget.h
    lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetInfo.h
      - copied, changed from r173824, lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTargetInfo.h
    lld/trunk/lib/ReaderWriter/ELF/Reader.cpp
      - copied, changed from r173824, lld/trunk/lib/ReaderWriter/ELF/ReaderELF.cpp
    lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h
      - copied, changed from r173824, lld/trunk/lib/ReaderWriter/ELF/ELFSectionChunks.h
    lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.h
      - copied, changed from r173824, lld/trunk/lib/ReaderWriter/ELF/ELFSegmentChunks.h
    lld/trunk/lib/ReaderWriter/ELF/TargetHandler.h
      - copied, changed from r173824, lld/trunk/lib/ReaderWriter/ELF/ELFTargetHandler.h
    lld/trunk/lib/ReaderWriter/ELF/TargetLayout.h
      - copied, changed from r173824, lld/trunk/lib/ReaderWriter/ELF/ELFTargetLayout.h
    lld/trunk/lib/ReaderWriter/ELF/Targets.h
      - copied, changed from r173824, lld/trunk/lib/ReaderWriter/ELF/ELFTargets.h
    lld/trunk/lib/ReaderWriter/ELF/Writer.cpp
      - copied, changed from r173824, lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp
    lld/trunk/lib/ReaderWriter/ELF/Writer.h
      - copied, changed from r173824, lld/trunk/lib/ReaderWriter/ELF/ELFWriter.h
    lld/trunk/lib/ReaderWriter/ELF/X86/X86Target.h
      - copied, changed from r173824, lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTarget.h
    lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetInfo.h
      - copied, changed from r173824, lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTargetInfo.h
    lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64Target.h
      - copied, changed from r173824, lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTarget.h
    lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.h
      - copied, changed from r173824, lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTargetInfo.h
Removed:
    lld/trunk/lib/ReaderWriter/ELF/AtomsELF.h
    lld/trunk/lib/ReaderWriter/ELF/DefaultELFLayout.h
    lld/trunk/lib/ReaderWriter/ELF/DefaultELFTargetHandler.h
    lld/trunk/lib/ReaderWriter/ELF/ELFChunk.h
    lld/trunk/lib/ReaderWriter/ELF/ELFHeaderChunks.h
    lld/trunk/lib/ReaderWriter/ELF/ELFLayout.h
    lld/trunk/lib/ReaderWriter/ELF/ELFSectionChunks.h
    lld/trunk/lib/ReaderWriter/ELF/ELFSegmentChunks.h
    lld/trunk/lib/ReaderWriter/ELF/ELFTargetHandler.h
    lld/trunk/lib/ReaderWriter/ELF/ELFTargetLayout.h
    lld/trunk/lib/ReaderWriter/ELF/ELFTargets.h
    lld/trunk/lib/ReaderWriter/ELF/ELFWriter.h
    lld/trunk/lib/ReaderWriter/ELF/FileELF.h
    lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTarget.h
    lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTargetInfo.h
    lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTarget.h
    lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTargetInfo.h
    lld/trunk/lib/ReaderWriter/ELF/ReaderELF.cpp
    lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp
    lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTarget.h
    lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTargetInfo.h
    lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTarget.h
    lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTargetInfo.h
Modified:
    lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h
    lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt
    lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp
    lld/trunk/lib/ReaderWriter/ELF/ExecutableAtoms.h
    lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp

Modified: lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h?rev=173838&r1=173837&r2=173838&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h (original)
+++ lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h Tue Jan 29 16:03:39 2013
@@ -21,11 +21,11 @@ namespace lld {
 class DefinedAtom;
 class Reference;
 
-namespace elf { template <typename ELFT> class ELFTargetHandler; }
+namespace elf { template <typename ELFT> class TargetHandler; }
 
-class ELFTargetHandlerBase {
+class TargetHandlerBase {
 public:
-  virtual ~ELFTargetHandlerBase() {}
+  virtual ~TargetHandlerBase() {}
 };
 
 class ELFTargetInfo : public TargetInfo {
@@ -47,13 +47,12 @@ public:
   static std::unique_ptr<ELFTargetInfo> create(const LinkerOptions &lo);
 
   template <typename ELFT>
-  lld::elf::ELFTargetHandler<ELFT> &getTargetHandler() const {
-    return static_cast<
-        lld::elf::ELFTargetHandler<ELFT> &>(*_targetHandler.get());
+  lld::elf::TargetHandler<ELFT> &getTargetHandler() const {
+    return static_cast<lld::elf::TargetHandler<ELFT> &>(*_targetHandler.get());
   }
 
 protected:
-  std::unique_ptr<ELFTargetHandlerBase> _targetHandler;
+  std::unique_ptr<TargetHandlerBase> _targetHandler;
 };
 } // end namespace lld
 

Copied: lld/trunk/lib/ReaderWriter/ELF/Atoms.h (from r173824, lld/trunk/lib/ReaderWriter/ELF/AtomsELF.h)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Atoms.h?p2=lld/trunk/lib/ReaderWriter/ELF/Atoms.h&p1=lld/trunk/lib/ReaderWriter/ELF/AtomsELF.h&r1=173824&r2=173838&rev=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/AtomsELF.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Atoms.h Tue Jan 29 16:03:39 2013
@@ -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 <vector>
 
 namespace lld {
+namespace elf {
+template <typename ELFT> class ELFFile;
+template <typename ELFT> class TargetAtomHandler;
 
-template <typename ELFT> class FileELF;
-
-namespace elf { template <typename ELFT> class ELFTargetAtomHandler; }
 /// \brief Relocation References: Defined Atoms may contain references that will
 /// need to be patched before the executable is written.
 template <class ELFT> class ELFReference LLVM_FINAL : public Reference {
@@ -93,12 +93,12 @@ class ELFAbsoluteAtom LLVM_FINAL : publi
   typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym;
 
 public:
-  ELFAbsoluteAtom(const FileELF<ELFT> &file, llvm::StringRef name,
+  ELFAbsoluteAtom(const ELFFile<ELFT> &file, StringRef name,
                   const Elf_Sym *symbol, uint64_t value)
       : _owningFile(file), _name(name), _symbol(symbol), _value(value) {
   }
 
-  virtual const class FileELF<ELFT> &file() const {
+  virtual const class ELFFile<ELFT> &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<ELFT> &_owningFile;
-  llvm::StringRef _name;
+  const ELFFile<ELFT> &_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 ELFT>
-class ELFUndefinedAtom LLVM_FINAL : public UndefinedAtom {
+class ELFUndefinedAtom LLVM_FINAL : public lld::UndefinedAtom {
   typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym;
 
 public:
-  ELFUndefinedAtom(const FileELF<ELFT> &file, llvm::StringRef name,
+  ELFUndefinedAtom(const ELFFile<ELFT> &file, StringRef name,
                    const Elf_Sym *symbol)
       : _owningFile(file), _name(name), _symbol(symbol) {}
 
-  virtual const class FileELF<ELFT> &file() const {
+  virtual const class ELFFile<ELFT> &file() const {
     return _owningFile;
   }
 
-  virtual llvm::StringRef name() const {
+  virtual StringRef name() const {
     return _name;
   }
 
@@ -154,8 +154,8 @@ public:
   }
 
 private:
-  const FileELF<ELFT> &_owningFile;
-  llvm::StringRef _name;
+  const ELFFile<ELFT> &_owningFile;
+  StringRef _name;
   const Elf_Sym *_symbol;
 };
 
@@ -167,9 +167,9 @@ class ELFDefinedAtom LLVM_FINAL : public
   typedef llvm::object::Elf_Shdr_Impl<ELFT> Elf_Shdr;
 
 public:
-  ELFDefinedAtom(const FileELF<ELFT> &file,
-                 llvm::StringRef symbolName,
-                 llvm::StringRef sectionName,
+  ELFDefinedAtom(const ELFFile<ELFT> &file,
+                 StringRef symbolName,
+                 StringRef sectionName,
                  const Elf_Sym *symbol,
                  const Elf_Shdr *section,
                  llvm::ArrayRef<uint8_t> contentData,
@@ -190,11 +190,11 @@ public:
     _ordinal = ++orderNumber;
   }
 
-  virtual const class FileELF<ELFT> &file() const {
+  virtual const class ELFFile<ELFT> &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<ELFT> &elfTargetHandler =
+      TargetHandler<ELFT> &TargetHandler =
           eti.getTargetHandler<ELFT>();
-      elf::ELFTargetAtomHandler<ELFT> &elfAtomHandler =
-          elfTargetHandler.targetAtomHandler();
+      TargetAtomHandler<ELFT> &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<ELFT> &_owningFile;
-  llvm::StringRef _symbolName;
-  llvm::StringRef _sectionName;
+  const ELFFile<ELFT> &_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<ELFReference<ELFT>*> &
     _referenceList;
 };
-} // namespace lld
+} // end namespace elf
+} // end namespace lld
+
 #endif

Removed: lld/trunk/lib/ReaderWriter/ELF/AtomsELF.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/AtomsELF.h?rev=173837&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/AtomsELF.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/AtomsELF.h (removed)
@@ -1,436 +0,0 @@
-//===- lib/ReaderWriter/ELF/AtomELF.h -------------------------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_READER_WRITER_ELF_ATOMS_ELF_H
-#define LLD_READER_WRITER_ELF_ATOMS_ELF_H
-
-#include "ELFTargetHandler.h"
-
-#include "lld/Core/LLVM.h"
-
-#include "llvm/ADT/ArrayRef.h"
-
-#include <memory>
-#include <vector>
-
-namespace lld {
-
-template <typename ELFT> class FileELF;
-
-namespace elf { template <typename ELFT> class ELFTargetAtomHandler; }
-/// \brief Relocation References: Defined Atoms may contain references that will
-/// need to be patched before the executable is written.
-template <class ELFT> class ELFReference LLVM_FINAL : public Reference {
-  typedef llvm::object::Elf_Rel_Impl<ELFT, false> Elf_Rel;
-  typedef llvm::object::Elf_Rel_Impl<ELFT, true> Elf_Rela;
-public:
-
-  ELFReference(const Elf_Rela *rela, uint64_t offset, const Atom *target)
-    : _target(target)
-    , _targetSymbolIndex(rela->getSymbol())
-    , _offsetInAtom(offset)
-    , _addend(rela->r_addend)
-    , _kind(rela->getType()) {}
-
-  ELFReference(const Elf_Rel *rel, uint64_t offset, const Atom *target)
-    : _target(target)
-    , _targetSymbolIndex(rel->getSymbol())
-    , _offsetInAtom(offset)
-    , _addend(0)
-    , _kind(rel->getType()) {}
-
-  virtual uint64_t offsetInAtom() const {
-    return _offsetInAtom;
-  }
-
-  virtual Kind kind() const {
-    return _kind;
-  }
-
-  virtual void setKind(Kind kind) {
-    _kind = kind;
-  }
-
-  virtual const Atom *target() const {
-    return _target;
-  }
-
-  /// \brief The symbol table index that contains the target reference.
-  uint64_t targetSymbolIndex() const {
-    return _targetSymbolIndex;
-  }
-
-  virtual Addend addend() const {
-    return _addend;
-  }
-
-  virtual void setAddend(Addend A) {
-    _addend = A;
-  }
-
-  virtual void setTarget(const Atom *newAtom) {
-    _target = newAtom;
-  }
-private:
-  const Atom  *_target;
-  uint64_t     _targetSymbolIndex;
-  uint64_t     _offsetInAtom;
-  Addend       _addend;
-  Kind         _kind;
-};
-
-/// \brief These atoms store symbols that are fixed to a particular address.
-/// This atom has no content its address will be used by the writer to fixup
-/// references that point to it.
-template<class ELFT>
-class ELFAbsoluteAtom LLVM_FINAL : public AbsoluteAtom {
-  typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym;
-
-public:
-  ELFAbsoluteAtom(const FileELF<ELFT> &file, llvm::StringRef name,
-                  const Elf_Sym *symbol, uint64_t value)
-      : _owningFile(file), _name(name), _symbol(symbol), _value(value) {
-  }
-
-  virtual const class FileELF<ELFT> &file() const {
-    return _owningFile;
-  } virtual Scope scope() const {
-    if (_symbol->st_other == llvm::ELF::STV_HIDDEN)
-      return scopeLinkageUnit;
-    if (_symbol->getBinding() == llvm::ELF::STB_LOCAL)
-      return scopeTranslationUnit;
-    else
-      return scopeGlobal;
-  }
-
-  virtual llvm::StringRef name() const {
-    return _name;
-  }
-
-  virtual uint64_t value() const {
-    return _value;
-  }
-
-private:
-  const FileELF<ELFT> &_owningFile;
-  llvm::StringRef _name;
-  const Elf_Sym *_symbol;
-  uint64_t _value;
-};
-
-/// \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 ELFT>
-class ELFUndefinedAtom LLVM_FINAL : public UndefinedAtom {
-  typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym;
-
-public:
-  ELFUndefinedAtom(const FileELF<ELFT> &file, llvm::StringRef name,
-                   const Elf_Sym *symbol)
-      : _owningFile(file), _name(name), _symbol(symbol) {}
-
-  virtual const class FileELF<ELFT> &file() const {
-    return _owningFile;
-  }
-
-  virtual llvm::StringRef name() const {
-    return _name;
-  }
-
-  // FIXME: What distinguishes a symbol in ELF that can help decide if the
-  // symbol is undefined only during build and not runtime? This will make us
-  // choose canBeNullAtBuildtime and canBeNullAtRuntime.
-  virtual CanBeNull canBeNull() const {
-    if (_symbol->getBinding() == llvm::ELF::STB_WEAK)
-      return CanBeNull::canBeNullAtBuildtime;
-    else
-      return CanBeNull::canBeNullNever;
-  }
-
-private:
-  const FileELF<ELFT> &_owningFile;
-  llvm::StringRef _name;
-  const Elf_Sym *_symbol;
-};
-
-/// \brief This atom stores defined symbols and will contain either data or
-/// code.
-template<class ELFT>
-class ELFDefinedAtom LLVM_FINAL : public DefinedAtom {
-  typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym;
-  typedef llvm::object::Elf_Shdr_Impl<ELFT> Elf_Shdr;
-
-public:
-  ELFDefinedAtom(const FileELF<ELFT> &file,
-                 llvm::StringRef symbolName,
-                 llvm::StringRef sectionName,
-                 const Elf_Sym *symbol,
-                 const Elf_Shdr *section,
-                 llvm::ArrayRef<uint8_t> contentData,
-                 unsigned int referenceStart,
-                 unsigned int referenceEnd,
-                 std::vector<ELFReference<ELFT>*> &referenceList)
-
-    : _owningFile(file)
-    , _symbolName(symbolName)
-    , _sectionName(sectionName)
-    , _symbol(symbol)
-    , _section(section)
-    , _contentData(contentData)
-    , _referenceStartIndex(referenceStart)
-    , _referenceEndIndex(referenceEnd)
-    , _referenceList(referenceList) {
-    static uint64_t orderNumber = 0;
-    _ordinal = ++orderNumber;
-  }
-
-  virtual const class FileELF<ELFT> &file() const {
-    return _owningFile;
-  }
-
-  virtual llvm::StringRef name() const {
-    return _symbolName;
-  }
-
-  virtual uint64_t ordinal() const {
-    return _ordinal;
-  }
-
-  virtual uint64_t size() const {
-    // Common symbols are not allocated in object files,
-    // so use st_size to tell how many bytes are required.
-    if ((_symbol->getType() == llvm::ELF::STT_COMMON)
-        || _symbol->st_shndx == llvm::ELF::SHN_COMMON)
-      return (uint64_t)_symbol->st_size;
-
-    return _contentData.size();
-  }
-
-  virtual Scope scope() const {
-    if (_symbol->st_other == llvm::ELF::STV_HIDDEN)
-      return scopeLinkageUnit;
-    else if (_symbol->getBinding() != llvm::ELF::STB_LOCAL)
-      return scopeGlobal;
-    else
-      return scopeTranslationUnit;
-  }
-
-  // FIXME: Need to revisit this in future.
-  virtual Interposable interposable() const {
-    return interposeNo;
-  }
-
-  // FIXME: What ways can we determine this in ELF?
-  virtual Merge merge() const {
-    if (_symbol->getBinding() == llvm::ELF::STB_WEAK)
-      return mergeAsWeak;
-
-    if ((_symbol->getType() == llvm::ELF::STT_COMMON)
-        || _symbol->st_shndx == llvm::ELF::SHN_COMMON)
-      return mergeAsTentative;
-
-    return mergeNo;
-  }
-
-  virtual ContentType contentType() const {
-    ContentType ret = typeUnknown;
-    uint64_t flags = _section->sh_flags;
-
-    if (_symbol->st_shndx > llvm::ELF::SHN_LOPROC &&
-        _symbol->st_shndx < llvm::ELF::SHN_HIPROC) {
-      const ELFTargetInfo &eti =
-          (_owningFile.getTargetInfo());
-      elf::ELFTargetHandler<ELFT> &elfTargetHandler =
-          eti.getTargetHandler<ELFT>();
-      elf::ELFTargetAtomHandler<ELFT> &elfAtomHandler =
-          elfTargetHandler.targetAtomHandler();
-      return elfAtomHandler.contentType(this);
-    }
-
-    if (_symbol->getType() == llvm::ELF::STT_GNU_IFUNC)
-      return typeResolver;
-
-    if (_symbol->st_shndx == llvm::ELF::SHN_COMMON)
-      return typeZeroFill;
-
-    switch (_section->sh_type) {
-    case llvm::ELF::SHT_PROGBITS:
-      flags &= ~llvm::ELF::SHF_ALLOC;
-      flags &= ~llvm::ELF::SHF_GROUP;
-      switch (flags) {
-      case llvm::ELF::SHF_EXECINSTR:
-      case (llvm::ELF::SHF_WRITE|llvm::ELF::SHF_EXECINSTR):
-        ret = typeCode;
-        break;
-      case llvm::ELF::SHF_WRITE:
-        ret = typeData;
-        break;
-      case (llvm::ELF::SHF_MERGE|llvm::ELF::SHF_STRINGS):
-      case llvm::ELF::SHF_STRINGS:
-        ret = typeConstant;
-        break;
-      default:
-        ret = typeCode;
-        break;
-      }
-      break;
-    case llvm::ELF::SHT_NOBITS:
-      ret = typeZeroFill;
-      break;
-    case llvm::ELF::SHT_NULL:
-      if ((_symbol->getType() == llvm::ELF::STT_COMMON)
-          || _symbol->st_shndx == llvm::ELF::SHN_COMMON)
-        ret = typeZeroFill;
-      break;
-    case llvm::ELF::SHT_INIT_ARRAY:
-      ret = typeData;
-      break;
-    }
-
-    return ret;
-  }
-
-  virtual Alignment alignment() const {
-    // Unallocated common symbols specify their alignment constraints in
-    // st_value.
-    if ((_symbol->getType() == llvm::ELF::STT_COMMON)
-        || _symbol->st_shndx == llvm::ELF::SHN_COMMON) {
-      return Alignment(llvm::Log2_64(_symbol->st_value));
-    }
-    return Alignment(llvm::Log2_64(_section->sh_addralign),
-                     _symbol->st_value % _section->sh_addralign);
-  }
-
-  // Do we have a choice for ELF?  All symbols live in explicit sections.
-  virtual SectionChoice sectionChoice() const {
-    if (_symbol->st_shndx > llvm::ELF::SHN_LORESERVE)
-      return sectionBasedOnContent;
-
-    return sectionCustomRequired;
-  }
-
-  virtual llvm::StringRef customSectionName() const {
-    if ((contentType() == typeZeroFill) ||
-        (_symbol->st_shndx == llvm::ELF::SHN_COMMON))
-      return ".bss";
-    return _sectionName;
-  }
-
-  virtual SectionPosition sectionPosition() const {
-    return sectionPositionAny;
-  }
-
-  // It isn't clear that __attribute__((used)) is transmitted to the ELF object
-  // file.
-  virtual DeadStripKind deadStrip() const {
-    return deadStripNormal;
-  }
-
-  virtual ContentPermissions permissions() const {
-    uint64_t flags = _section->sh_flags;
-    switch (_section->sh_type) {
-    // permRW_L is for sections modified by the runtime
-    // loader.
-    case llvm::ELF::SHT_REL:
-    case llvm::ELF::SHT_RELA:
-      return permRW_L;
-
-    case llvm::ELF::SHT_DYNAMIC:
-    case llvm::ELF::SHT_PROGBITS:
-      flags &= ~llvm::ELF::SHF_ALLOC;
-      flags &= ~llvm::ELF::SHF_GROUP;
-      switch (flags) {
-      // Code
-      case llvm::ELF::SHF_EXECINSTR:
-        return permR_X;
-      case (llvm::ELF::SHF_WRITE|llvm::ELF::SHF_EXECINSTR):
-        return permRWX;
-      // Data
-      case llvm::ELF::SHF_WRITE:
-        return permRW_;
-      // Strings
-      case llvm::ELF::SHF_MERGE:
-      case llvm::ELF::SHF_STRINGS:
-        return permR__;
-
-      default:
-        if (flags & llvm::ELF::SHF_WRITE)
-          return permRW_;
-        return permR__;
-      }
-
-    case llvm::ELF::SHT_NOBITS:
-      return permRW_;
-
-    case llvm::ELF::SHT_INIT_ARRAY:
-      return permRW_;
-
-    default:
-      return perm___;
-    }
-  }
-
-  // Many non ARM architectures use ELF file format This not really a place to
-  // put a architecture specific method in an atom. A better approach is needed.
-  virtual bool isThumb() const {
-    return false;
-  }
-
-  // FIXME: Not Sure if ELF supports alias atoms. Find out more.
-  virtual bool isAlias() const {
-    return false;
-  }
-
-  virtual llvm::ArrayRef<uint8_t> rawContent() const {
-    return _contentData;
-  }
-
-  DefinedAtom::reference_iterator begin() const {
-    uintptr_t index = _referenceStartIndex;
-    const void *it = reinterpret_cast<const void*>(index);
-    return reference_iterator(*this, it);
-  }
-
-  DefinedAtom::reference_iterator end() const {
-    uintptr_t index = _referenceEndIndex;
-    const void *it = reinterpret_cast<const void*>(index);
-    return reference_iterator(*this, it);
-  }
-
-  const Reference *derefIterator(const void *It) const {
-    uintptr_t index = reinterpret_cast<uintptr_t>(It);
-    assert(index >= _referenceStartIndex);
-    assert(index < _referenceEndIndex);
-    return ((_referenceList)[index]);
-  }
-
-  void incrementIterator(const void*& It) const {
-    uintptr_t index = reinterpret_cast<uintptr_t>(It);
-    ++index;
-    It = reinterpret_cast<const void*>(index);
-  }
-
-private:
-
-  const FileELF<ELFT> &_owningFile;
-  llvm::StringRef _symbolName;
-  llvm::StringRef _sectionName;
-  const Elf_Sym *_symbol;
-  const Elf_Shdr *_section;
-  /// \brief Holds the bits that make up the atom.
-  llvm::ArrayRef<uint8_t> _contentData;
-
-  uint64_t _ordinal;
-  unsigned int _referenceStartIndex;
-  unsigned int _referenceEndIndex;
-  std::vector<ELFReference<ELFT>*> &
-    _referenceList;
-};
-} // namespace lld
-#endif

Modified: lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt?rev=173838&r1=173837&r2=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt (original)
+++ lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt Tue Jan 29 16:03:39 2013
@@ -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
   )

Copied: lld/trunk/lib/ReaderWriter/ELF/Chunk.h (from r173824, lld/trunk/lib/ReaderWriter/ELF/ELFChunk.h)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Chunk.h?p2=lld/trunk/lib/ReaderWriter/ELF/Chunk.h&p1=lld/trunk/lib/ReaderWriter/ELF/ELFChunk.h&r1=173824&r2=173838&rev=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFChunk.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Chunk.h Tue Jan 29 16:03:39 2013
@@ -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

Removed: lld/trunk/lib/ReaderWriter/ELF/DefaultELFLayout.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/DefaultELFLayout.h?rev=173837&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/DefaultELFLayout.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/DefaultELFLayout.h (removed)
@@ -1,658 +0,0 @@
-//===- lib/ReaderWriter/ELF/DefaultELFLayout.h ---------------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_READER_WRITER_DEFAULT_ELF_LAYOUT_H_
-#define LLD_READER_WRITER_DEFAULT_ELF_LAYOUT_H_
-
-#include "ELFChunk.h"
-#include "ELFHeaderChunks.h"
-#include "ELFLayout.h"
-#include "ELFSectionChunks.h"
-#include "ELFSegmentChunks.h"
-
-#include "lld/Core/LinkerOptions.h"
-
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/Hashing.h"
-#include "llvm/ADT/OwningPtr.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringExtras.h"
-#include "llvm/ADT/StringMap.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/StringSwitch.h"
-
-#include <map>
-#include <tuple>
-#include <unordered_map>
-
-/// \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 {
-
-template<class ELFT>
-class DefaultELFLayout : public ELFLayout {
-public:
-
-  // The order in which the sections appear in the output file
-  // If its determined, that the layout needs to change
-  // just changing the order of enumerations would essentially
-  // change the layout in the output file
-  // Change the enumerations so that Target can override and stick 
-  // a section anywhere it wants to
-  enum DefaultSectionOrder {
-    ORDER_NOT_DEFINED = 0,
-    ORDER_INTERP = 10,
-    ORDER_NOTE = 20,
-    ORDER_HASH = 30,
-    ORDER_DYNAMIC_SYMBOLS = 40,
-    ORDER_DYNAMIC_STRINGS = 50,
-    ORDER_INIT = 60,
-    ORDER_TEXT = 70,
-    ORDER_PLT = 80,
-    ORDER_FINI = 90,
-    ORDER_REL = 95,
-    ORDER_RODATA = 100,
-    ORDER_EH_FRAME = 110,
-    ORDER_EH_FRAMEHDR = 120,
-    ORDER_CTORS = 130,
-    ORDER_DTORS = 140,
-    ORDER_INIT_ARRAY = 150,
-    ORDER_FINI_ARRAY = 160,
-    ORDER_DYNAMIC = 170,
-    ORDER_GOT = 180,
-    ORDER_GOT_PLT = 190,
-    ORDER_DATA = 200,
-    ORDER_BSS = 210,
-    ORDER_OTHER = 220,
-    ORDER_SECTION_STRINGS = 230,
-    ORDER_SYMBOL_TABLE = 240,
-    ORDER_STRING_TABLE = 250,
-    ORDER_SECTION_HEADERS = 260
-  };
-
-public:
-
-  // The Key used for creating Sections
-  // The sections are created using
-  // SectionName, contentPermissions
-  struct SectionKey {
-    SectionKey(StringRef name, DefinedAtom::ContentPermissions perm)
-        : _name(name), _perm(perm) {
-    }
-
-    // Data members
-    const StringRef _name;
-    DefinedAtom::ContentPermissions _perm;
-  };
-
-  struct SectionKeyHash {
-    int64_t operator()(const SectionKey &k) const {
-      return llvm::hash_combine(k._name, k._perm);
-    }
-  };
-
-  struct SectionKeyEq {
-    bool operator()(const SectionKey &lhs, const SectionKey &rhs) const {
-      return ((lhs._name == rhs._name) && (lhs._perm == rhs._perm));
-    }
-  };
-
-  typedef typename std::vector<Chunk<ELFT> *>::iterator ChunkIter;
-  // The key used for Segments
-  // The segments are created using
-  // SegmentName, Segment flags
-  typedef std::pair<StringRef, int64_t> SegmentKey;
-  // Merged Sections contain the map of Sectionnames to a vector of sections,
-  // that have been merged to form a single section
-  typedef std::map<StringRef, MergedSections<ELFT> *> MergedSectionMapT;
-  typedef typename std::vector<
-      MergedSections<ELFT> *>::iterator MergedSectionIter;
-
-  // HashKey for the Segment
-  class SegmentHashKey {
-  public:
-    int64_t operator() (const SegmentKey &k) const {
-      // k.first = SegmentName
-      // k.second = SegmentFlags
-      return llvm::hash_combine(k.first, k.second);
-    }
-  };
-
-  typedef std::unordered_map<SectionKey, Section<ELFT> *, SectionKeyHash,
-                             SectionKeyEq> SectionMapT;
-  typedef std::unordered_map<SegmentKey, Segment<ELFT> *,
-                             SegmentHashKey> SegmentMapT;
-
-  /// \brief All absolute atoms are created in the ELF Layout by using 
-  /// an AbsoluteAtomPair. Contains a pair of AbsoluteAtom and the 
-  /// value which is the address of the absolute atom
-  class AbsoluteAtomPair {
-  public:
-    AbsoluteAtomPair(const AbsoluteAtom *a, int64_t value) 
-                     : _absoluteAtom(a)
-                     , _value(value) { }
-
-    const AbsoluteAtom *absoluteAtom() { return _absoluteAtom; }
-    int64_t value() const { return _value; }
-    void setValue(int64_t val) { _value = val; }
-
-  private:
-    const AbsoluteAtom *_absoluteAtom;
-    int64_t _value;
-  };
-
-  /// \brief find a absolute atom pair given a absolute atom name
-  struct FindByName {
-    const std::string _name;
-    FindByName(StringRef name) : _name(name) {}
-    bool operator()(AbsoluteAtomPair& j) { 
-      return j.absoluteAtom()->name() == _name; 
-    }
-  };
-
-  typedef typename std::vector<AbsoluteAtomPair>::iterator AbsoluteAtomIterT;
-
-  DefaultELFLayout(const ELFTargetInfo &ti) : _targetInfo(ti) {}
-
-  /// \brief Return the section order for a input section
-  virtual SectionOrder getSectionOrder
-              (const StringRef name,
-              int32_t contentType,
-              int32_t contentPermissions);
-
-  /// \brief This maps the input sections to the output section names
-  StringRef getSectionName(const StringRef name,
-                           const int32_t contentType);
-
-  /// \brief Gets the segment for a output section
-  virtual ELFLayout::SegmentType getSegmentType(Section<ELFT> *section) const;
-
-  /// \brief Returns true/false depending on whether the section has a Output
-  //         segment or not
-  static bool hasOutputSegment(Section<ELFT> *section);
-
-  // Adds an atom to the section
-  virtual error_code addAtom(const Atom *atom);
-
-  /// \brief Find an output Section given a section name.
-  MergedSections<ELFT> *findOutputSection(StringRef name) {
-    auto iter = _mergedSectionMap.find(name);
-    if (iter == _mergedSectionMap.end()) 
-      return nullptr;
-    return iter->second;
-  }
-
-  /// \brief find a absolute atom given a name
-  AbsoluteAtomIterT findAbsoluteAtom(const StringRef name) {
-    return std::find_if(_absoluteAtoms.begin(), _absoluteAtoms.end(),
-                                                FindByName(name));
-  }
-
-  // Merge sections with the same name into a MergedSections
-  void mergeSimiliarSections();
-
-  void assignSectionsToSegments();
-
-  void assignVirtualAddress();
-
-  void assignOffsetsForMiscSections();
-
-  void assignFileOffsets();
-
-  /// Inline functions
-  inline range<AbsoluteAtomIterT> absoluteAtoms() { return _absoluteAtoms; }
-
-  inline void addSection(Chunk<ELFT> *c) {
-    _sections.push_back(c);
-  }
-
-  inline void finalize() {
-    for (auto &si : _sections)
-      si->finalize();
-  }
-
-  inline bool findAtomAddrByName(const StringRef name, uint64_t &addr) {
-    for (auto sec : _sections)
-      if (auto section = dyn_cast<Section<ELFT>>(sec))
-        if (section->findAtomAddrByName(name, addr))
-         return true;
-    return false;
-  }
-
-  inline void setELFHeader(ELFHeader<ELFT> *e) {
-    _elfHeader = e;
-  }
-
-  inline void setProgramHeader(ELFProgramHeader<ELFT> *p) {
-    _programHeader = p;
-  }
-
-  inline range<MergedSectionIter> mergedSections() { return _mergedSections; }
-
-  inline range<ChunkIter> sections() { return _sections; }
-
-  inline range<ChunkIter> segments() { return _segments; }
-
-  inline ELFHeader<ELFT> *elfHeader() {
-    return _elfHeader;
-  }
-
-  inline ELFProgramHeader<ELFT> *elfProgramHeader() {
-    return _programHeader;
-  }
-
-  ELFRelocationTable<ELFT> *getRelocationTable() {
-    // Only create the relocation table if it is needed.
-    if (!_relocationTable) {
-      _relocationTable = new (_allocator)
-          ELFRelocationTable<ELFT>(_targetInfo, ".rela.plt", ORDER_REL);
-      addSection(_relocationTable);
-    }
-    return _relocationTable;
-  }
-
-private:
-  SectionMapT _sectionMap;
-  MergedSectionMapT _mergedSectionMap;
-  SegmentMapT _segmentMap;
-  std::vector<Chunk<ELFT> *> _sections;
-  std::vector<Segment<ELFT> *> _segments;
-  std::vector<MergedSections<ELFT> *> _mergedSections;
-  ELFHeader<ELFT> *_elfHeader;
-  ELFProgramHeader<ELFT> *_programHeader;
-  ELFRelocationTable<ELFT> *_relocationTable;
-  std::vector<AbsoluteAtomPair> _absoluteAtoms;
-  llvm::BumpPtrAllocator _allocator;
-  const ELFTargetInfo &_targetInfo;
-};
-
-template<class ELFT>
-ELFLayout::SectionOrder
-DefaultELFLayout<ELFT>::getSectionOrder(const StringRef name, 
-                                        int32_t contentType,
-                                        int32_t contentPermissions)
-{
-  switch (contentType) {
-  case DefinedAtom::typeResolver:
-  case DefinedAtom::typeCode:
-    return llvm::StringSwitch<Reference::Kind>(name)
-      .StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR)
-      .StartsWith(".eh_frame", ORDER_EH_FRAME)
-      .StartsWith(".init", ORDER_INIT)
-      .StartsWith(".fini", ORDER_FINI)
-      .StartsWith(".hash", ORDER_HASH)
-      .Default(ORDER_TEXT);
-  
-  case DefinedAtom::typeConstant:
-    return ORDER_RODATA;
-  
-  case DefinedAtom::typeData:
-    return llvm::StringSwitch<Reference::Kind>(name)
-      .StartsWith(".init_array", ORDER_INIT_ARRAY)
-      .Default(ORDER_DATA);
-  
-  case DefinedAtom::typeZeroFill:
-    return ORDER_BSS;
-
-  case DefinedAtom::typeGOT:
-    return ORDER_GOT;
-  case DefinedAtom::typeStub:
-    return ORDER_PLT;
-  
-  default:
-    // If we get passed in a section push it to OTHER
-    if (contentPermissions == DefinedAtom::perm___)
-      return ORDER_OTHER;
-  
-    return ORDER_NOT_DEFINED;
-  }
-}
-
-/// \brief This maps the input sections to the output section names
-template<class ELFT>
-StringRef 
-DefaultELFLayout<ELFT>::getSectionName(const StringRef name, 
-                                       const int32_t contentType) {
-  if (contentType == DefinedAtom::typeZeroFill)
-    return ".bss";
-  if (name.startswith(".text"))
-    return ".text";
-  if (name.startswith(".rodata"))
-    return ".rodata";
-  return name;
-}
-
-/// \brief Gets the segment for a output section
-template<class ELFT>
-ELFLayout::SegmentType 
-DefaultELFLayout<ELFT>::getSegmentType(Section<ELFT> *section) const {
-  switch(section->order()) {
-  case ORDER_INTERP:
-    return llvm::ELF::PT_INTERP;
-
-  case ORDER_TEXT:
-  case ORDER_HASH:
-  case ORDER_DYNAMIC_SYMBOLS:
-  case ORDER_DYNAMIC_STRINGS:
-  case ORDER_REL:
-  case ORDER_INIT:
-  case ORDER_PLT:
-  case ORDER_FINI:
-  case ORDER_RODATA:
-  case ORDER_EH_FRAME:
-  case ORDER_EH_FRAMEHDR:
-    return llvm::ELF::PT_LOAD;
-
-  case ORDER_NOTE:
-    return llvm::ELF::PT_NOTE;
-
-  case ORDER_DYNAMIC:
-    return llvm::ELF::PT_DYNAMIC;
-
-  case ORDER_CTORS:
-  case ORDER_DTORS:
-    return llvm::ELF::PT_GNU_RELRO;
-
-  case ORDER_GOT:
-  case ORDER_GOT_PLT:
-  case ORDER_DATA:
-  case ORDER_BSS:
-  case ORDER_INIT_ARRAY:
-  case ORDER_FINI_ARRAY:
-    return llvm::ELF::PT_LOAD;
-
-  default:
-    return llvm::ELF::PT_NULL;
-  }
-}
-
-template<class ELFT>
-bool
-DefaultELFLayout<ELFT>::hasOutputSegment(Section<ELFT> *section) {
-  switch(section->order()) {
-  case ORDER_INTERP:
-  case ORDER_HASH:
-  case ORDER_DYNAMIC_SYMBOLS:
-  case ORDER_DYNAMIC_STRINGS:
-  case ORDER_REL:
-  case ORDER_INIT:
-  case ORDER_PLT:
-  case ORDER_TEXT:
-  case ORDER_FINI:
-  case ORDER_RODATA:
-  case ORDER_EH_FRAME:
-  case ORDER_EH_FRAMEHDR:
-  case ORDER_NOTE:
-  case ORDER_DYNAMIC:
-  case ORDER_CTORS:
-  case ORDER_DTORS:
-  case ORDER_GOT:
-  case ORDER_GOT_PLT:
-  case ORDER_DATA:
-  case ORDER_INIT_ARRAY:
-  case ORDER_FINI_ARRAY:
-  case ORDER_BSS:
-    return true;
-  
-  default:
-    return false;
-  }
-}
-
-template<class ELFT>
-error_code
-DefaultELFLayout<ELFT>::addAtom(const Atom *atom) {
-  if (const DefinedAtom *definedAtom = dyn_cast<DefinedAtom>(atom)) {
-    const StringRef sectionName = getSectionName(
-        definedAtom->customSectionName(), definedAtom->contentType());
-    const lld::DefinedAtom::ContentPermissions permissions =
-        definedAtom->permissions();
-    const lld::DefinedAtom::ContentType contentType =
-        definedAtom->contentType();
-    const SectionKey sectionKey(sectionName, permissions);
-    Section<ELFT> *section;
-
-    if (_sectionMap.find(sectionKey) == _sectionMap.end()) {
-      SectionOrder section_order =
-          getSectionOrder(sectionName, contentType, permissions);
-      section = new (_allocator) Section<ELFT>(
-          _targetInfo, sectionName, contentType, permissions, section_order);
-      section->setOrder(section_order);
-      _sections.push_back(section);
-      _sectionMap.insert(std::make_pair(sectionKey, section));
-    } else {
-      section = _sectionMap[sectionKey];
-    }
-    section->appendAtom(atom);
-    // Add runtime relocations to the .rela section.
-    for (const auto &reloc : *definedAtom)
-      if (_targetInfo.isRuntimeRelocation(*definedAtom, *reloc))
-        getRelocationTable()->addRelocation(*definedAtom, *reloc);
-  } else if (const AbsoluteAtom *absoluteAtom = dyn_cast<AbsoluteAtom>(atom)) {
-    // Absolute atoms are not part of any section, they are global for the whole
-    // link
-    _absoluteAtoms.push_back(AbsoluteAtomPair(absoluteAtom,
-                                              absoluteAtom->value()));
-  } else {
-    llvm_unreachable("Only absolute / defined atoms can be added here");
-  }
-  return error_code::success();
-}
-
-/// Merge sections with the same name into a MergedSections
-template<class ELFT>
-void 
-DefaultELFLayout<ELFT>::mergeSimiliarSections() {
-  MergedSections<ELFT> *mergedSection;
-
-  for (auto &si : _sections) {
-    const std::pair<StringRef, MergedSections<ELFT> *>
-      currentMergedSections(si->name(), nullptr);
-    std::pair<typename MergedSectionMapT::iterator, bool>
-                            mergedSectionInsert
-                            (_mergedSectionMap.insert(currentMergedSections));
-    if (!mergedSectionInsert.second) {
-      mergedSection = mergedSectionInsert.first->second;
-    } else {
-      mergedSection = new (_allocator.Allocate<MergedSections<ELFT>>())
-        MergedSections<ELFT>(si->name());
-      _mergedSections.push_back(mergedSection);
-      mergedSectionInsert.first->second = mergedSection;
-    }
-    mergedSection->appendSection(si);
-  }
-}
-
-template<class ELFT>
-void 
-DefaultELFLayout<ELFT>::assignSectionsToSegments() {
-  // sort the sections by their order as defined by the layout
-  std::stable_sort(_sections.begin(), _sections.end(),
-  [](Chunk<ELFT> *A, Chunk<ELFT> *B) {
-     return A->order() < B->order();
-  });
-  // Merge all sections
-  mergeSimiliarSections();
-  // Set the ordinal after sorting the sections
-  int ordinal = 1;
-  for (auto msi : _mergedSections) {
-    msi->setOrdinal(ordinal);
-    for (auto ai : msi->sections()) {
-      ai->setOrdinal(ordinal);
-    }
-    ++ordinal;
-  }
-  for (auto msi : _mergedSections) {
-    for (auto ai : msi->sections()) {
-      if (auto section = dyn_cast<Section<ELFT>>(ai)) {
-        if (!hasOutputSegment(section))
-          continue;
-        msi->setHasSegment();
-        section->setSegment(getSegmentType(section));
-        const StringRef segmentName = section->segmentKindToStr();
-        // Use the flags of the merged Section for the segment
-        const SegmentKey key(segmentName, msi->flags());
-        const std::pair<SegmentKey, Segment<ELFT> *>
-          currentSegment(key, nullptr);
-        std::pair<typename SegmentMapT::iterator, bool>
-                            segmentInsert(_segmentMap.insert(currentSegment));
-        Segment<ELFT> *segment;
-        if (!segmentInsert.second) {
-          segment = segmentInsert.first->second;
-        } else {
-          segment = new (_allocator)
-              Segment<ELFT>(_targetInfo, segmentName, getSegmentType(section));
-          segmentInsert.first->second = segment;
-          _segments.push_back(segment);
-        }
-        segment->append(section);
-      }
-    }
-  }
-}
-
-template<class ELFT>
-void
-DefaultELFLayout<ELFT>::assignFileOffsets() {
-  std::sort(_segments.begin(), _segments.end(),
-            Segment<ELFT>::compareSegments);
-  int ordinal = 0;
-  // Compute the number of segments that might be needed, so that the
-  // size of the program header can be computed
-  uint64_t offset = 0;
-  for (auto si : _segments) {
-    si->setOrdinal(++ordinal);
-    si->assignOffsets(offset);
-    offset += si->fileSize();
-  }
-}
-
-
-template<class ELFT>
-void
-DefaultELFLayout<ELFT>::assignVirtualAddress() {
-  if (_segments.empty())
-    return;
-  
-  uint64_t virtualAddress = _targetInfo.getBaseAddress();
-  
-  // HACK: This is a super dirty hack. The elf header and program header are
-  // not part of a section, but we need them to be loaded at the base address
-  // so that AT_PHDR is set correctly by the loader and so they are accessible
-  // 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);
-  
-  bool newSegmentHeaderAdded = true;
-  while (true) {
-    for (auto si : _segments) {
-      newSegmentHeaderAdded = _programHeader->addSegment(si);
-    }
-    if (!newSegmentHeaderAdded)
-      break;
-    uint64_t fileoffset = 0;
-    uint64_t address = virtualAddress;
-    // Fix the offsets after adding the program header
-    for (auto &si : _segments) {
-      // Align the segment to a page boundary
-      fileoffset = llvm::RoundUpToAlignment(fileoffset,
-                                            _targetInfo.getPageSize());
-      si->assignOffsets(fileoffset);
-      fileoffset = si->fileOffset() + si->fileSize();
-    }
-    // start assigning virtual addresses
-    for (auto si = _segments.begin(); si != _segments.end(); ++si) {
-      (*si)->setVAddr(virtualAddress);
-      // The first segment has the virtualAddress set to the base address as
-      // we have added the file header and the program header dont align the
-      // first segment to the pagesize
-      (*si)->assignVirtualAddress(address);
-      (*si)->setMemSize(address - virtualAddress);
-      virtualAddress = llvm::RoundUpToAlignment(address,
-                                                _targetInfo.getPageSize());
-    }
-    _programHeader->resetProgramHeaders();
-  }
-  Section<ELFT> *section;
-  // Fix the offsets of all the atoms within a section
-  for (auto &si : _sections) {
-    section = dyn_cast<Section<ELFT>>(si);
-    if (section && DefaultELFLayout<ELFT>::hasOutputSegment(section))
-      section->assignOffsets(section->fileOffset());
-  }
-  // Set the size of the merged Sections
-  for (auto msi : _mergedSections) {
-    uint64_t sectionfileoffset = 0;
-    uint64_t startFileOffset = 0;
-    uint64_t sectionsize = 0;
-    bool isFirstSection = true;
-    for (auto si : msi->sections()) {
-      if (isFirstSection) {
-        startFileOffset = si->fileOffset();
-        isFirstSection = false;
-      }
-      sectionfileoffset = si->fileOffset();
-      sectionsize = si->fileSize();
-    }
-    sectionsize = (sectionfileoffset - startFileOffset) + sectionsize;
-    msi->setFileOffset(startFileOffset);
-    msi->setSize(sectionsize);
-  }
-  // Set the virtual addr of the merged Sections
-  for (auto msi : _mergedSections) {
-    uint64_t sectionstartaddr = 0;
-    uint64_t startaddr = 0;
-    uint64_t sectionsize = 0;
-    bool isFirstSection = true;
-    for (auto si : msi->sections()) {
-      if (isFirstSection) {
-        startaddr = si->virtualAddr();
-        isFirstSection = false;
-      }
-      sectionstartaddr = si->virtualAddr();
-      sectionsize = si->memSize();
-    }
-    sectionsize = (sectionstartaddr - startaddr) + sectionsize;
-    msi->setMemSize(sectionsize);
-    msi->setAddr(startaddr);
-  }
-}
-
-template<class ELFT>
-void
-DefaultELFLayout<ELFT>::assignOffsetsForMiscSections() {
-  uint64_t fileoffset = 0;
-  uint64_t size = 0;
-  for (auto si : _segments) {
-    fileoffset = si->fileOffset();
-    size = si->fileSize();
-  }
-  fileoffset = fileoffset + size;
-  Section<ELFT> *section;
-  for (auto si : _sections) {
-    section = dyn_cast<Section<ELFT>>(si);
-    if (section && DefaultELFLayout<ELFT>::hasOutputSegment(section))
-      continue;
-    fileoffset = llvm::RoundUpToAlignment(fileoffset, si->align2());
-    si->setFileOffset(fileoffset);
-    si->setVAddr(0);
-    fileoffset += si->fileSize();
-  }
-}
-
-} // elf
-} // lld
-
-#endif // LLD_READER_WRITER_DEFAULT_ELF_LAYOUT_H_

Removed: lld/trunk/lib/ReaderWriter/ELF/DefaultELFTargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/DefaultELFTargetHandler.h?rev=173837&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/DefaultELFTargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/DefaultELFTargetHandler.h (removed)
@@ -1,68 +0,0 @@
-//===- lib/ReaderWriter/ELF/DefaultELFTargetHandler.h ---------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// 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"
-
-#include "lld/Core/LinkerOptions.h"
-#include "lld/ReaderWriter/ELFTargetInfo.h"
-
-#include "llvm/ADT/Triple.h"
-#include "llvm/Support/ELF.h"
-
-namespace lld {
-namespace elf {
-
-template <class ELFT>
-class DefaultELFTargetHandler : public ELFTargetHandler<ELFT> {
-
-public:
-  DefaultELFTargetHandler(ELFTargetInfo &targetInfo)
-      : ELFTargetHandler<ELFT>(targetInfo) {
-  }
-
-  bool doesOverrideELFHeader() { return false; }
-
-  void setELFHeaderInfo(ELFHeader<ELFT> *elfHeader) {
-    llvm_unreachable("Target should provide implementation for function ");
-  }
-
-  /// ELFTargetLayout 
-  ELFTargetLayout<ELFT> &targetLayout() {
-    llvm_unreachable("Target should provide implementation for function ");
-  }
-
-  /// ELFTargetAtomHandler
-  ELFTargetAtomHandler<ELFT> &targetAtomHandler() {
-    llvm_unreachable("Target should provide implementation for function ");
-  }
-
-  /// Create a set of Default target sections that a target might needj
-  void createDefaultSections() {}
-
-  /// \brief Add a section to the current Layout
-  void addSection(Section<ELFT> *section) {}
-
-  /// \brief add new symbol file 
-  void addFiles(InputFiles &) {}
-
-  /// \brief Finalize the symbol values
-  void finalizeSymbolValues() {}
-
-  /// \brief allocate Commons, some architectures may move small common
-  /// symbols over to small data, this would also be used 
-  void allocateCommons() {}
-};
-
-} // elf
-} // lld
-
-#endif

Copied: lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h (from r173824, lld/trunk/lib/ReaderWriter/ELF/DefaultELFLayout.h)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h?p2=lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h&p1=lld/trunk/lib/ReaderWriter/ELF/DefaultELFLayout.h&r1=173824&r2=173838&rev=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/DefaultELFLayout.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h Tue Jan 29 16:03:39 2013
@@ -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 <tuple>
 #include <unordered_map>
 
-/// \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 ELFT>
-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<AbsoluteAtomPair>::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<ELFT> *section) const;
+  virtual Layout::SegmentType getSegmentType(Section<ELFT> *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<ELFT> *e) {
-    _elfHeader = e;
+  inline void setHeader(Header<ELFT> *e) {
+    _header = e;
   }
 
-  inline void setProgramHeader(ELFProgramHeader<ELFT> *p) {
+  inline void setProgramHeader(ProgramHeader<ELFT> *p) {
     _programHeader = p;
   }
 
@@ -244,19 +242,19 @@ public:
 
   inline range<ChunkIter> segments() { return _segments; }
 
-  inline ELFHeader<ELFT> *elfHeader() {
-    return _elfHeader;
+  inline Header<ELFT> *getHeader() {
+    return _header;
   }
 
-  inline ELFProgramHeader<ELFT> *elfProgramHeader() {
+  inline ProgramHeader<ELFT> *getProgramHeader() {
     return _programHeader;
   }
 
-  ELFRelocationTable<ELFT> *getRelocationTable() {
+  RelocationTable<ELFT> *getRelocationTable() {
     // Only create the relocation table if it is needed.
     if (!_relocationTable) {
       _relocationTable = new (_allocator)
-          ELFRelocationTable<ELFT>(_targetInfo, ".rela.plt", ORDER_REL);
+          RelocationTable<ELFT>(_targetInfo, ".rela.plt", ORDER_REL);
       addSection(_relocationTable);
     }
     return _relocationTable;
@@ -269,17 +267,17 @@ private:
   std::vector<Chunk<ELFT> *> _sections;
   std::vector<Segment<ELFT> *> _segments;
   std::vector<MergedSections<ELFT> *> _mergedSections;
-  ELFHeader<ELFT> *_elfHeader;
-  ELFProgramHeader<ELFT> *_programHeader;
-  ELFRelocationTable<ELFT> *_relocationTable;
+  Header<ELFT> *_header;
+  ProgramHeader<ELFT> *_programHeader;
+  RelocationTable<ELFT> *_relocationTable;
   std::vector<AbsoluteAtomPair> _absoluteAtoms;
   llvm::BumpPtrAllocator _allocator;
   const ELFTargetInfo &_targetInfo;
 };
 
 template<class ELFT>
-ELFLayout::SectionOrder
-DefaultELFLayout<ELFT>::getSectionOrder(const StringRef name, 
+Layout::SectionOrder
+DefaultLayout<ELFT>::getSectionOrder(const StringRef name, 
                                         int32_t contentType,
                                         int32_t contentPermissions)
 {
@@ -322,7 +320,7 @@ DefaultELFLayout<ELFT>::getSectionOrder(
 /// \brief This maps the input sections to the output section names
 template<class ELFT>
 StringRef 
-DefaultELFLayout<ELFT>::getSectionName(const StringRef name, 
+DefaultLayout<ELFT>::getSectionName(const StringRef name, 
                                        const int32_t contentType) {
   if (contentType == DefinedAtom::typeZeroFill)
     return ".bss";
@@ -335,8 +333,8 @@ DefaultELFLayout<ELFT>::getSectionName(c
 
 /// \brief Gets the segment for a output section
 template<class ELFT>
-ELFLayout::SegmentType 
-DefaultELFLayout<ELFT>::getSegmentType(Section<ELFT> *section) const {
+Layout::SegmentType 
+DefaultLayout<ELFT>::getSegmentType(Section<ELFT> *section) const {
   switch(section->order()) {
   case ORDER_INTERP:
     return llvm::ELF::PT_INTERP;
@@ -379,7 +377,7 @@ DefaultELFLayout<ELFT>::getSegmentType(S
 
 template<class ELFT>
 bool
-DefaultELFLayout<ELFT>::hasOutputSegment(Section<ELFT> *section) {
+DefaultLayout<ELFT>::hasOutputSegment(Section<ELFT> *section) {
   switch(section->order()) {
   case ORDER_INTERP:
   case ORDER_HASH:
@@ -412,13 +410,13 @@ DefaultELFLayout<ELFT>::hasOutputSegment
 
 template<class ELFT>
 error_code
-DefaultELFLayout<ELFT>::addAtom(const Atom *atom) {
+DefaultLayout<ELFT>::addAtom(const Atom *atom) {
   if (const DefinedAtom *definedAtom = dyn_cast<DefinedAtom>(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<ELFT> *section;
@@ -453,7 +451,7 @@ DefaultELFLayout<ELFT>::addAtom(const At
 /// Merge sections with the same name into a MergedSections
 template<class ELFT>
 void 
-DefaultELFLayout<ELFT>::mergeSimiliarSections() {
+DefaultLayout<ELFT>::mergeSimiliarSections() {
   MergedSections<ELFT> *mergedSection;
 
   for (auto &si : _sections) {
@@ -476,7 +474,7 @@ DefaultELFLayout<ELFT>::mergeSimiliarSec
 
 template<class ELFT>
 void 
-DefaultELFLayout<ELFT>::assignSectionsToSegments() {
+DefaultLayout<ELFT>::assignSectionsToSegments() {
   // sort the sections by their order as defined by the layout
   std::stable_sort(_sections.begin(), _sections.end(),
   [](Chunk<ELFT> *A, Chunk<ELFT> *B) {
@@ -524,7 +522,7 @@ DefaultELFLayout<ELFT>::assignSectionsTo
 
 template<class ELFT>
 void
-DefaultELFLayout<ELFT>::assignFileOffsets() {
+DefaultLayout<ELFT>::assignFileOffsets() {
   std::sort(_segments.begin(), _segments.end(),
             Segment<ELFT>::compareSegments);
   int ordinal = 0;
@@ -541,7 +539,7 @@ DefaultELFLayout<ELFT>::assignFileOffset
 
 template<class ELFT>
 void
-DefaultELFLayout<ELFT>::assignVirtualAddress() {
+DefaultLayout<ELFT>::assignVirtualAddress() {
   if (_segments.empty())
     return;
   
@@ -553,7 +551,7 @@ DefaultELFLayout<ELFT>::assignVirtualAdd
   // 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<ELFT>::assignVirtualAdd
   // Fix the offsets of all the atoms within a section
   for (auto &si : _sections) {
     section = dyn_cast<Section<ELFT>>(si);
-    if (section && DefaultELFLayout<ELFT>::hasOutputSegment(section))
+    if (section && DefaultLayout<ELFT>::hasOutputSegment(section))
       section->assignOffsets(section->fileOffset());
   }
   // Set the size of the merged Sections
@@ -632,7 +630,7 @@ DefaultELFLayout<ELFT>::assignVirtualAdd
 
 template<class ELFT>
 void
-DefaultELFLayout<ELFT>::assignOffsetsForMiscSections() {
+DefaultLayout<ELFT>::assignOffsetsForMiscSections() {
   uint64_t fileoffset = 0;
   uint64_t size = 0;
   for (auto si : _segments) {
@@ -643,7 +641,7 @@ DefaultELFLayout<ELFT>::assignOffsetsFor
   Section<ELFT> *section;
   for (auto si : _sections) {
     section = dyn_cast<Section<ELFT>>(si);
-    if (section && DefaultELFLayout<ELFT>::hasOutputSegment(section))
+    if (section && DefaultLayout<ELFT>::hasOutputSegment(section))
       continue;
     fileoffset = llvm::RoundUpToAlignment(fileoffset, si->align2());
     si->setFileOffset(fileoffset);
@@ -651,8 +649,7 @@ DefaultELFLayout<ELFT>::assignOffsetsFor
     fileoffset += si->fileSize();
   }
 }
+} // end namespace elf
+} // end namespace lld
 
-} // elf
-} // lld
-
-#endif // LLD_READER_WRITER_DEFAULT_ELF_LAYOUT_H_
+#endif

Copied: lld/trunk/lib/ReaderWriter/ELF/DefaultTargetHandler.h (from r173824, lld/trunk/lib/ReaderWriter/ELF/DefaultELFTargetHandler.h)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/DefaultTargetHandler.h?p2=lld/trunk/lib/ReaderWriter/ELF/DefaultTargetHandler.h&p1=lld/trunk/lib/ReaderWriter/ELF/DefaultELFTargetHandler.h&r1=173824&r2=173838&rev=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/DefaultELFTargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/DefaultTargetHandler.h Tue Jan 29 16:03:39 2013
@@ -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 ELFT>
-class DefaultELFTargetHandler : public ELFTargetHandler<ELFT> {
+class DefaultTargetHandler : public TargetHandler<ELFT> {
 
 public:
-  DefaultELFTargetHandler(ELFTargetInfo &targetInfo)
-      : ELFTargetHandler<ELFT>(targetInfo) {
+  DefaultTargetHandler(ELFTargetInfo &targetInfo)
+      : TargetHandler<ELFT>(targetInfo) {
   }
 
-  bool doesOverrideELFHeader() { return false; }
+  bool doesOverrideHeader() { return false; }
 
-  void setELFHeaderInfo(ELFHeader<ELFT> *elfHeader) {
+  void setHeaderInfo(Header<ELFT> *Header) {
     llvm_unreachable("Target should provide implementation for function ");
   }
 
-  /// ELFTargetLayout 
-  ELFTargetLayout<ELFT> &targetLayout() {
+  /// TargetLayout 
+  TargetLayout<ELFT> &targetLayout() {
     llvm_unreachable("Target should provide implementation for function ");
   }
 
-  /// ELFTargetAtomHandler
-  ELFTargetAtomHandler<ELFT> &targetAtomHandler() {
+  /// TargetAtomHandler
+  TargetAtomHandler<ELFT> &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

Removed: lld/trunk/lib/ReaderWriter/ELF/ELFChunk.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFChunk.h?rev=173837&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFChunk.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFChunk.h (removed)
@@ -1,94 +0,0 @@
-//===- lib/ReaderWriter/ELF/ELFChunks.h ---------------------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_READER_WRITER_ELF_CHUNKS_H_
-#define LLD_READER_WRITER_ELF_CHUNKS_H_
-
-#include "llvm/ADT/OwningPtr.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Object/ELF.h"
-#include "llvm/Support/Allocator.h"
-#include "llvm/Support/Debug.h"
-#include "llvm/Support/ELF.h"
-#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/FileOutputBuffer.h"
-
-namespace lld {
-class ELFTargetInfo;
-
-namespace elf {
-class ELFWriter;
-
-/// \brief A chunk is a contiguous region of space
-template<class ELFT>
-class Chunk {
-public:
-
-  /// \brief Describes the type of Chunk
-  enum Kind {
-    K_ELFHeader, // ELF Header
-    K_ELFProgramHeader, // Program Header
-    K_ELFSegment, // Segment
-    K_ELFSection, // Section
-    K_ELFSectionHeader // Section header
-  };
-  Chunk(llvm::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) {
-  }
-  virtual             ~Chunk() {}
-  // Does the chunk occupy disk space
-  virtual bool        occupiesNoDiskSpace() const {
-    return false;
-  }
-  // The name of the chunk
-  llvm::StringRef name() const { return _name; }
-  // Kind of chunk
-  Kind kind() const { return _kind; }
-  uint64_t            fileSize() const { return _fsize; }
-  uint64_t            align2() const { return _align2; }
-  void                appendAtom() const;
-
-  // The ordinal value of the chunk
-  uint64_t            ordinal() const { return _ordinal;}
-  void               setOrdinal(uint64_t newVal) { _ordinal = newVal;}
-  // The order in which the chunk would appear in the output file
-  uint64_t            order() const { return _order; }
-  void               setOrder(uint32_t order) { _order = order; }
-  // Output file offset of the chunk
-  uint64_t            fileOffset() const { return _fileoffset; }
-  void               setFileOffset(uint64_t offset) { _fileoffset = offset; }
-  // Output start address of the chunk
-  void               setVAddr(uint64_t start) { _start = start; }
-  uint64_t            virtualAddr() const { return _start; }
-  // Does the chunk occupy memory during execution ?
-  uint64_t            memSize() const { return _msize; }
-  void               setMemSize(uint64_t msize) { _msize = msize; }
-  // Writer the chunk
-  virtual void write(ELFWriter *writer, llvm::FileOutputBuffer &buffer) = 0;
-  // Finalize the chunk before writing
-  virtual void       finalize() = 0;
-
-protected:
-  llvm::StringRef _name;
-  Kind _kind;
-  uint64_t _fsize;
-  uint64_t _msize;
-  uint64_t _align2;
-  uint32_t  _order;
-  uint64_t _ordinal;
-  uint64_t _start;
-  uint64_t _fileoffset;
-  const ELFTargetInfo &_targetInfo;
-};
-
-} // elf
-} // lld
-
-#endif // LLD_READER_WRITER_ELF_CHUNKS_H_

Removed: lld/trunk/lib/ReaderWriter/ELF/ELFHeaderChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFHeaderChunks.h?rev=173837&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFHeaderChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFHeaderChunks.h (removed)
@@ -1,311 +0,0 @@
-//===- lib/ReaderWriter/ELF/ELFHeaderChunks.h -----------------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_READER_WRITER_ELF_HEADER_CHUNKS_H_
-#define LLD_READER_WRITER_ELF_HEADER_CHUNKS_H_
-
-#include "ELFSegmentChunks.h"
-
-#include "llvm/Object/ELF.h"
-#include "llvm/Support/Allocator.h"
-#include "llvm/Support/Debug.h"
-#include "llvm/Support/ELF.h"
-#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/FileOutputBuffer.h"
-
-/// \brief An ELFHeader represents the Elf[32/64]_Ehdr structure at the
-///        start of an ELF executable file.
-namespace lld {
-namespace elf {
-
-template<class ELFT>
-class ELFHeader : public Chunk<ELFT> {
-public:
-  typedef llvm::object::Elf_Ehdr_Impl<ELFT> Elf_Ehdr;
-
-  ELFHeader(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; }
-  void e_machine(uint16_t machine)     { _eh.e_machine = machine; }
-  void e_version(uint32_t version)     { _eh.e_version = version; }
-  void e_entry(int64_t entry)         { _eh.e_entry = entry; }
-  void e_phoff(int64_t phoff)         { _eh.e_phoff = phoff; }
-  void e_shoff(int64_t shoff)         { _eh.e_shoff = shoff; }
-  void e_flags(uint32_t flags)         { _eh.e_flags = flags; }
-  void e_ehsize(uint16_t ehsize)       { _eh.e_ehsize = ehsize; }
-  void e_phentsize(uint16_t phentsize) { _eh.e_phentsize = phentsize; }
-  void e_phnum(uint16_t phnum)         { _eh.e_phnum = phnum; }
-  void e_shentsize(uint16_t shentsize) { _eh.e_shentsize = shentsize; }
-  void e_shnum(uint16_t shnum)         { _eh.e_shnum = shnum; }
-  void e_shstrndx(uint16_t shstrndx)   { _eh.e_shstrndx = shstrndx; }
-  uint64_t  fileSize()                 { return sizeof (Elf_Ehdr); }
-
-  static inline bool classof(const Chunk<ELFT> *c) {
-    return c->Kind() == Chunk<ELFT>::K_ELFHeader;
-  }
-
-  void write(ELFWriter *writer, llvm::FileOutputBuffer &buffer);
-
-  void finalize() { }
-
-private:
-  Elf_Ehdr _eh;
-};
-
-template <class ELFT>
-ELFHeader<ELFT>::ELFHeader(const ELFTargetInfo &ti)
-    : Chunk<ELFT>("elfhdr", Chunk<ELFT>::K_ELFHeader, ti) {
-  this->_align2 = ELFT::Is64Bits ? 8 : 4;
-  this->_fsize = sizeof(Elf_Ehdr);
-  this->_msize = sizeof(Elf_Ehdr);
-  memset(_eh.e_ident, 0, llvm::ELF::EI_NIDENT);
-  e_ident(llvm::ELF::EI_MAG0, 0x7f);
-  e_ident(llvm::ELF::EI_MAG1, 'E');
-  e_ident(llvm::ELF::EI_MAG2, 'L');
-  e_ident(llvm::ELF::EI_MAG3, 'F');
-  e_ehsize(sizeof(Elf_Ehdr));
-  e_flags(2);
-}
-
-template <class ELFT>
-void ELFHeader<ELFT>::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
-///        start of an ELF executable file.
-template<class ELFT>
-class ELFProgramHeader : public Chunk<ELFT> {
-public:
-  typedef llvm::object::Elf_Phdr_Impl<ELFT> Elf_Phdr;
-  typedef typename std::vector<Elf_Phdr *>::iterator PhIterT;
-
-  /// \brief Find a program header entry, given the type of entry that
-  /// we are looking for
-  class FindPhdr {
-  public:
-    FindPhdr(uint64_t type, uint64_t flags, uint64_t flagsClear) 
-             : _type(type)
-             , _flags(flags)
-             , _flagsClear(flagsClear)
-    {}
-
-    bool operator()(const Elf_Phdr *j) const { 
-      return ((j->p_type == _type) &&
-              ((j->p_flags & _flags) == _flags) &&
-              (!(j->p_flags & _flagsClear)));
-    }
-  private:
-    uint64_t _type;
-    uint64_t _flags;
-    uint64_t _flagsClear;
-  };
-
-  ELFProgramHeader(const ELFTargetInfo &ti)
-      : Chunk<ELFT>("elfphdr", Chunk<ELFT>::K_ELFProgramHeader, ti) {
-    this->_align2 = ELFT::Is64Bits ? 8 : 4;
-    resetProgramHeaders();
-  }
-
-  bool addSegment(Segment<ELFT> *segment);
-
-  void resetProgramHeaders() {
-    _phi = _ph.begin();
-  }
-
-  uint64_t  fileSize() {
-    return sizeof(Elf_Phdr) * _ph.size();
-  }
-
-  static inline bool classof(const Chunk<ELFT> *c) {
-    return c->Kind() == Chunk<ELFT>::K_ELFProgramHeader;
-  }
-
-  void write(ELFWriter *writer, llvm::FileOutputBuffer &buffer);
-
-  /// \brief find a program header entry in the list of program headers
-  PhIterT findProgramHeader(uint64_t type, uint64_t flags, uint64_t flagClear) {
-    return std::find_if(_ph.begin(), _ph.end(), 
-                        FindPhdr(type, flags, flagClear));
-  }
-
-  PhIterT begin() {
-    return _ph.begin();
-  }
-
-  PhIterT end() {
-    return _ph.end();
-  }
-
-  void finalize() { }
-
-  int64_t entsize() {
-    return sizeof(Elf_Phdr);
-  }
-
-  int64_t numHeaders() {
-    return _ph.size();
-  }
-
-private:
-  std::vector<Elf_Phdr *> _ph;
-  PhIterT _phi;
-  llvm::BumpPtrAllocator  _allocator;
-};
-
-template<class ELFT>
-bool
-ELFProgramHeader<ELFT>::addSegment(Segment<ELFT> *segment) {
-  Elf_Phdr *phdr = nullptr;
-  bool ret = false;
-
-  for (auto slice : segment->slices()) {
-    if (_phi == _ph.end()) {
-      phdr = new(_allocator.Allocate<Elf_Phdr>()) Elf_Phdr;
-      _ph.push_back(phdr);
-      _phi = _ph.end();
-      ret = true;
-    } else {
-      phdr = (*_phi);
-      ++_phi;
-    }
-    phdr->p_type = segment->segmentType();
-    phdr->p_offset = slice->fileOffset();
-    phdr->p_vaddr = slice->virtualAddr();
-    phdr->p_paddr = slice->virtualAddr();
-    phdr->p_filesz = slice->fileSize();
-    phdr->p_memsz = slice->memSize();
-    phdr->p_flags = segment->flags();
-    phdr->p_align = (phdr->p_type == llvm::ELF::PT_LOAD) ?
-                     segment->pageSize() : slice->align2();
-  }
-  this->_fsize = fileSize();
-  this->_msize = this->_fsize;
-
-  return ret;
-}
-
-template <class ELFT>
-void ELFProgramHeader<ELFT>::write(ELFWriter *writer,
-                                   llvm::FileOutputBuffer &buffer) {
-  uint8_t *chunkBuffer = buffer.getBufferStart();
-  uint8_t *dest = chunkBuffer + this->fileOffset();
-  for (auto phi : _ph) {
-    memcpy(dest, phi, sizeof(Elf_Phdr));
-    dest += sizeof(Elf_Phdr);
-  }
-}
-
-/// \brief An ELFSectionHeader represents the Elf[32/64]_Shdr structure
-/// at the end of the file
-template<class ELFT>
-class ELFSectionHeader : public Chunk<ELFT> {
-public:
-  typedef llvm::object::Elf_Shdr_Impl<ELFT> Elf_Shdr;
-
-  ELFSectionHeader(const ELFTargetInfo &, int32_t order);
-
-  void appendSection(MergedSections<ELFT> *section);
-  
-  void updateSection(Section<ELFT> *section);
-  
-  static inline bool classof(const Chunk<ELFT> *c) {
-    return c->getChunkKind() == Chunk<ELFT>::K_ELFSectionHeader;
-  }
-  
-  void setStringSection(ELFStringTable<ELFT> *s) {
-    _stringSection = s;
-  }
-
-  void write(ELFWriter *writer, llvm::FileOutputBuffer &buffer);
-  
-  void finalize() { }
-  
-  inline uint16_t fileSize() {
-    return sizeof(Elf_Shdr) * _sectionInfo.size();
-  }
-
-  inline int64_t entsize() {
-    return sizeof(Elf_Shdr);
-  }
-  
-  inline int64_t numHeaders() {
-    return _sectionInfo.size();
-  }
-
-private:
-  ELFStringTable<ELFT> *_stringSection;
-  std::vector<Elf_Shdr*>                  _sectionInfo;
-  llvm::BumpPtrAllocator                  _sectionAllocate;
-};
-
-template <class ELFT>
-ELFSectionHeader<ELFT>::ELFSectionHeader(const ELFTargetInfo &ti, int32_t order)
-    : Chunk<ELFT>("shdr", Chunk<ELFT>::K_ELFSectionHeader, ti) {
-  this->_fsize = 0;
-  this->_align2 = 8;
-  this->setOrder(order);
-  // The first element in the list is always NULL
-  Elf_Shdr *nullshdr = new (_sectionAllocate.Allocate<Elf_Shdr>()) Elf_Shdr;
-  ::memset(nullshdr, 0, sizeof (Elf_Shdr));
-  _sectionInfo.push_back(nullshdr);
-  this->_fsize += sizeof (Elf_Shdr);
-}
-
-template<class ELFT>
-void 
-ELFSectionHeader<ELFT>::appendSection(MergedSections<ELFT> *section) {
-  Elf_Shdr *shdr = new (_sectionAllocate.Allocate<Elf_Shdr>()) Elf_Shdr;
-  shdr->sh_name   = _stringSection->addString(section->name());
-  shdr->sh_type   = section->type();
-  shdr->sh_flags  = section->flags();
-  shdr->sh_offset = section->fileOffset();
-  shdr->sh_addr   = section->virtualAddr();
-  shdr->sh_size   = section->memSize();
-  shdr->sh_link   = section->link();
-  shdr->sh_info   = section->shinfo();
-  shdr->sh_addralign = section->align2();
-  shdr->sh_entsize = section->entsize();
-  _sectionInfo.push_back(shdr);
-}
-
-template<class ELFT>
-void 
-ELFSectionHeader<ELFT>::updateSection(Section<ELFT> *section) {
-  Elf_Shdr *shdr = _sectionInfo[section->ordinal()];
-  shdr->sh_type   = section->type();
-  shdr->sh_flags  = section->flags();
-  shdr->sh_offset = section->fileOffset();
-  shdr->sh_addr   = section->virtualAddr();
-  shdr->sh_size   = section->fileSize();
-  shdr->sh_link   = section->link();
-  shdr->sh_info   = section->shinfo();
-  shdr->sh_addralign = section->align2();
-  shdr->sh_entsize = section->entsize();
-}
-
-template <class ELFT>
-void ELFSectionHeader<ELFT>::write(ELFWriter *writer,
-                                   llvm::FileOutputBuffer &buffer) {
-  uint8_t *chunkBuffer = buffer.getBufferStart();
-  uint8_t *dest = chunkBuffer + this->fileOffset();
-  for (auto shi : _sectionInfo) {
-    memcpy(dest, shi, sizeof(Elf_Shdr));
-    dest += sizeof(Elf_Shdr);
-  }
-  _stringSection->write(writer, buffer);
-}
-
-} // elf
-} // lld
-
-#endif // LLD_READER_WRITER_ELF_HEADER_CHUNKS_H_

Removed: lld/trunk/lib/ReaderWriter/ELF/ELFLayout.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFLayout.h?rev=173837&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFLayout.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFLayout.h (removed)
@@ -1,72 +0,0 @@
-//===- lib/ReaderWriter/ELF/ELFLayout.h ---------------------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_READER_WRITER_ELF_LAYOUT_H_
-#define LLD_READER_WRITER_ELF_LAYOUT_H_
-
-#include "lld/Core/DefinedAtom.h"
-
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Object/ELF.h"
-#include "llvm/Support/Allocator.h"
-#include "llvm/Support/Debug.h"
-#include "llvm/Support/ELF.h"
-
-namespace lld {
-namespace elf {
-/// \brief The ELFLayout 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
-//         needed by the lld linker
-class ELFLayout {
-public:
-  typedef uint32_t SectionOrder;
-  typedef uint32_t SegmentType;
-  typedef uint32_t Flags;
-
-public:
-  /// Return the order the section would appear in the output file
-  virtual SectionOrder getSectionOrder
-                        (const llvm::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, 
-                                  uint64_t &addr) = 0;
-  /// associates a section to a segment
-  virtual void assignSectionsToSegments() = 0;
-  /// associates a virtual address to the segment, section, and the atom
-  virtual void assignVirtualAddress() = 0;
-  /// associates a file offset to the segment, section and the atom
-  virtual void assignFileOffsets() = 0;
-
-public:
-  ELFLayout() {}
-
-  virtual ~ELFLayout() { }
-};
-
-struct AtomLayout {
-  AtomLayout(const Atom *a, uint64_t fileOff, uint64_t virAddr)
-    : _atom(a), _fileOffset(fileOff), _virtualAddr(virAddr) {}
-
-  AtomLayout()
-    : _atom(nullptr), _fileOffset(0), _virtualAddr(0) {}
-
-  const Atom *_atom;
-  uint64_t _fileOffset;
-  uint64_t _virtualAddr;
-};
-} // lld
-} // elf
-
-#endif // LLD_READER_WRITER_ELF_LAYOUT_H_

Removed: lld/trunk/lib/ReaderWriter/ELF/ELFSectionChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFSectionChunks.h?rev=173837&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFSectionChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFSectionChunks.h (removed)
@@ -1,745 +0,0 @@
-//===- lib/ReaderWriter/ELF/ELFSectionChunks.h -----------------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#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 "lld/Core/DefinedAtom.h"
-#include "lld/Core/range.h"
-
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/OwningPtr.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Object/ELF.h"
-#include "llvm/Support/Allocator.h"
-#include "llvm/Support/Debug.h"
-#include "llvm/Support/ELF.h"
-#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/FileOutputBuffer.h"
-
-namespace lld {
-namespace elf {
-
-/// \brief A section contains a set of atoms that have similiar properties
-///        The atoms that have similiar properties are merged to form a section
-template<class ELFT>
-class Section : public Chunk<ELFT> {
-public:
-  // The Kind of section that the object represents
-  enum SectionKind {
-    K_Default,
-    K_Target, // The section is handed over to the target
-    K_SymbolTable,
-    K_StringTable,
-  };
-  // 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,
-          const int32_t contentType, const int32_t contentPermissions,
-          const int32_t order, const SectionKind kind = K_Default);
-
-  /// return the section kind
-  inline SectionKind sectionKind() const {
-    return _sectionKind;
-  }
-
-  /// Align the offset to the required modulus defined by the atom alignment
-  uint64_t alignOffset(uint64_t offset, DefinedAtom::Alignment &atomAlign);
-
-  // \brief Append an atom to a Section. The atom gets pushed into a vector
-  // contains the atom, the atom file offset, the atom virtual address
-  // the atom file offset is aligned appropriately as set by the Reader
-  void appendAtom(const Atom *atom);
-
-  /// \brief Set the virtual address of each Atom in the Section. This
-  /// routine gets called after the linker fixes up the virtual address
-  /// of the section
-  inline void assignVirtualAddress(uint64_t &addr) {
-    for (auto &ai : _atoms) {
-      ai._virtualAddr = addr + ai._fileOffset;
-    }
-    addr += this->memSize();
-  }
-
-  /// \brief Set the file offset of each Atom in the section. This routine
-  /// gets called after the linker fixes up the section offset
-  inline void assignOffsets(uint64_t offset) {
-    for (auto &ai : _atoms) {
-      ai._fileOffset = offset + ai._fileOffset;
-    }
-  }
-
-  /// \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) {
-    for (auto ai : _atoms) {
-      if (ai._atom->name() == name) {
-        addr = ai._virtualAddr;
-        return true;
-      }
-    }
-    return false;
-  }
-
-  /// \brief Does the Atom occupy any disk space
-  inline bool occupiesNoDiskSpace() const {
-    return _contentType == DefinedAtom::typeZeroFill;
-  }
-
-  /// \brief The permission of the section is the most permissive permission
-  /// of all atoms that the section contains
-  inline void setContentPermissions(int32_t perm) {
-    _contentPermissions = std::max(perm, _contentPermissions);
-  }
-
-  /// \brief Get the section flags, defined by the permissions of the section
-  int64_t flags();
-
-  /// \brief Return the section type, the returned value is recorded in the
-  /// sh_type field of the Section Header
-  int type();
-
-  /// \brief convert the segment type to a String for diagnostics
-  ///        and printing purposes
-  llvm::StringRef segmentKindToStr() const;
-
-  /// \brief Return the raw flags, we need this to sort segments
-  inline int64_t atomflags() const {
-    return _contentPermissions;
-  }
-
-  /// \brief Returns the section link field, the returned value is
-  ///        recorded in the sh_link field of the Section Header
-  inline int link() const {
-    return _link;
-  }
-
-  inline void setLink(int32_t link) {
-    _link = link;
-  }
-
-  /// \brief Returns the section entsize field, the returned value is
-  ///        recorded in the sh_entsize field of the Section Header
-  inline int entsize() const {
-    return _entSize;
-  }
-
-  /// \brief Returns the shinfo field, the returned value is
-  ///        recorded in the sh_info field of the Section Header
-  inline int shinfo() const {
-    return _shInfo;
-  }
-
-  /// \brief Records the segmentType, that this section belongs to
-  inline void setSegment(const ELFLayout::SegmentType segmentType) {
-    _segmentType = segmentType;
-  }
-
-  /// \brief for LLVM style RTTI information
-  static inline bool classof(const Chunk<ELFT> *c) {
-    return c->kind() == Chunk<ELFT>::K_ELFSection;
-  }
-
-  /// \brief Finalize the section contents before writing
-  inline void finalize() { }
-
-  /// \brief Write the section and the atom contents to the buffer
-  void write(ELFWriter *writer, llvm::FileOutputBuffer &buffer);
-
-  /// Atom Iterators
-  typedef typename std::vector<AtomLayout>::iterator atom_iter;
-
-  range<atom_iter> atoms() { return _atoms; }
-
-protected:
-  int32_t _contentType;
-  int32_t _contentPermissions;
-  SectionKind _sectionKind;
-  std::vector<AtomLayout> _atoms;
-  ELFLayout::SegmentType _segmentType;
-  int64_t _entSize;
-  int64_t _shInfo;
-  int64_t _link;
-};
-
-// Create a section object, the section is set to the default type if the
-// caller doesnot set it
-template <class ELFT>
-Section<ELFT>::Section(const ELFTargetInfo &ti, const StringRef sectionName,
-                       const int32_t contentType,
-                       const int32_t contentPermissions, const int32_t order,
-                       const SectionKind kind)
-    : Chunk<ELFT>(sectionName, Chunk<ELFT>::K_ELFSection, ti),
-      _contentType(contentType), _contentPermissions(contentPermissions),
-      _sectionKind(kind), _entSize(0), _shInfo(0), _link(0) {
-  this->setOrder(order);
-}
-
-/// Align the offset to the required modulus defined by the atom alignment
-template<class ELFT>
-uint64_t 
-Section<ELFT>::alignOffset(uint64_t offset, DefinedAtom::Alignment &atomAlign) {
-  uint64_t requiredModulus = atomAlign.modulus;
-  uint64_t align2 = 1u << atomAlign.powerOf2;
-  uint64_t currentModulus = (offset % align2);
-  uint64_t retOffset = offset;
-  if (currentModulus != requiredModulus) {
-    if (requiredModulus > currentModulus)
-      retOffset += requiredModulus - currentModulus;
-    else
-      retOffset += align2 + requiredModulus - currentModulus;
-  }
-  return retOffset;
-}
-
-// \brief Append an atom to a Section. The atom gets pushed into a vector
-// contains the atom, the atom file offset, the atom virtual address
-// the atom file offset is aligned appropriately as set by the Reader
-template<class ELFT>
-void 
-Section<ELFT>::appendAtom(const Atom *atom) {
-  Atom::Definition atomType = atom->definition();
-  const DefinedAtom *definedAtom = cast<DefinedAtom>(atom);
-
-  DefinedAtom::Alignment atomAlign = definedAtom->alignment();
-  uint64_t align2 = 1u << atomAlign.powerOf2;
-  // Align the atom to the required modulus/ align the file offset and the
-  // memory offset seperately this is required so that BSS symbols are handled
-  // properly as the BSS symbols only occupy memory size and not file size
-  uint64_t fOffset = alignOffset(this->fileSize(), atomAlign);
-  uint64_t mOffset = alignOffset(this->memSize(), atomAlign);
-  switch (atomType) {
-  case Atom::definitionRegular:
-    switch(definedAtom->contentType()) {
-    case  DefinedAtom::typeCode:
-    case  DefinedAtom::typeData:
-    case  DefinedAtom::typeConstant:
-    case DefinedAtom::typeGOT:
-    case DefinedAtom::typeStub:
-    case DefinedAtom::typeResolver:
-      _atoms.push_back(AtomLayout(atom, fOffset, 0));
-      this->_fsize = fOffset + definedAtom->size();
-      this->_msize = mOffset + definedAtom->size();
-      DEBUG_WITH_TYPE("Section",
-                      llvm::dbgs() << "[" << this->name() << " " << this << "] "
-                                   << "Adding atom: " << atom->name() << "@"
-                                   << fOffset << "\n");
-      break;
-    case  DefinedAtom::typeZeroFill:
-      _atoms.push_back(AtomLayout(atom, mOffset, 0));
-      this->_msize = mOffset + definedAtom->size();
-      break;
-    default:
-      this->_fsize = fOffset + definedAtom->size();
-      this->_msize = mOffset + definedAtom->size();
-      break;
-    }
-    break;
-  default:
-    llvm_unreachable("Expecting only definedAtoms being passed here");
-    break;
-  }
-  // Set the section alignment to the largest alignment
-  // std::max doesnot support uint64_t
-  if (this->_align2 < align2)
-    this->_align2 = align2;
-}
-
-/// \brief Get the section flags, defined by the permissions of the section
-template<class ELFT>
-int64_t 
-Section<ELFT>::flags() {
-  switch (_contentPermissions) {
-  case DefinedAtom::perm___:
-    return 0;
-
-  case DefinedAtom::permR__:
-      return llvm::ELF::SHF_ALLOC;
-
-  case DefinedAtom::permR_X:
-      return llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR;
-
-  case DefinedAtom::permRW_:
-  case DefinedAtom::permRW_L:
-      return llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE;
-
-  case DefinedAtom::permRWX:
-      return llvm::ELF::SHF_ALLOC |
-              llvm::ELF::SHF_WRITE |
-              llvm::ELF::SHF_EXECINSTR;
-
-  default:
-      break;
-  }
-  return llvm::ELF::SHF_ALLOC;
-}
-
-/// \brief Return the section type, the returned value is recorded in the
-/// sh_type field of the Section Header
-
-template<class ELFT>
-int 
-Section<ELFT>::type() {
-  if (_sectionKind == K_SymbolTable)
-    return llvm::ELF::SHT_SYMTAB;
-
-  switch (_contentType) {
-  case DefinedAtom::typeCode:
-  case DefinedAtom::typeData:
-  case DefinedAtom::typeConstant:
-  case DefinedAtom::typeGOT:
-  case DefinedAtom::typeStub:
-  case DefinedAtom::typeResolver:
-    return llvm::ELF::SHT_PROGBITS;
-
-  case DefinedAtom::typeZeroFill:
-   return llvm::ELF::SHT_NOBITS;
-
-  // Case to handle section types
-  // Symtab, String Table ...
-  default:
-   return _contentType;
-  }
-}
-
-/// \brief convert the segment type to a String for diagnostics
-///        and printing purposes
-template<class ELFT>
-StringRef 
-Section<ELFT>::segmentKindToStr() const {
-  switch(_segmentType) {
-  case llvm::ELF::PT_INTERP:
-    return "INTERP";
-  case llvm::ELF::PT_LOAD:
-    return "LOAD";
-  case llvm::ELF::PT_GNU_EH_FRAME:
-    return "EH_FRAME";
-  case llvm::ELF::PT_NOTE:
-    return "NOTE";
-  case llvm::ELF::PT_DYNAMIC:
-    return "DYNAMIC";
-  case llvm::ELF::PT_GNU_RELRO:
-    return "RELRO";
-  case llvm::ELF::PT_NULL:
-    return "NULL";
-  default:
-    return "UNKNOWN";
-  }
-}
-
-/// \brief Write the section and the atom contents to the buffer
-template <class ELFT>
-void Section<ELFT>::write(ELFWriter *writer, llvm::FileOutputBuffer &buffer) {
-  uint8_t *chunkBuffer = buffer.getBufferStart();
-  for (auto &ai : _atoms) {
-    DEBUG_WITH_TYPE("Section",
-                    llvm::dbgs() << "Writing atom: " << ai._atom->name()
-                                 << " | " << ai._fileOffset << "\n");
-    const DefinedAtom *definedAtom = cast<DefinedAtom>(ai._atom);
-    if (definedAtom->contentType() == DefinedAtom::typeZeroFill)
-      continue;
-    // Copy raw content of atom to file buffer.
-    llvm::ArrayRef<uint8_t> content = definedAtom->rawContent();
-    uint64_t contentSize = content.size();
-    if (contentSize == 0)
-      continue;
-    uint8_t *atomContent = chunkBuffer + ai._fileOffset;
-    std::copy_n(content.data(), contentSize, atomContent);
-    for (const auto ref : *definedAtom) {
-      uint32_t offset = ref->offsetInAtom();
-      uint64_t targetAddress = 0;
-      assert(ref->target() != nullptr && "Found the target to be NULL");
-      targetAddress = writer->addressOfAtom(ref->target());
-      uint64_t fixupAddress = writer->addressOfAtom(ai._atom) + offset;
-      // apply the relocation
-      writer->kindHandler()->applyFixup(ref->kind(),
-                                        ref->addend(),
-                                        &atomContent[offset],
-                                        fixupAddress,
-                                        targetAddress);
-    }
-  }
-}
-
-/// \brief A MergedSections represents a set of sections grouped by the same
-/// name. The output file that gets written by the linker has sections grouped
-/// by similiar names
-template<class ELFT>
-class MergedSections {
-public:
-  // Iterators
-  typedef typename std::vector<Chunk<ELFT> *>::iterator ChunkIter;
-
-  MergedSections(llvm::StringRef name);
-
-  // Appends a section into the list of sections that are part of this Merged
-  // Section
-  void appendSection(Chunk<ELFT> *c);
-
-  // Set the MergedSections is associated with a segment
-  inline void setHasSegment() { _hasSegment = true; }
-
-  /// Sets the ordinal
-  inline void setOrdinal(uint64_t ordinal) {
-    _ordinal = ordinal;
-  }
-
-  /// Sets the Memory size
-  inline void setMemSize(uint64_t memsz) {
-    _memSize = memsz;
-  }
-
-  /// Sets the size fo the merged Section
-  inline void setSize(uint64_t fsiz) {
-    _size = fsiz;
-  }
-
-  // The offset of the first section contained in the merged section is
-  // contained here
-  inline void setFileOffset(uint64_t foffset) {
-    _fileOffset = foffset;
-  }
-
-  // Sets the starting address of the section
-  inline void setAddr(uint64_t addr) {
-    _virtualAddr = addr;
-  }
-
-  inline range<ChunkIter> sections() { return _sections; }
-
-  // The below functions returns the properties of the MergeSection
-  inline bool hasSegment() const { return _hasSegment; }
-
-  inline llvm::StringRef name() const { return _name; }
-
-  inline int64_t shinfo() const { return _shInfo; }
-
-  inline uint64_t align2() const { return _align2; }
-
-  inline int64_t link() const { return _link; }
-
-  inline int64_t type() const { return _type; }
-
-  inline uint64_t virtualAddr() const { return _virtualAddr; }
-
-  inline int64_t ordinal() const { return _ordinal; }
-
-  inline int64_t kind() const { return _kind; }
-
-  inline uint64_t fileSize() const { return _size; }
-
-  inline int64_t entsize() const { return _entSize; }
-
-  inline uint64_t fileOffset() const { return _fileOffset; }
-
-  inline int64_t flags() const { return _flags; }
-
-  inline uint64_t memSize() { return _memSize; }
-
-private:
-  llvm::StringRef _name;
-  bool _hasSegment;
-  uint64_t _ordinal;
-  int64_t _flags;
-  uint64_t _size;
-  uint64_t _memSize;
-  uint64_t _fileOffset;
-  uint64_t _virtualAddr;
-  int64_t _shInfo;
-  int64_t _entSize;
-  int64_t _link;
-  uint64_t _align2;
-  int64_t _kind;
-  int64_t _type;
-  std::vector<Chunk<ELFT> *> _sections;
-};
-
-/// MergedSections
-template<class ELFT>
-MergedSections<ELFT>::MergedSections(StringRef name)
-  : _name(name)
-  ,_hasSegment(false)
-  ,_ordinal(0)
-  ,_flags(0)
-  ,_size(0)
-  ,_memSize(0)
-  ,_fileOffset(0)
-  ,_virtualAddr(0)
-  ,_shInfo(0)
-  ,_entSize(0)
-  ,_link(0)
-  ,_align2(0)
-  ,_kind(0)
-  ,_type(0) { }
-  
-
-template<class ELFT>
-void
-MergedSections<ELFT>::appendSection(Chunk<ELFT> *c) {
-  if (c->align2() > _align2)
-    _align2 = c->align2();
-  if (const auto section = dyn_cast<Section<ELFT>>(c)) {
-    _link = section->link();
-    _shInfo = section->shinfo();
-    _entSize = section->entsize();
-    _type = section->type();
-    if (_flags < section->flags())
-      _flags = section->flags();
-  }
-  _kind = c->kind();
-  _sections.push_back(c);
-}
-
-/// \brief The class represents the ELF String Table
-template<class ELFT>
-class ELFStringTable : public Section<ELFT> {
-public:
-  ELFStringTable(const ELFTargetInfo &, const char *str, int32_t order);
-
-  static inline bool classof(const Chunk<ELFT> *c) {
-    return c->kind() == Section<ELFT>::K_StringTable;
-  }
-
-  uint64_t addString(const llvm::StringRef symname);
-
-  void write(ELFWriter *writer, llvm::FileOutputBuffer &buffer);
-
-  inline void finalize() { }
-
-private:
-  std::vector<llvm::StringRef> _strings;
-};
-
-template <class ELFT>
-ELFStringTable<ELFT>::ELFStringTable(const ELFTargetInfo &ti, const char *str,
-                                     int32_t order)
-    : Section<ELFT>(ti, str, llvm::ELF::SHT_STRTAB, DefinedAtom::perm___, order,
-                    Section<ELFT>::K_StringTable) {
-  // the string table has a NULL entry for which
-  // add an empty string
-  _strings.push_back("");
-  this->_fsize = 1;
-  this->_align2 = 1;
-  this->setOrder(order);
-}
-
-template<class ELFT>
-uint64_t
-ELFStringTable<ELFT>::addString(const StringRef symname) {
-  _strings.push_back(symname);
-  uint64_t offset = this->_fsize;
-  this->_fsize += symname.size() + 1;
-  return offset;
-}
-
-template <class ELFT>
-void ELFStringTable<ELFT>::write(ELFWriter *writer,
-                                 llvm::FileOutputBuffer &buffer) {
-  uint8_t *chunkBuffer = buffer.getBufferStart();
-  uint8_t *dest = chunkBuffer + this->fileOffset();
-  for (auto si : _strings) {
-    memcpy(dest, si.data(), si.size());
-    dest += si.size();
-    memcpy(dest, "", 1);
-    dest += 1;
-  }
-}
-
-/// \brief The ELFSymbolTable class represents the symbol table in a ELF file
-template<class ELFT>
-class ELFSymbolTable : public Section<ELFT> {
-public:
-  typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym;
-
-  ELFSymbolTable(const ELFTargetInfo &ti, const char *str, int32_t order);
-
-  void addSymbol(const Atom *atom, int32_t sectionIndex, uint64_t addr = 0);
-
-  void finalize();
-
-  void write(ELFWriter *writer, llvm::FileOutputBuffer &buffer);
-
-  static inline bool classof(const Chunk<ELFT> *c) {
-    return c->kind() == Section<ELFT>::K_SymbolTable;
-  }
-
-  inline void setStringSection(ELFStringTable<ELFT> *s) {
-    _stringSection = s;
-  }
-
-private:
-  ELFStringTable<ELFT> *_stringSection;
-  std::vector<Elf_Sym*> _symbolTable;
-  llvm::BumpPtrAllocator _symbolAllocate;
-  int64_t _link;
-};
-
-/// ELF Symbol Table 
-template <class ELFT>
-ELFSymbolTable<ELFT>::ELFSymbolTable(const ELFTargetInfo &ti, const char *str,
-                                     int32_t order)
-    : Section<ELFT>(ti, str, llvm::ELF::SHT_SYMTAB, 0, order,
-                    Section<ELFT>::K_SymbolTable) {
-  this->setOrder(order);
-  Elf_Sym *symbol = new (_symbolAllocate.Allocate<Elf_Sym>()) Elf_Sym;
-  memset((void *)symbol, 0, sizeof(Elf_Sym));
-  _symbolTable.push_back(symbol);
-  this->_entSize = sizeof(Elf_Sym);
-  this->_fsize = sizeof(Elf_Sym);
-  this->_align2 = sizeof(void *);
-}
-
-template<class ELFT>
-void 
-ELFSymbolTable<ELFT>::addSymbol(const Atom *atom, 
-                                int32_t sectionIndex, 
-                                uint64_t addr) {
-  Elf_Sym *symbol = new(_symbolAllocate.Allocate<Elf_Sym>()) Elf_Sym;
-  unsigned char binding = 0, type = 0;
-  symbol->st_name = _stringSection->addString(atom->name());
-  symbol->st_size = 0;
-  symbol->st_shndx = sectionIndex;
-  symbol->st_value = 0;
-  symbol->st_other = llvm::ELF::STV_DEFAULT;
-  if (const DefinedAtom *da = dyn_cast<const DefinedAtom>(atom)){
-    symbol->st_size = da->size();
-    lld::DefinedAtom::ContentType ct;
-    switch (ct = da->contentType()){
-    case  DefinedAtom::typeCode:
-    case DefinedAtom::typeStub:
-      symbol->st_value = addr;
-      type = llvm::ELF::STT_FUNC;
-      break;
-    case DefinedAtom::typeResolver:
-      symbol->st_value = addr;
-      type = llvm::ELF::STT_GNU_IFUNC;
-      break;
-    case  DefinedAtom::typeData:
-    case  DefinedAtom::typeConstant:
-    case DefinedAtom::typeGOT:
-      symbol->st_value = addr;
-      type = llvm::ELF::STT_OBJECT;
-      break;
-    case  DefinedAtom::typeZeroFill:
-      type = llvm::ELF::STT_OBJECT;
-      symbol->st_value = addr;
-      break;
-    default:
-      type = llvm::ELF::STT_NOTYPE;
-    }
-    if (da->scope() == DefinedAtom::scopeTranslationUnit)
-      binding = llvm::ELF::STB_LOCAL;
-    else
-      binding = llvm::ELF::STB_GLOBAL;
-  } else if (const AbsoluteAtom *aa = dyn_cast<const AbsoluteAtom>(atom)){
-    type = llvm::ELF::STT_OBJECT;
-    symbol->st_shndx = llvm::ELF::SHN_ABS;
-    switch (aa->scope()) {
-    case AbsoluteAtom::scopeLinkageUnit:
-      symbol->st_other = llvm::ELF::STV_HIDDEN;
-      binding = llvm::ELF::STB_LOCAL;
-      break;
-    case AbsoluteAtom::scopeTranslationUnit:
-      binding = llvm::ELF::STB_LOCAL;
-      break;
-    case AbsoluteAtom::scopeGlobal:
-      binding = llvm::ELF::STB_GLOBAL;
-      break;
-    }
-    symbol->st_value = addr;
-  } else {
-   symbol->st_value = 0;
-   type = llvm::ELF::STT_NOTYPE;
-   binding = llvm::ELF::STB_WEAK;
-  }
-  symbol->setBindingAndType(binding, type);
-  _symbolTable.push_back(symbol);
-  this->_fsize += sizeof(Elf_Sym);
-}
-
-template<class ELFT>
-void 
-ELFSymbolTable<ELFT>::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(),
-  [](const Elf_Sym *A, const Elf_Sym *B) {
-     return A->getBinding() < B->getBinding();
-  });
-  uint16_t shInfo = 0;
-  for (auto i : _symbolTable) {
-    if (i->getBinding() != llvm::ELF::STB_LOCAL)
-      break;
-    shInfo++;
-  }
-  this->_shInfo = shInfo;
-  this->setLink(_stringSection->ordinal());
-}
-
-template <class ELFT>
-void ELFSymbolTable<ELFT>::write(ELFWriter *writer,
-                                 llvm::FileOutputBuffer &buffer) {
-  uint8_t *chunkBuffer = buffer.getBufferStart();
-  uint8_t *dest = chunkBuffer + this->fileOffset();
-  for (auto sti : _symbolTable) {
-    memcpy(dest, sti, sizeof(Elf_Sym));
-    dest += sizeof(Elf_Sym);
-  }
-}
-
-template <class ELFT> class ELFRelocationTable : public Section<ELFT> {
-public:
-  typedef llvm::object::Elf_Rel_Impl<ELFT, true> Elf_Rela;
-
-  ELFRelocationTable(const ELFTargetInfo &ti, StringRef str, int32_t order)
-      : Section<ELFT>(ti, str, llvm::ELF::SHT_RELA, DefinedAtom::permR__, order,
-                      Section<ELFT>::K_Default) {
-    this->setOrder(order);
-    this->_entSize = sizeof(Elf_Rela);
-    this->_align2 = llvm::alignOf<Elf_Rela>();
-  }
-
-  void addRelocation(const DefinedAtom &da, const Reference &r) {
-    _relocs.emplace_back(da, r);
-    this->_fsize = _relocs.size() * sizeof(Elf_Rela);
-    this->_msize = this->_fsize;
-  }
-
-  void write(ELFWriter *writer, llvm::FileOutputBuffer &buffer) {
-    uint8_t *chunkBuffer = buffer.getBufferStart();
-    uint8_t *dest = chunkBuffer + this->fileOffset();
-    for (const auto &rel : _relocs) {
-      Elf_Rela *r = reinterpret_cast<Elf_Rela *>(dest);
-      r->setSymbolAndType(0, rel.second.kind());
-      r->r_offset =
-          writer->addressOfAtom(&rel.first) + rel.second.offsetInAtom();
-      r->r_addend =
-          writer->addressOfAtom(rel.second.target()) + rel.second.addend();
-      dest += sizeof(Elf_Rela);
-      DEBUG_WITH_TYPE("ELFRelocationTable", llvm::dbgs()
-                      << "IRELATIVE relocation at " << rel.first.name() << "@"
-                      << r->r_offset << " to " << rel.second.target()->name()
-                      << "@" << r->r_addend << "\n");
-    }
-  }
-
-private:
-  std::vector<std::pair<const DefinedAtom &, const Reference &>> _relocs;
-};
-
-} // elf
-} // lld
-
-#endif //LLD_READER_WRITER_ELF_SECTION_CHUNKS_H_

Removed: lld/trunk/lib/ReaderWriter/ELF/ELFSegmentChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFSegmentChunks.h?rev=173837&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFSegmentChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFSegmentChunks.h (removed)
@@ -1,374 +0,0 @@
-//===- lib/ReaderWriter/ELF/ELFSegmentChunks.h -----------------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#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 "lld/Core/range.h"
-#include "lld/ReaderWriter/Writer.h"
-
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/OwningPtr.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Object/ELF.h"
-#include "llvm/Support/Allocator.h"
-#include "llvm/Support/Debug.h"
-#include "llvm/Support/ELF.h"
-#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 {
-
-template<class ELFT>
-class SegmentSlice {
-public:
-  typedef typename std::vector<Chunk<ELFT> *>::iterator SectionIter;
-
-  SegmentSlice() { }
-
-  /// Set the segment slice so that it begins at the offset specified
-  /// by file offset and set the start of the slice to be s and the end
-  /// of the slice to be e
-  void set(uint64_t fileoffset, int32_t s, int e) {
-    _startSection = s;
-    _endSection = e + 1;
-    _offset = fileoffset;
-  }
-
-  // Set the segment slice start and end iterators. This is used to walk through
-  // the sections that are part of the Segment slice
-  inline void setSections(range<SectionIter> sections) {
-    _sections = sections;
-  }
-
-  // Return the fileOffset of the slice
-  inline uint64_t fileOffset() const { return _offset; }
-
-  // Return the size of the slice
-  inline uint64_t fileSize() const { return _size; }
-
-  // Return the start of the slice
-  inline int32_t startSection() const { return _startSection; }
-
-  // Return the start address of the slice
-  inline uint64_t virtualAddr() const { return _addr; }
-
-  // Return the memory size of the slice
-  inline uint64_t memSize() const { return _memSize; }
-
-  // Return the alignment of the slice
-  inline uint64_t align2() const { return _align2; }
-
-  inline void setSize(uint64_t sz) { _size = sz; }
-
-  inline void setMemSize(uint64_t memsz) { _memSize = memsz; }
-
-  inline void setVAddr(uint64_t addr) { _addr = addr; }
-
-  inline void setAlign(uint64_t align) { _align2 = align; }
-
-  static bool compare_slices(SegmentSlice<ELFT> *a, SegmentSlice<ELFT> *b) {
-    return a->startSection() < b->startSection();
-  }
-
-  inline range<SectionIter> sections() {
-    return _sections;
-  }
-
-private:
-  int32_t _startSection;
-  int32_t _endSection;
-  range<SectionIter> _sections;
-  uint64_t _addr;
-  uint64_t _offset;
-  uint64_t _size;
-  uint64_t _align2;
-  uint64_t _memSize;
-};
-
-/// \brief A segment contains a set of sections, that have similiar properties
-//  the sections are already seperated based on different flags and properties
-//  the segment is just a way to concatenate sections to segments
-template<class ELFT>
-class Segment : public Chunk<ELFT> {
-public:
-  typedef typename std::vector<SegmentSlice<ELFT> *>::iterator SliceIter;
-  typedef typename std::vector<Chunk<ELFT> *>::iterator SectionIter;
-
-  Segment(const ELFTargetInfo &ti, const StringRef name,
-          const ELFLayout::SegmentType type);
-
-  /// append a section to a segment
-  void append(Section<ELFT> *section);
-
-  /// Sort segments depending on the property
-  /// If we have a Program Header segment, it should appear first
-  /// If we have a INTERP segment, that should appear after the Program Header
-  /// All Loadable segments appear next in this order
-  /// All Read Write Execute segments follow
-  /// All Read Execute segments appear next
-  /// All Read only segments appear first
-  /// All Write execute segments follow
-  static bool compareSegments(Segment<ELFT> *sega, Segment<ELFT> *segb);
-
-  /// \brief Start assigning file offset to the segment chunks The fileoffset
-  /// needs to be page at the start of the segment and in addition the
-  /// fileoffset needs to be aligned to the max section alignment within the
-  /// segment. This is required so that the ELF property p_poffset % p_align =
-  /// p_vaddr mod p_align holds true.
-  /// The algorithm starts off by assigning the startOffset thats passed in as
-  /// parameter to the first section in the segment, if the difference between
-  /// the newly computed offset is greater than a page, then we create a segment
-  /// slice, as it would be a waste of virtual memory just to be filled with
-  /// zeroes
-  void assignOffsets(uint64_t startOffset);
-
-  /// \brief Assign virtual addresses to the slices
-  void assignVirtualAddress(uint64_t &addr);
-
-  // Write the Segment
-  void write(ELFWriter *writer, llvm::FileOutputBuffer &buffer);
-
-  int64_t flags() const;
-
-  /// Prepend a generic chunk to the segment.
-  void prepend(Chunk<ELFT> *c) {
-    _sections.insert(_sections.begin(), c);
-  }
-
-  // Finalize the segment, before we want to write to the output file
-  inline void finalize() { }
-
-  // For LLVM RTTI
-  static inline bool classof(const Chunk<ELFT> *c) {
-    return c->kind() == Chunk<ELFT>::K_ELFSegment;
-  }
-
-  // Getters
-  inline int32_t sectionCount() const {
-    return _sections.size();
-  }
-
-  inline ELFLayout::SegmentType segmentType() { return _segmentType; }
-
-  inline int pageSize() const { return this->_targetInfo.getPageSize(); }
-
-  inline int64_t atomflags() const { return _atomflags; }
-
-  inline int64_t numSlices() const {
-    return _segmentSlices.size();
-  }
-
-  inline range<SliceIter> slices() { return _segmentSlices; }
-
-  // These two accessors are still needed for a call to std::stable_sort.
-  // Consider adding wrappers for two iterator algorithms.
-  inline SliceIter slices_begin() {
-    return _segmentSlices.begin();
-  }
-
-  inline SliceIter slices_end() {
-    return _segmentSlices.end();
-  }
-
-protected:
-  /// \brief Section or some other chunk type.
-  std::vector<Chunk<ELFT> *> _sections;
-  std::vector<SegmentSlice<ELFT> *> _segmentSlices;
-  ELFLayout::SegmentType _segmentType;
-  int64_t _flags;
-  int64_t _atomflags;
-  llvm::BumpPtrAllocator _segmentAllocate;
-};
-
-template <class ELFT>
-Segment<ELFT>::Segment(const ELFTargetInfo &ti, const StringRef name,
-                       const ELFLayout::SegmentType type)
-    : Chunk<ELFT>(name, Chunk<ELFT>::K_ELFSegment, ti), _segmentType(type),
-      _flags(0), _atomflags(0) {
-  this->_align2 = 0;
-  this->_fsize = 0;
-}
-
-template<class ELFT>
-void 
-Segment<ELFT>::append(Section<ELFT> *section) {
-  _sections.push_back(section);
-  if (_flags < section->flags())
-    _flags = section->flags();
-  if (_atomflags < section->atomflags())
-    _atomflags = section->atomflags();
-  if (this->_align2 < section->align2())
-    this->_align2 = section->align2();
-}
-
-template<class ELFT>
-bool 
-Segment<ELFT>::compareSegments(Segment<ELFT> *sega, Segment<ELFT> *segb) {
-  if (sega->atomflags() < segb->atomflags())
-    return false;
-  return true;
-}
-
-template<class ELFT>
-void 
-Segment<ELFT>::assignOffsets(uint64_t startOffset) {
-  int startSection = 0;
-  int currSection = 0;
-  SectionIter startSectionIter, endSectionIter;
-  // slice align is set to the max alignment of the chunks that are
-  // contained in the slice
-  uint64_t sliceAlign = 0;
-  // Current slice size
-  uint64_t curSliceSize = 0;
-  // Current Slice File Offset
-  uint64_t curSliceFileOffset = 0;
-
-  startSectionIter = _sections.begin();
-  endSectionIter = _sections.end();
-  startSection = 0;
-  bool isFirstSection = true;
-  for (auto si = _sections.begin(); si != _sections.end(); ++si) {
-    if (isFirstSection) {
-      // align the startOffset to the section alignment
-      uint64_t newOffset =
-        llvm::RoundUpToAlignment(startOffset, (*si)->align2());
-      curSliceFileOffset = newOffset;
-      sliceAlign = (*si)->align2();
-      this->setFileOffset(startOffset);
-      (*si)->setFileOffset(newOffset);
-      curSliceSize = (*si)->fileSize();
-      isFirstSection = false;
-    } else {
-      uint64_t curOffset = curSliceFileOffset + curSliceSize;
-      uint64_t newOffset =
-        llvm::RoundUpToAlignment(curOffset, (*si)->align2());
-      SegmentSlice<ELFT> *slice = nullptr;
-      // If the newOffset computed is more than a page away, lets create
-      // a seperate segment, so that memory is not used up while running
-      if ((newOffset - curOffset) > this->_targetInfo.getPageSize()) {
-        // TODO: use std::find here
-        for (auto s : slices()) {
-          if (s->startSection() == startSection) {
-            slice = s;
-            break;
-          }
-        }
-        if (!slice) {
-          slice = new (_segmentAllocate.Allocate<SegmentSlice<ELFT>>())
-            SegmentSlice<ELFT>();
-          _segmentSlices.push_back(slice);
-        }
-        slice->set(curSliceFileOffset, startSection, currSection);
-        slice->setSections(make_range(startSectionIter, endSectionIter));
-        slice->setSize(curSliceSize);
-        slice->setAlign(sliceAlign);
-        uint64_t newPageOffset = llvm::RoundUpToAlignment(
-            curOffset, this->_targetInfo.getPageSize());
-        newOffset = llvm::RoundUpToAlignment(newPageOffset, (*si)->align2());
-        curSliceFileOffset = newOffset;
-        startSectionIter = endSectionIter;
-        startSection = currSection;
-        (*si)->setFileOffset(curSliceFileOffset);
-        curSliceSize = newOffset - curSliceFileOffset + (*si)->fileSize();
-        sliceAlign = (*si)->align2();
-      } else {
-        if (sliceAlign < (*si)->align2())
-          sliceAlign = (*si)->align2();
-        (*si)->setFileOffset(newOffset);
-        curSliceSize = newOffset - curSliceFileOffset + (*si)->fileSize();
-      }
-    }
-    currSection++;
-    endSectionIter = si;
-  }
-  SegmentSlice<ELFT> *slice = nullptr;
-  for (auto s : slices()) {
-    // TODO: add std::find
-    if (s->startSection() == startSection) {
-      slice = s;
-      break;
-    }
-  }
-  if (!slice) {
-    slice = new (_segmentAllocate.Allocate<SegmentSlice<ELFT>>())
-      SegmentSlice<ELFT>();
-    _segmentSlices.push_back(slice);
-  }
-  slice->set(curSliceFileOffset, startSection, currSection);
-  slice->setSections(make_range(startSectionIter, _sections.end()));
-  slice->setSize(curSliceSize);
-  slice->setAlign(sliceAlign);
-  this->_fsize = curSliceFileOffset - startOffset + curSliceSize;
-  std::stable_sort(slices_begin(), slices_end(),
-                   SegmentSlice<ELFT>::compare_slices);
-}
-
-/// \brief Assign virtual addresses to the slices
-template<class ELFT>
-void 
-Segment<ELFT>::assignVirtualAddress(uint64_t &addr) {
-  for (auto slice : slices()) {
-    // Align to a page
-    addr = llvm::RoundUpToAlignment(addr, this->_targetInfo.getPageSize());
-    // Align to the slice alignment
-    addr = llvm::RoundUpToAlignment(addr, slice->align2());
-
-    bool virtualAddressSet = false;
-    for (auto section : slice->sections()) {
-      // Align the section address
-      addr = llvm::RoundUpToAlignment(addr, section->align2());
-      if (!virtualAddressSet) {
-        slice->setVAddr(addr);
-        virtualAddressSet = true;
-      }
-      section->setVAddr(addr);
-      if (auto s = dyn_cast<Section<ELFT>>(section))
-        s->assignVirtualAddress(addr);
-      else
-        addr += section->memSize();
-      section->setMemSize(addr - section->virtualAddr());
-    }
-    slice->setMemSize(addr - slice->virtualAddr());
-  }
-}
-
-// Write the Segment
-template <class ELFT>
-void Segment<ELFT>::write(ELFWriter *writer, llvm::FileOutputBuffer &buffer) {
-  for (auto slice : slices())
-    for (auto section : slice->sections())
-      section->write(writer, buffer);
-}
-
-template<class ELFT>
-int64_t 
-Segment<ELFT>::flags() const {
-  int64_t fl = 0;
-  if (_flags & llvm::ELF::SHF_ALLOC)
-    fl |= llvm::ELF::PF_R;
-  if (_flags & llvm::ELF::SHF_WRITE)
-    fl |= llvm::ELF::PF_W;
-  if (_flags & llvm::ELF::SHF_EXECINSTR)
-    fl |= llvm::ELF::PF_X;
-  return fl;
-}
-
-} // elf
-} // lld
-
-#endif // LLD_READER_WRITER_ELF_SEGMENT_CHUNKS_H_

Removed: lld/trunk/lib/ReaderWriter/ELF/ELFTargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFTargetHandler.h?rev=173837&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFTargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFTargetHandler.h (removed)
@@ -1,157 +0,0 @@
-//===- lib/ReaderWriter/ELF/ELFTargetHandler.h -----------------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file
-/// \brief These interfaces provide target specific hooks to change the linker's
-/// behaivor.
-///
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_READER_WRITER_ELF_TARGETHANDLER_H
-#define LLD_READER_WRITER_ELF_TARGETHANDLER_H
-
-#include "lld/Core/InputFiles.h"
-#include "lld/Core/LinkerOptions.h"
-#include "lld/Core/LLVM.h"
-#include "lld/Core/TargetInfo.h"
-#include "lld/ReaderWriter/ELFTargetInfo.h"
-
-#include "llvm/ADT/Hashing.h"
-
-#include <memory>
-#include <vector>
-#include <unordered_map>
-
-namespace lld {
-template <class ELFT> class ELFDefinedAtom;
-namespace elf {
-template <class ELFT> class ELFTargetLayout;
-template <class ELFT> class ELFHeader;
-template <class ELFT> class Section;
-
-/// \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 ELFT> class ELFTargetAtomHandler {
-public:
-  typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym;
-
-  virtual DefinedAtom::ContentType contentType(
-      const lld::ELFDefinedAtom<ELFT> *atom) const {
-    return atom->contentType();
-  }
-
-  virtual DefinedAtom::ContentType contentType(const Elf_Sym *sym) const {
-    return DefinedAtom::typeZeroFill;
-  }
-
-  virtual DefinedAtom::ContentPermissions contentPermissions(
-      const lld::ELFDefinedAtom<ELFT> *atom) const {
-    return atom->permissions();
-  }
-};
-
-/// \brief An interface to override functions that are provided by the 
-/// the default ELF Layout
-template <class ELFT> class ELFTargetHandler : public ELFTargetHandlerBase {
-
-public:
-  ELFTargetHandler(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
-  /// of atoms that is determined by the target
-  void registerTargetSection(StringRef name,
-                             DefinedAtom::ContentPermissions perm) {
-    const TargetSectionKey targetSection(name, perm);
-    if (_registeredTargetSections.find(targetSection) ==
-        _registeredTargetSections.end())
-      _registeredTargetSections.insert(std::make_pair(targetSection, true));
-  }
-
-  /// Check if the section is registered given the section name and its
-  /// contentType, if they are registered the target would need to 
-  /// create a section so that atoms insert, atom virtual address assignment
-  /// could be overridden and controlled by the Target
-  bool isSectionRegisteredByTarget(StringRef name,
-                                   DefinedAtom::ContentPermissions perm) {
-    const TargetSectionKey targetSection(name, perm);
-    if (_registeredTargetSections.find(targetSection) ==
-        _registeredTargetSections.end())
-      return false;
-    return true;
-  }
-
-  /// 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;
-
-  /// Set the ELF Header information 
-  virtual void setELFHeaderInfo(ELFHeader<ELFT> *elfHeader) = 0;
-
-  /// ELFTargetLayout 
-  virtual ELFTargetLayout<ELFT> &targetLayout() = 0;
-
-  /// ELFTargetAtomHandler
-  virtual ELFTargetAtomHandler<ELFT> &targetAtomHandler() = 0;
-
-  /// Create a set of Default target sections that a target might needj
-  virtual void createDefaultSections() = 0;
-
-  /// \brief Add a section to the current Layout
-  virtual void addSection(Section<ELFT> *section) = 0;
-
-  /// \brief add new symbol file 
-  virtual void addFiles(InputFiles &) = 0;
-
-  /// \brief Finalize the symbol values
-  virtual void finalizeSymbolValues() = 0;
-
-  /// \brief allocate Commons, some architectures may move small common
-  /// symbols over to small data, this would also be used 
-  virtual void allocateCommons() = 0;
-
-private:
-  struct TargetSectionKey {
-    TargetSectionKey(StringRef name, DefinedAtom::ContentPermissions perm)
-        : _name(name), _perm(perm) {
-    }
-
-    // Data members
-    const StringRef _name;
-    DefinedAtom::ContentPermissions _perm;
-  };
-
-  struct TargetSectionKeyHash {
-    int64_t operator()(const TargetSectionKey &k) const {
-      return llvm::hash_combine(k._name, k._perm);
-    }
-  };
-
-  struct TargetSectionKeyEq {
-    bool operator()(const TargetSectionKey &lhs,
-                    const TargetSectionKey &rhs) const {
-      return ((lhs._name == rhs._name) && (lhs._perm == rhs._perm));
-    }
-  };
-
-  typedef std::unordered_map<TargetSectionKey, bool, TargetSectionKeyHash,
-                             TargetSectionKeyEq> RegisteredTargetSectionMapT;
-  typedef typename RegisteredTargetSectionMapT::iterator RegisteredTargetSectionMapIterT;
-
-protected:
-  const ELFTargetInfo &_targetInfo;
-  RegisteredTargetSectionMapT _registeredTargetSections;
-};
-
-} // elf
-} // lld
-
-#endif // LLD_READER_WRITER_ELF_TARGETHANDLER_H

Modified: lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp?rev=173838&r1=173837&r2=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp Tue Jan 29 16:03:39 2013
@@ -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
 std::unique_ptr<ELFTargetInfo> ELFTargetInfo::create(const LinkerOptions &lo) {
   switch (llvm::Triple(llvm::Triple::normalize(lo._target)).getArch()) {
   case llvm::Triple::x86:
-    return std::unique_ptr<ELFTargetInfo>(new lld::elf::X86ELFTargetInfo(lo));
+    return std::unique_ptr<ELFTargetInfo>(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<ELFTargetInfo>(new lld::elf::PPCELFTargetInfo(lo));
+    return std::unique_ptr<ELFTargetInfo>(new lld::elf::PPCTargetInfo(lo));
   default:
     return std::unique_ptr<ELFTargetInfo>();
   }

Removed: lld/trunk/lib/ReaderWriter/ELF/ELFTargetLayout.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFTargetLayout.h?rev=173837&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFTargetLayout.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFTargetLayout.h (removed)
@@ -1,64 +0,0 @@
-//===- lib/ReaderWriter/ELF/ELFTargetLayout.h -----------------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_READER_WRITER_ELF_TARGET_LAYOUT_H
-#define LLD_READER_WRITER_ELF_TARGET_LAYOUT_H
-
-#include "DefaultELFLayout.h"
-
-#include "lld/Core/LLVM.h"
-
-namespace lld {
-namespace elf {
-/// \brief The target can override certain functions in the DefaultELFLayout
-/// class so that the order, the name of the section and the segment type could
-/// be changed in the final layout
-template <class ELFT> class ELFTargetLayout : public DefaultELFLayout<ELFT> {
-public:
-  ELFTargetLayout(ELFTargetInfo &targetInfo)
-      : DefaultELFLayout<ELFT>(targetInfo) {
-  }
-
-  /// isTargetSection provides a way to determine if the section that
-  /// we are processing has been registered by the target and the target
-  /// wants to handle them. 
-  /// For example: the Writer may be processing a section but the target
-  /// might want to override the functionality on how atoms are inserted
-  /// into the section. Such sections are set the K_TargetSection flag in
-  /// the SectionKind after they are created
-  virtual bool isTargetSection(const StringRef name, const int32_t contentType,
-                               const int32_t contentPermissions) = 0;
-
-  /// The target may want to override the sectionName to a different
-  /// section Name in the output
-  virtual StringRef sectionName(const StringRef name, const int32_t contentType,
-                                const int32_t contentPermissions) = 0;
-
-  /// The target may want to override the section order that has been 
-  /// set by the DefaultLayout
-  virtual ELFLayout::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<ELFT> *section) const = 0;
-
-  /// Returns true/false depending on whether the section has a Output
-  //  segment or not
-  bool hasOutputSegment(Section<ELFT> *section) = 0;
-
-  /// Returns the target Section for a section name and content Type
-  Section<ELFT> *getSection(const StringRef name,
-                            DefinedAtom::ContentPermissions permissions) = 0;
-
-};
-} // end namespace elf
-} // end namespace lld
-
-#endif

Removed: lld/trunk/lib/ReaderWriter/ELF/ELFTargets.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFTargets.h?rev=173837&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFTargets.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFTargets.h (removed)
@@ -1,18 +0,0 @@
-//===- lib/ReaderWriter/ELF/ELFTargets.h ----------------------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#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"
-
-#endif

Removed: lld/trunk/lib/ReaderWriter/ELF/ELFWriter.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFWriter.h?rev=173837&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFWriter.h (removed)
@@ -1,45 +0,0 @@
-//===- lib/ReaderWriter/ELF/ELFWriter.h ---------------------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_READER_WRITER_ELF_WRITER_H_
-#define LLD_READER_WRITER_ELF_WRITER_H_
-
-#include "ReferenceKinds.h"
-
-#include "lld/Core/File.h"
-#include "lld/Core/InputFiles.h"
-#include "lld/ReaderWriter/Writer.h"
-
-namespace lld {
-namespace elf {
-/// \brief The ELFWriter class is a base class for the linker to write
-///        various kinds of ELF files.
-class ELFWriter : public Writer {
-public:
-  ELFWriter() { }
-
-public:
-  /// \brief builds the chunks that needs to be written to the output
-  ///        ELF file
-  virtual void buildChunks(const lld::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;
-
-  /// \brief Get the virtual address of \p atom after layout.
-  virtual uint64_t addressOfAtom(const Atom *atom) = 0;
-
-  /// \brief Return the processing function to apply Relocations
-  virtual KindHandler *kindHandler()  = 0;
-};
-
-} // elf
-} // lld
-
-#endif // LLD_READER_WRITER_ELF_WRITER_H_

Modified: lld/trunk/lib/ReaderWriter/ELF/ExecutableAtoms.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ExecutableAtoms.h?rev=173838&r1=173837&r2=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ExecutableAtoms.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ExecutableAtoms.h Tue Jan 29 16:03:39 2013
@@ -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 ELFT> class CRuntimeFileELF : public FileELF<ELFT> {
+template <class ELFT> class CRuntimeFile : public ELFFile<ELFT> {
 public:
   typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym;
-  CRuntimeFileELF(const ELFTargetInfo &ti) : FileELF<ELFT>(ti, "C runtime") {}
+  CRuntimeFile(const ELFTargetInfo &ti) : ELFFile<ELFT>(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<ELFT> > ())
-      ELFAbsoluteAtom<ELFT>(
-        *this, symbolName, symbol, -1);
+    auto *newAtom =
+        new (_allocator) ELFAbsoluteAtom<ELFT>(*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;
+    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<ELFT> > ())
-      ELFUndefinedAtom<ELFT>(
-        *this, symbolName, symbol);
+    auto *newAtom =
+        new (_allocator) ELFUndefinedAtom<ELFT>(*this, symbolName, symbol);
     _undefinedAtoms._atoms.push_back(newAtom);
   }
 
@@ -92,8 +87,7 @@ private:
   File::atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
   File::atom_collection_vector<AbsoluteAtom> _absoluteAtoms;
 };
+} // end namespace elf
+} // end namespace lld 
 
-} // namespace elf
-} // namespace lld 
-
-#endif // LLD_READER_WRITER_ELF_EXECUTABLE_ATOM_H_
+#endif

Copied: lld/trunk/lib/ReaderWriter/ELF/File.h (from r173824, lld/trunk/lib/ReaderWriter/ELF/FileELF.h)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/File.h?p2=lld/trunk/lib/ReaderWriter/ELF/File.h&p1=lld/trunk/lib/ReaderWriter/ELF/FileELF.h&r1=173824&r2=173838&rev=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/FileELF.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/File.h Tue Jan 29 16:03:39 2013
@@ -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 <map>
 
 namespace lld {
-
-template <class ELFT> 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 ELFT> class ELFFile : public File {
   typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym;
   typedef llvm::object::Elf_Shdr_Impl<ELFT> Elf_Shdr;
   typedef llvm::object::Elf_Rel_Impl<ELFT, false> Elf_Rel;
   typedef llvm::object::Elf_Rel_Impl<ELFT, true> 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<llvm::MemoryBuffer> MB,
+  ELFFile(const ELFTargetInfo &ti, std::unique_ptr<llvm::MemoryBuffer> 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<ELFT> &elfTargetHandler =
+          TargetHandler<ELFT> &TargetHandler =
               _elfTargetInfo.getTargetHandler<ELFT>();
-          elf::ELFTargetAtomHandler<ELFT> &elfAtomHandler =
-              elfTargetHandler.targetAtomHandler();
+          TargetAtomHandler<ELFT> &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

Removed: lld/trunk/lib/ReaderWriter/ELF/FileELF.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/FileELF.h?rev=173837&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/FileELF.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/FileELF.h (removed)
@@ -1,336 +0,0 @@
-//===- lib/ReaderWriter/ELF/FileELF.h ------------------------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// 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
-
-#include "AtomsELF.h"
-
-#include "lld/Core/Reference.h"
-#include "lld/ReaderWriter/ELFTargetInfo.h"
-#include "lld/ReaderWriter/ReaderArchive.h"
-
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/SmallString.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Object/ELF.h"
-#include "llvm/Object/ObjectFile.h"
-#include "llvm/Support/Allocator.h"
-#include "llvm/Support/Casting.h"
-#include "llvm/Support/ELF.h"
-#include "llvm/Support/Endian.h"
-#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ErrorOr.h"
-#include "llvm/Support/MathExtras.h"
-#include "llvm/Support/Memory.h"
-#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/Path.h"
-#include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/system_error.h"
-
-#include <map>
-
-namespace lld {
-
-template <class ELFT> class FileELF : public File {
-  typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym;
-  typedef llvm::object::Elf_Shdr_Impl<ELFT> Elf_Shdr;
-  typedef llvm::object::Elf_Rel_Impl<ELFT, false> Elf_Rel;
-  typedef llvm::object::Elf_Rel_Impl<ELFT, true> Elf_Rela;
-
-public:
-  FileELF(const ELFTargetInfo &ti, const StringRef name)
-      : File(name), _elfTargetInfo(ti) {
-  }
-
-  FileELF(const ELFTargetInfo &ti, std::unique_ptr<llvm::MemoryBuffer> MB,
-          llvm::error_code &EC)
-      : File(MB->getBufferIdentifier()), _elfTargetInfo(ti) {
-    static uint32_t lastOrdinal = 0;
-    _ordinal = lastOrdinal++;
-
-    llvm::OwningPtr<llvm::object::Binary> binaryFile;
-    EC = createBinary(MB.release(), binaryFile);
-    if (EC)
-      return;
-
-    // Point Obj to correct class and bitwidth ELF object
-    _objFile.reset(
-        llvm::dyn_cast<llvm::object::ELFObjectFile<ELFT> >(binaryFile.get()));
-
-    if (!_objFile) {
-      EC = make_error_code(llvm::object::object_error::invalid_file_type);
-      return;
-    }
-
-    binaryFile.take();
-
-    std::map<const Elf_Shdr *, std::vector<const Elf_Sym *> > sectionSymbols;
-
-    // Handle: SHT_REL and SHT_RELA sections:
-    // Increment over the sections, when REL/RELA section types are found add
-    // the contents to the RelocationReferences map.
-    llvm::object::section_iterator sit(_objFile->begin_sections());
-    llvm::object::section_iterator sie(_objFile->end_sections());
-    for (; sit != sie; sit.increment(EC)) {
-      if (EC)
-        return;
-
-      const Elf_Shdr *section = _objFile->getElfSection(sit);
-
-      if (section->sh_type == llvm::ELF::SHT_RELA) {
-        llvm::StringRef sectionName;
-        if ((EC = _objFile->getSectionName(section, sectionName)))
-          return;
-        // Get rid of the leading .rela so Atoms can use their own section
-        // name to find the relocs.
-        sectionName = sectionName.drop_front(5);
-
-        auto rai(_objFile->beginELFRela(section));
-        auto rae(_objFile->endELFRela(section));
-
-        auto &Ref = _relocationAddendRefences[sectionName];
-        for (; rai != rae; ++rai) {
-          Ref.push_back(&*rai);
-        }
-      }
-
-      if (section->sh_type == llvm::ELF::SHT_REL) {
-        llvm::StringRef sectionName;
-        if ((EC = _objFile->getSectionName(section, sectionName)))
-          return;
-        // Get rid of the leading .rel so Atoms can use their own section
-        // name to find the relocs.
-        sectionName = sectionName.drop_front(4);
-
-        auto ri(_objFile->beginELFRel(section));
-        auto re(_objFile->endELFRel(section));
-
-        auto &Ref = _relocationReferences[sectionName];
-        for (; ri != re; ++ri) {
-          Ref.push_back(&*ri);
-        }
-      }
-    }
-
-    // Increment over all the symbols collecting atoms and symbol names for
-    // later use.
-    llvm::object::symbol_iterator it(_objFile->begin_symbols());
-    llvm::object::symbol_iterator ie(_objFile->end_symbols());
-
-    for (; it != ie; it.increment(EC)) {
-      if (EC)
-        return;
-
-      if ((EC = it->getSection(sit)))
-        return;
-
-      const Elf_Shdr *section = _objFile->getElfSection(sit);
-      const Elf_Sym *symbol = _objFile->getElfSymbol(it);
-
-      llvm::StringRef symbolName;
-      if ((EC = _objFile->getSymbolName(section, symbol, symbolName)))
-        return;
-
-      if (symbol->st_shndx == llvm::ELF::SHN_ABS) {
-        // Create an absolute atom.
-        auto *newAtom = new (_readerStorage)
-            ELFAbsoluteAtom<ELFT>(*this, symbolName, symbol, symbol->st_value);
-
-        _absoluteAtoms._atoms.push_back(newAtom);
-        _symbolToAtomMapping.insert(std::make_pair(symbol, newAtom));
-      } else if (symbol->st_shndx == llvm::ELF::SHN_UNDEF) {
-        // Create an undefined atom.
-        auto *newAtom = new (_readerStorage)
-            ELFUndefinedAtom<ELFT>(*this, symbolName, symbol);
-
-        _undefinedAtoms._atoms.push_back(newAtom);
-        _symbolToAtomMapping.insert(std::make_pair(symbol, newAtom));
-      } else {
-        // This is actually a defined symbol. Add it to its section's list of
-        // symbols.
-        if (symbol->getType() == llvm::ELF::STT_NOTYPE || symbol->getType() ==
-            llvm::ELF::STT_OBJECT || symbol->getType() == llvm::ELF::STT_FUNC ||
-            symbol->getType() == llvm::ELF::STT_GNU_IFUNC ||
-            symbol->getType() == llvm::ELF::STT_SECTION || symbol->getType() ==
-            llvm::ELF::STT_FILE || symbol->getType() == llvm::ELF::STT_TLS ||
-            symbol->getType() == llvm::ELF::STT_COMMON ||
-            symbol->st_shndx == llvm::ELF::SHN_COMMON) {
-          sectionSymbols[section].push_back(symbol);
-        } else {
-          llvm::errs() << "Unable to create atom for: " << symbolName << "\n";
-          EC = llvm::object::object_error::parse_failed;
-          return;
-        }
-      }
-    }
-
-    for (auto &i : sectionSymbols) {
-      auto &symbols = i.second;
-      // Sort symbols by position.
-      std::stable_sort(symbols.begin(), symbols.end(),
-                       [](const Elf_Sym * A, const Elf_Sym * B) {
-        return A->st_value < B->st_value;
-      });
-
-      StringRef sectionContents;
-      if ((EC = _objFile->getSectionContents(i.first, sectionContents)))
-        return;
-
-      llvm::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;
-        if ((EC = _objFile->getSymbolName(i.first, *si, symbolName)))
-          return;
-
-        bool isCommon = (*si)->getType() == llvm::ELF::STT_COMMON ||
-                        (*si)->st_shndx == llvm::ELF::SHN_COMMON;
-
-        DefinedAtom::ContentType c;
-
-        if (((*si)->st_shndx >= llvm::ELF::SHN_LOPROC) &&
-            ((*si)->st_shndx <= llvm::ELF::SHN_HIPROC)) {
-          elf::ELFTargetHandler<ELFT> &elfTargetHandler =
-              _elfTargetInfo.getTargetHandler<ELFT>();
-          elf::ELFTargetAtomHandler<ELFT> &elfAtomHandler =
-              elfTargetHandler.targetAtomHandler();
-          c = elfAtomHandler.contentType(*si);
-
-          if (c == DefinedAtom::typeZeroFill)
-            isCommon = true;
-        }
-
-        // Get the symbol's content:
-        uint64_t contentSize;
-        if (si + 1 == se) {
-          // if this is the last symbol, take up the remaining data.
-          contentSize = isCommon ? 0 : i.first->sh_size - (*si)->st_value;
-        } else {
-          contentSize = isCommon ? 0 : (*(si + 1))->st_value - (*si)->st_value;
-        }
-
-        // Don't allocate content to a weak symbol, as they may be merged away.
-        // Create an anonymous atom to hold the data.
-        ELFDefinedAtom<ELFT> *anonAtom = nullptr;
-        if ((*si)->getBinding() == llvm::ELF::STB_WEAK && contentSize != 0) {
-          // Create a new non-weak ELF symbol.
-          auto sym = new (_readerStorage) Elf_Sym;
-          *sym = **si;
-          sym->setBinding(llvm::ELF::STB_GLOBAL);
-          anonAtom = createDefinedAtomAndAssignRelocations(
-              "", sectionName, sym, i.first,
-              ArrayRef<uint8_t>((uint8_t *)sectionContents.data() +
-                                (*si)->st_value, contentSize));
-          contentSize = 0;
-        }
-
-        ArrayRef<uint8_t> symbolData = ArrayRef<uint8_t>(
-            (uint8_t *)sectionContents.data() + (*si)->st_value, contentSize);
-
-        auto newAtom = createDefinedAtomAndAssignRelocations(
-            symbolName, sectionName, *si, i.first, symbolData);
-
-        _definedAtoms._atoms.push_back(newAtom);
-        _symbolToAtomMapping.insert(std::make_pair((*si), newAtom));
-        if (anonAtom)
-          _definedAtoms._atoms.push_back(anonAtom);
-      }
-    }
-
-    // All the Atoms and References are created.  Now update each Reference's
-    // target with the Atom pointer it refers to.
-    for (auto &ri : _references) {
-      const Elf_Sym *Symbol = _objFile->getElfSymbol(ri->targetSymbolIndex());
-      ri->setTarget(findAtom(Symbol));
-    }
-  }
-
-  virtual const atom_collection<DefinedAtom> &defined() const {
-    return _definedAtoms;
-  }
-
-  virtual const atom_collection<UndefinedAtom> &undefined() const {
-    return _undefinedAtoms;
-  }
-
-  virtual const atom_collection<SharedLibraryAtom> &sharedLibrary() const {
-    return _sharedLibraryAtoms;
-  }
-
-  virtual const atom_collection<AbsoluteAtom> &absolute() const {
-    return _absoluteAtoms;
-  }
-
-  virtual const ELFTargetInfo &getTargetInfo() const { return _elfTargetInfo; }
-
-  Atom *findAtom(const Elf_Sym *symbol) {
-    return _symbolToAtomMapping.lookup(symbol);
-  }
-
-private:
-  ELFDefinedAtom<ELFT> *createDefinedAtomAndAssignRelocations(
-      StringRef symbolName, StringRef sectionName, const Elf_Sym *symbol,
-      const Elf_Shdr *section, ArrayRef<uint8_t> content) {
-    unsigned int referenceStart = _references.size();
-
-    // Only relocations that are inside the domain of the atom are added.
-
-    // Add Rela (those with r_addend) references:
-    for (auto &rai : _relocationAddendRefences[sectionName]) {
-      if (!((rai->r_offset >= symbol->st_value) &&
-            (rai->r_offset < symbol->st_value + content.size())))
-        continue;
-      auto *ERef = new (_readerStorage)
-          ELFReference<ELFT>(rai, rai->r_offset - symbol->st_value, nullptr);
-      _references.push_back(ERef);
-    }
-
-    // Add Rel references.
-    for (auto &ri : _relocationReferences[sectionName]) {
-      if ((ri->r_offset >= symbol->st_value) &&
-          (ri->r_offset < symbol->st_value + content.size())) {
-        auto *ERef = new (_readerStorage)
-            ELFReference<ELFT>(ri, ri->r_offset - symbol->st_value, nullptr);
-        _references.push_back(ERef);
-      }
-    }
-
-    // Create the DefinedAtom and add it to the list of DefinedAtoms.
-    return new (_readerStorage) ELFDefinedAtom<
-        ELFT>(*this, symbolName, sectionName, symbol, section, content,
-              referenceStart, _references.size(), _references);
-  }
-
-  std::unique_ptr<llvm::object::ELFObjectFile<ELFT> > _objFile;
-  atom_collection_vector<DefinedAtom> _definedAtoms;
-  atom_collection_vector<UndefinedAtom> _undefinedAtoms;
-  atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
-  atom_collection_vector<AbsoluteAtom> _absoluteAtoms;
-
-  /// \brief _relocationAddendRefences and _relocationReferences contain the
-  /// list of relocations references.  In ELF, if a section named, ".text" has
-  /// relocations will also have a section named ".rel.text" or ".rela.text"
-  /// which will hold the entries. -- .rel or .rela is prepended to create
-  /// the SHT_REL(A) section name.
-  std::map<StringRef, std::vector<const Elf_Rela *> > _relocationAddendRefences;
-  std::map<StringRef, std::vector<const Elf_Rel *> > _relocationReferences;
-  std::vector<ELFReference<ELFT> *> _references;
-  llvm::DenseMap<const Elf_Sym *, Atom *> _symbolToAtomMapping;
-  llvm::BumpPtrAllocator _readerStorage;
-  const ELFTargetInfo &_elfTargetInfo;
-};
-} // lld
-
-#endif

Copied: lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h (from r173824, lld/trunk/lib/ReaderWriter/ELF/ELFHeaderChunks.h)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h?p2=lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h&p1=lld/trunk/lib/ReaderWriter/ELF/ELFHeaderChunks.h&r1=173824&r2=173838&rev=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFHeaderChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h Tue Jan 29 16:03:39 2013
@@ -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 ELFT>
-class ELFHeader : public Chunk<ELFT> {
+class Header : public Chunk<ELFT> {
 public:
   typedef llvm::object::Elf_Ehdr_Impl<ELFT> 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<ELFT> *c) {
-    return c->Kind() == Chunk<ELFT>::K_ELFHeader;
+    return c->Kind() == Chunk<ELFT>::K_Header;
   }
 
   void write(ELFWriter *writer, llvm::FileOutputBuffer &buffer);
@@ -60,8 +59,8 @@ private:
 };
 
 template <class ELFT>
-ELFHeader<ELFT>::ELFHeader(const ELFTargetInfo &ti)
-    : Chunk<ELFT>("elfhdr", Chunk<ELFT>::K_ELFHeader, ti) {
+Header<ELFT>::Header(const ELFTargetInfo &ti)
+    : Chunk<ELFT>("elfhdr", Chunk<ELFT>::K_Header, ti) {
   this->_align2 = ELFT::Is64Bits ? 8 : 4;
   this->_fsize = sizeof(Elf_Ehdr);
   this->_msize = sizeof(Elf_Ehdr);
@@ -75,16 +74,16 @@ ELFHeader<ELFT>::ELFHeader(const ELFTarg
 }
 
 template <class ELFT>
-void ELFHeader<ELFT>::write(ELFWriter *writer, llvm::FileOutputBuffer &buffer) {
+void Header<ELFT>::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 ELFT>
-class ELFProgramHeader : public Chunk<ELFT> {
+class ProgramHeader : public Chunk<ELFT> {
 public:
   typedef llvm::object::Elf_Phdr_Impl<ELFT> Elf_Phdr;
   typedef typename std::vector<Elf_Phdr *>::iterator PhIterT;
@@ -110,8 +109,8 @@ public:
     uint64_t _flagsClear;
   };
 
-  ELFProgramHeader(const ELFTargetInfo &ti)
-      : Chunk<ELFT>("elfphdr", Chunk<ELFT>::K_ELFProgramHeader, ti) {
+  ProgramHeader(const ELFTargetInfo &ti)
+      : Chunk<ELFT>("elfphdr", Chunk<ELFT>::K_ProgramHeader, ti) {
     this->_align2 = ELFT::Is64Bits ? 8 : 4;
     resetProgramHeaders();
   }
@@ -127,7 +126,7 @@ public:
   }
 
   static inline bool classof(const Chunk<ELFT> *c) {
-    return c->Kind() == Chunk<ELFT>::K_ELFProgramHeader;
+    return c->Kind() == Chunk<ELFT>::K_ProgramHeader;
   }
 
   void write(ELFWriter *writer, llvm::FileOutputBuffer &buffer);
@@ -164,7 +163,7 @@ private:
 
 template<class ELFT>
 bool
-ELFProgramHeader<ELFT>::addSegment(Segment<ELFT> *segment) {
+ProgramHeader<ELFT>::addSegment(Segment<ELFT> *segment) {
   Elf_Phdr *phdr = nullptr;
   bool ret = false;
 
@@ -195,7 +194,7 @@ ELFProgramHeader<ELFT>::addSegment(Segme
 }
 
 template <class ELFT>
-void ELFProgramHeader<ELFT>::write(ELFWriter *writer,
+void ProgramHeader<ELFT>::write(ELFWriter *writer,
                                    llvm::FileOutputBuffer &buffer) {
   uint8_t *chunkBuffer = buffer.getBufferStart();
   uint8_t *dest = chunkBuffer + this->fileOffset();
@@ -205,24 +204,24 @@ void ELFProgramHeader<ELFT>::write(ELFWr
   }
 }
 
-/// \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 ELFT>
-class ELFSectionHeader : public Chunk<ELFT> {
+class SectionHeader : public Chunk<ELFT> {
 public:
   typedef llvm::object::Elf_Shdr_Impl<ELFT> Elf_Shdr;
 
-  ELFSectionHeader(const ELFTargetInfo &, int32_t order);
+  SectionHeader(const ELFTargetInfo &, int32_t order);
 
   void appendSection(MergedSections<ELFT> *section);
   
   void updateSection(Section<ELFT> *section);
   
   static inline bool classof(const Chunk<ELFT> *c) {
-    return c->getChunkKind() == Chunk<ELFT>::K_ELFSectionHeader;
+    return c->getChunkKind() == Chunk<ELFT>::K_SectionHeader;
   }
   
-  void setStringSection(ELFStringTable<ELFT> *s) {
+  void setStringSection(StringTable<ELFT> *s) {
     _stringSection = s;
   }
 
@@ -243,14 +242,14 @@ public:
   }
 
 private:
-  ELFStringTable<ELFT> *_stringSection;
+  StringTable<ELFT> *_stringSection;
   std::vector<Elf_Shdr*>                  _sectionInfo;
   llvm::BumpPtrAllocator                  _sectionAllocate;
 };
 
 template <class ELFT>
-ELFSectionHeader<ELFT>::ELFSectionHeader(const ELFTargetInfo &ti, int32_t order)
-    : Chunk<ELFT>("shdr", Chunk<ELFT>::K_ELFSectionHeader, ti) {
+SectionHeader<ELFT>::SectionHeader(const ELFTargetInfo &ti, int32_t order)
+    : Chunk<ELFT>("shdr", Chunk<ELFT>::K_SectionHeader, ti) {
   this->_fsize = 0;
   this->_align2 = 8;
   this->setOrder(order);
@@ -263,7 +262,7 @@ ELFSectionHeader<ELFT>::ELFSectionHeader
 
 template<class ELFT>
 void 
-ELFSectionHeader<ELFT>::appendSection(MergedSections<ELFT> *section) {
+SectionHeader<ELFT>::appendSection(MergedSections<ELFT> *section) {
   Elf_Shdr *shdr = new (_sectionAllocate.Allocate<Elf_Shdr>()) Elf_Shdr;
   shdr->sh_name   = _stringSection->addString(section->name());
   shdr->sh_type   = section->type();
@@ -280,7 +279,7 @@ ELFSectionHeader<ELFT>::appendSection(Me
 
 template<class ELFT>
 void 
-ELFSectionHeader<ELFT>::updateSection(Section<ELFT> *section) {
+SectionHeader<ELFT>::updateSection(Section<ELFT> *section) {
   Elf_Shdr *shdr = _sectionInfo[section->ordinal()];
   shdr->sh_type   = section->type();
   shdr->sh_flags  = section->flags();
@@ -294,7 +293,7 @@ ELFSectionHeader<ELFT>::updateSection(Se
 }
 
 template <class ELFT>
-void ELFSectionHeader<ELFT>::write(ELFWriter *writer,
+void SectionHeader<ELFT>::write(ELFWriter *writer,
                                    llvm::FileOutputBuffer &buffer) {
   uint8_t *chunkBuffer = buffer.getBufferStart();
   uint8_t *dest = chunkBuffer + this->fileOffset();
@@ -304,8 +303,7 @@ void ELFSectionHeader<ELFT>::write(ELFWr
   }
   _stringSection->write(writer, buffer);
 }
+} // end namespace elf
+} // end namespace lld
 
-} // elf
-} // lld
-
-#endif // LLD_READER_WRITER_ELF_HEADER_CHUNKS_H_
+#endif

Removed: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTarget.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTarget.h?rev=173837&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTarget.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTarget.h (removed)
@@ -1,9 +0,0 @@
-//===- lib/ReaderWriter/ELF/Hexagon/HexagonELFTarget.h ---------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "HexagonELFTargetInfo.h"

Removed: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTargetInfo.h?rev=173837&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTargetInfo.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTargetInfo.h (removed)
@@ -1,36 +0,0 @@
-//===- lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h ------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_READER_WRITER_ELF_HEXAGON_TARGETINFO_H
-#define LLD_READER_WRITER_ELF_HEXAGON_TARGETINFO_H
-
-#include "lld/ReaderWriter/ELFTargetInfo.h"
-#include "lld/Core/LinkerOptions.h"
-#include "llvm/Object/ELF.h"
-#include "llvm/Support/ELF.h"
-
-#include "DefaultELFTargetHandler.h"
-
-namespace lld {
-namespace elf {
-class HexagonELFTargetInfo LLVM_FINAL : public ELFTargetInfo {
-public:
-  HexagonELFTargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) {
-    _targetHandler = std::unique_ptr<ELFTargetHandlerBase>(
-        new DefaultELFTargetHandler<llvm::object::ELFType<llvm::support::little,
-                                                          4, false> >(*this));
-  }
-
-  virtual uint64_t getPageSize() const { return 0x1000; }
-};
-
-} // elf
-} // lld
-
-#endif // LLD_READER_WRITER_ELF_HEXAGON_TARGETINFO_H

Copied: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTarget.h (from r173824, lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTarget.h)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTarget.h?p2=lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTarget.h&p1=lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTarget.h&r1=173824&r2=173838&rev=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTarget.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTarget.h Tue Jan 29 16:03:39 2013
@@ -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"

Copied: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h (from r173824, lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTargetInfo.h)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h?p2=lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h&p1=lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTargetInfo.h&r1=173824&r2=173838&rev=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTargetInfo.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h Tue Jan 29 16:03:39 2013
@@ -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<ELFTargetHandlerBase>(
-        new DefaultELFTargetHandler<llvm::object::ELFType<llvm::support::little,
+  HexagonTargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) {
+    _targetHandler = std::unique_ptr<TargetHandlerBase>(
+        new DefaultTargetHandler<llvm::object::ELFType<llvm::support::little,
                                                           4, false> >(*this));
   }
 

Copied: lld/trunk/lib/ReaderWriter/ELF/Layout.h (from r173824, lld/trunk/lib/ReaderWriter/ELF/ELFLayout.h)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Layout.h?p2=lld/trunk/lib/ReaderWriter/ELF/Layout.h&p1=lld/trunk/lib/ReaderWriter/ELF/ELFLayout.h&r1=173824&r2=173838&rev=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFLayout.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Layout.h Tue Jan 29 16:03:39 2013
@@ -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

Removed: lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTarget.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTarget.h?rev=173837&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTarget.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTarget.h (removed)
@@ -1,9 +0,0 @@
-//===- lib/ReaderWriter/ELF/PPC/PPCELFTarget.h ---------------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "PPCELFTargetInfo.h"

Removed: lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTargetInfo.h?rev=173837&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTargetInfo.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTargetInfo.h (removed)
@@ -1,38 +0,0 @@
-//===- lib/ReaderWriter/ELF/Hexagon/PPCTargetInfo.h -----------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_READER_WRITER_ELF_PPC_TARGETINFO_H
-#define LLD_READER_WRITER_ELF_PPC_TARGETINFO_H
-
-#include "lld/ReaderWriter/ELFTargetInfo.h"
-#include "lld/Core/LinkerOptions.h"
-#include "llvm/Object/ELF.h"
-#include "llvm/Support/ELF.h"
-
-#include "DefaultELFTargetHandler.h"
-
-namespace lld {
-namespace elf {
-class PPCELFTargetInfo LLVM_FINAL : public ELFTargetInfo {
-public:
-  PPCELFTargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) {
-    _targetHandler = std::unique_ptr<ELFTargetHandlerBase>(
-        new DefaultELFTargetHandler<
-                llvm::object::ELFType<llvm::support::big, 4, false> >(*this));
-  }
-
-  virtual bool isLittleEndian() const { return false; }
-
-  virtual uint64_t getPageSize() const { return 0x1000; }
-};
-
-} // elf
-} // lld
-
-#endif // LLD_READER_WRITER_ELF_PPC_TARGETINFO_H

Copied: lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTarget.h (from r173824, lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTarget.h)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTarget.h?p2=lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTarget.h&p1=lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTarget.h&r1=173824&r2=173838&rev=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTarget.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTarget.h Tue Jan 29 16:03:39 2013
@@ -1,4 +1,4 @@
-//===- lib/ReaderWriter/ELF/Hexagon/X86ELFTarget.h -----------------------===//
+//===- lib/ReaderWriter/ELF/PPC/PPCTarget.h -------------------------------===//
 //
 //                             The LLVM Linker
 //
@@ -6,4 +6,5 @@
 // License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
-#include "X86ELFTargetInfo.h"
+
+#include "PPCTargetInfo.h"

Copied: lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetInfo.h (from r173824, lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTargetInfo.h)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetInfo.h?p2=lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetInfo.h&p1=lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTargetInfo.h&r1=173824&r2=173838&rev=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTargetInfo.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetInfo.h Tue Jan 29 16:03:39 2013
@@ -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<ELFTargetHandlerBase>(
-        new DefaultELFTargetHandler<
+  PPCTargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) {
+    _targetHandler = std::unique_ptr<TargetHandlerBase>(
+        new DefaultTargetHandler<
                 llvm::object::ELFType<llvm::support::big, 4, false> >(*this));
   }
 

Copied: lld/trunk/lib/ReaderWriter/ELF/Reader.cpp (from r173824, lld/trunk/lib/ReaderWriter/ELF/ReaderELF.cpp)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Reader.cpp?p2=lld/trunk/lib/ReaderWriter/ELF/Reader.cpp&p1=lld/trunk/lib/ReaderWriter/ELF/ReaderELF.cpp&r1=173824&r2=173838&rev=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ReaderELF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Reader.cpp Tue Jan 29 16:03:39 2013
@@ -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 <map>
 #include <vector>
 
-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<ReaderFunc> read)
-      : Reader(ti), _elfTargetInfo(ti), _readerArchive(ti, read) {
+  ELFReader(const ELFTargetInfo &ti, std::function<ReaderFunc> read)
+      : lld::Reader(ti), _elfTargetInfo(ti), _readerArchive(ti, read) {
   }
 
   error_code parseFile(std::unique_ptr<MemoryBuffer> mb,
@@ -71,46 +71,46 @@ public:
     case llvm::sys::ELF_Relocatable_FileType: {
       std::pair<unsigned char, unsigned char> Ident = getElfArchType(&*mb);
       std::unique_ptr<File> 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<ELFType<llvm::support::little, 4, false> >(
+          f.reset(new ELFFile<ELFType<llvm::support::little, 4, false> >(
                           _elfTargetInfo, std::move(mb), ec));
         else if (MaxAlignment >= 2)
-          f.reset(new FileELF<ELFType<llvm::support::little, 2, false> >(
+          f.reset(new ELFFile<ELFType<llvm::support::little, 2, false> >(
                           _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<ELFType<llvm::support::big, 4, false> >(
+          f.reset(new ELFFile<ELFType<llvm::support::big, 4, false> >(
                           _elfTargetInfo, std::move(mb), ec));
         else if (MaxAlignment >= 2)
-          f.reset(new FileELF<ELFType<llvm::support::big, 2, false> >(
+          f.reset(new ELFFile<ELFType<llvm::support::big, 2, false> >(
                           _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<ELFType<llvm::support::big, 8, true> >(
+          f.reset(new ELFFile<ELFType<llvm::support::big, 8, true> >(
                           _elfTargetInfo, std::move(mb), ec));
         else if (MaxAlignment >= 2)
-          f.reset(new FileELF<ELFType<llvm::support::big, 2, true> >(
+          f.reset(new ELFFile<ELFType<llvm::support::big, 2, true> >(
                           _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<ELFType<llvm::support::little, 8, true> >(
+          f.reset(new ELFFile<ELFType<llvm::support::little, 8, true> >(
                           _elfTargetInfo, std::move(mb), ec));
         else if (MaxAlignment >= 2)
-          f.reset(new FileELF<ELFType<llvm::support::little, 2, true> >(
+          f.reset(new ELFFile<ELFType<llvm::support::little, 2, true> >(
                           _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<Reader> createReaderELF(const ELFTargetInfo &eti,
                                         std::function<ReaderFunc> read) {
-  return std::unique_ptr<Reader>(new ReaderELF(eti, std::move(read)));
+  return std::unique_ptr<Reader>(new elf::ELFReader(eti, std::move(read)));
 }
 } // end namespace lld

Removed: lld/trunk/lib/ReaderWriter/ELF/ReaderELF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ReaderELF.cpp?rev=173837&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ReaderELF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ReaderELF.cpp (removed)
@@ -1,147 +0,0 @@
-//===- lib/ReaderWriter/ELF/ReaderELF.cpp ---------------------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file
-/// \brief Defines the ELF Reader and all helper sub classes to consume an ELF
-/// file and produces atoms out of it.
-///
-//===----------------------------------------------------------------------===//
-
-#include "lld/ReaderWriter/Reader.h"
-
-#include "AtomsELF.h"
-#include "FileELF.h"
-
-#include "lld/Core/Reference.h"
-#include "lld/ReaderWriter/ELFTargetInfo.h"
-#include "lld/ReaderWriter/ReaderArchive.h"
-
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/SmallString.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Object/ELF.h"
-#include "llvm/Object/ObjectFile.h"
-#include "llvm/Support/Allocator.h"
-#include "llvm/Support/Casting.h"
-#include "llvm/Support/ELF.h"
-#include "llvm/Support/Endian.h"
-#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ErrorOr.h"
-#include "llvm/Support/MathExtras.h"
-#include "llvm/Support/Memory.h"
-#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/Path.h"
-#include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/system_error.h"
-
-#include <map>
-#include <vector>
-
-using namespace lld;
-using llvm::support::endianness;
-using namespace llvm::object;
-
-namespace {
-/// \brief A reader object that will instantiate correct FileELF by examining the
-/// memory buffer for ELF class and bit width
-class ReaderELF : public Reader {
-public:
-  ReaderELF(const ELFTargetInfo &ti, std::function<ReaderFunc> read)
-      : Reader(ti), _elfTargetInfo(ti), _readerArchive(ti, read) {
-  }
-
-  error_code parseFile(std::unique_ptr<MemoryBuffer> mb,
-                       std::vector<std::unique_ptr<File> > &result) {
-    using llvm::object::ELFType;
-    llvm::sys::LLVMFileType fileType =
-        llvm::sys::IdentifyFileType(mb->getBufferStart(),
-                                    static_cast<unsigned>(mb->getBufferSize()));
-
-    std::size_t MaxAlignment =
-        1ULL << llvm::CountTrailingZeros_64(uintptr_t(mb->getBufferStart()));
-
-    llvm::error_code ec;
-    switch (fileType) {
-    case llvm::sys::ELF_Relocatable_FileType: {
-      std::pair<unsigned char, unsigned char> Ident = getElfArchType(&*mb);
-      std::unique_ptr<File> f;
-      // Instantiate the correct FileELF 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<ELFType<llvm::support::little, 4, false> >(
-                          _elfTargetInfo, std::move(mb), ec));
-        else if (MaxAlignment >= 2)
-          f.reset(new FileELF<ELFType<llvm::support::little, 2, false> >(
-                          _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<ELFType<llvm::support::big, 4, false> >(
-                          _elfTargetInfo, std::move(mb), ec));
-        else if (MaxAlignment >= 2)
-          f.reset(new FileELF<ELFType<llvm::support::big, 2, false> >(
-                          _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<ELFType<llvm::support::big, 8, true> >(
-                          _elfTargetInfo, std::move(mb), ec));
-        else if (MaxAlignment >= 2)
-          f.reset(new FileELF<ELFType<llvm::support::big, 2, true> >(
-                          _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<ELFType<llvm::support::little, 8, true> >(
-                          _elfTargetInfo, std::move(mb), ec));
-        else if (MaxAlignment >= 2)
-          f.reset(new FileELF<ELFType<llvm::support::little, 2, true> >(
-                          _elfTargetInfo, std::move(mb), ec));
-        else
-          llvm_unreachable("Invalid alignment for ELF file!");
-      }
-      if (!ec)
-        result.push_back(std::move(f));
-      break;
-    }
-    case llvm::sys::Archive_FileType:
-      ec = _readerArchive.parseFile(std::move(mb), result);
-      break;
-    default:
-      llvm_unreachable("not supported format");
-      break;
-    }
-
-    if (ec)
-      return ec;
-
-    return error_code::success();
-  }
-
-private:
-  const ELFTargetInfo &_elfTargetInfo;
-  ReaderArchive _readerArchive;
-};
-} // end anon namespace.
-
-namespace lld {
-std::unique_ptr<Reader> createReaderELF(const ELFTargetInfo &eti,
-                                        std::function<ReaderFunc> read) {
-  return std::unique_ptr<Reader>(new ReaderELF(eti, std::move(read)));
-}
-} // end namespace lld

Copied: lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h (from r173824, lld/trunk/lib/ReaderWriter/ELF/ELFSectionChunks.h)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h?p2=lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h&p1=lld/trunk/lib/ReaderWriter/ELF/ELFSectionChunks.h&r1=173824&r2=173838&rev=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFSectionChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h Tue Jan 29 16:03:39 2013
@@ -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<AtomLayout> _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<Chunk<ELFT> *>::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<ELFT>::appendSection(Chun
 
 /// \brief The class represents the ELF String Table
 template<class ELFT>
-class ELFStringTable : public Section<ELFT> {
+class StringTable : public Section<ELFT> {
 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<ELFT> *c) {
     return c->kind() == Section<ELFT>::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<llvm::StringRef> _strings;
+  std::vector<StringRef> _strings;
 };
 
 template <class ELFT>
-ELFStringTable<ELFT>::ELFStringTable(const ELFTargetInfo &ti, const char *str,
+StringTable<ELFT>::StringTable(const ELFTargetInfo &ti, const char *str,
                                      int32_t order)
     : Section<ELFT>(ti, str, llvm::ELF::SHT_STRTAB, DefinedAtom::perm___, order,
                     Section<ELFT>::K_StringTable) {
@@ -537,7 +537,7 @@ ELFStringTable<ELFT>::ELFStringTable(con
 
 template<class ELFT>
 uint64_t
-ELFStringTable<ELFT>::addString(const StringRef symname) {
+StringTable<ELFT>::addString(const StringRef symname) {
   _strings.push_back(symname);
   uint64_t offset = this->_fsize;
   this->_fsize += symname.size() + 1;
@@ -545,7 +545,7 @@ ELFStringTable<ELFT>::addString(const St
 }
 
 template <class ELFT>
-void ELFStringTable<ELFT>::write(ELFWriter *writer,
+void StringTable<ELFT>::write(ELFWriter *writer,
                                  llvm::FileOutputBuffer &buffer) {
   uint8_t *chunkBuffer = buffer.getBufferStart();
   uint8_t *dest = chunkBuffer + this->fileOffset();
@@ -557,13 +557,13 @@ void ELFStringTable<ELFT>::write(ELFWrit
   }
 }
 
-/// \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 ELFT>
-class ELFSymbolTable : public Section<ELFT> {
+class SymbolTable : public Section<ELFT> {
 public:
   typedef llvm::object::Elf_Sym_Impl<ELFT> 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<ELFT>::K_SymbolTable;
   }
 
-  inline void setStringSection(ELFStringTable<ELFT> *s) {
+  inline void setStringSection(StringTable<ELFT> *s) {
     _stringSection = s;
   }
 
 private:
-  ELFStringTable<ELFT> *_stringSection;
+  StringTable<ELFT> *_stringSection;
   std::vector<Elf_Sym*> _symbolTable;
   llvm::BumpPtrAllocator _symbolAllocate;
   int64_t _link;
@@ -588,7 +588,7 @@ private:
 
 /// ELF Symbol Table 
 template <class ELFT>
-ELFSymbolTable<ELFT>::ELFSymbolTable(const ELFTargetInfo &ti, const char *str,
+SymbolTable<ELFT>::SymbolTable(const ELFTargetInfo &ti, const char *str,
                                      int32_t order)
     : Section<ELFT>(ti, str, llvm::ELF::SHT_SYMTAB, 0, order,
                     Section<ELFT>::K_SymbolTable) {
@@ -603,7 +603,7 @@ ELFSymbolTable<ELFT>::ELFSymbolTable(con
 
 template<class ELFT>
 void 
-ELFSymbolTable<ELFT>::addSymbol(const Atom *atom, 
+SymbolTable<ELFT>::addSymbol(const Atom *atom, 
                                 int32_t sectionIndex, 
                                 uint64_t addr) {
   Elf_Sym *symbol = new(_symbolAllocate.Allocate<Elf_Sym>()) Elf_Sym;
@@ -615,9 +615,9 @@ ELFSymbolTable<ELFT>::addSymbol(const At
   symbol->st_other = llvm::ELF::STV_DEFAULT;
   if (const DefinedAtom *da = dyn_cast<const DefinedAtom>(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<ELFT>::addSymbol(const At
       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<ELFT>::addSymbol(const At
 
 template<class ELFT>
 void 
-ELFSymbolTable<ELFT>::finalize() {
+SymbolTable<ELFT>::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<ELFT>::finalize() {
 }
 
 template <class ELFT>
-void ELFSymbolTable<ELFT>::write(ELFWriter *writer,
+void SymbolTable<ELFT>::write(ELFWriter *writer,
                                  llvm::FileOutputBuffer &buffer) {
   uint8_t *chunkBuffer = buffer.getBufferStart();
   uint8_t *dest = chunkBuffer + this->fileOffset();
@@ -699,11 +699,11 @@ void ELFSymbolTable<ELFT>::write(ELFWrit
   }
 }
 
-template <class ELFT> class ELFRelocationTable : public Section<ELFT> {
+template <class ELFT> class RelocationTable : public Section<ELFT> {
 public:
   typedef llvm::object::Elf_Rel_Impl<ELFT, true> Elf_Rela;
 
-  ELFRelocationTable(const ELFTargetInfo &ti, StringRef str, int32_t order)
+  RelocationTable(const ELFTargetInfo &ti, StringRef str, int32_t order)
       : Section<ELFT>(ti, str, llvm::ELF::SHT_RELA, DefinedAtom::permR__, order,
                       Section<ELFT>::K_Default) {
     this->setOrder(order);
@@ -738,8 +738,7 @@ public:
 private:
   std::vector<std::pair<const DefinedAtom &, const Reference &>> _relocs;
 };
+} // end namespace elf
+} // end namespace lld
 
-} // elf
-} // lld
-
-#endif //LLD_READER_WRITER_ELF_SECTION_CHUNKS_H_
+#endif

Copied: lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.h (from r173824, lld/trunk/lib/ReaderWriter/ELF/ELFSegmentChunks.h)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.h?p2=lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.h&p1=lld/trunk/lib/ReaderWriter/ELF/ELFSegmentChunks.h&r1=173824&r2=173838&rev=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFSegmentChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.h Tue Jan 29 16:03:39 2013
@@ -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 ELFT>
 class SegmentSlice {
 public:
@@ -110,7 +109,7 @@ public:
   typedef typename std::vector<Chunk<ELFT> *>::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<ELFT> *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<Chunk<ELFT> *> _sections;
   std::vector<SegmentSlice<ELFT> *> _segmentSlices;
-  ELFLayout::SegmentType _segmentType;
+  Layout::SegmentType _segmentType;
   int64_t _flags;
   int64_t _atomflags;
   llvm::BumpPtrAllocator _segmentAllocate;
@@ -197,7 +196,7 @@ protected:
 
 template <class ELFT>
 Segment<ELFT>::Segment(const ELFTargetInfo &ti, const StringRef name,
-                       const ELFLayout::SegmentType type)
+                       const Layout::SegmentType type)
     : Chunk<ELFT>(name, Chunk<ELFT>::K_ELFSegment, ti), _segmentType(type),
       _flags(0), _atomflags(0) {
   this->_align2 = 0;
@@ -367,8 +366,7 @@ Segment<ELFT>::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

Copied: lld/trunk/lib/ReaderWriter/ELF/TargetHandler.h (from r173824, lld/trunk/lib/ReaderWriter/ELF/ELFTargetHandler.h)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/TargetHandler.h?p2=lld/trunk/lib/ReaderWriter/ELF/TargetHandler.h&p1=lld/trunk/lib/ReaderWriter/ELF/ELFTargetHandler.h&r1=173824&r2=173838&rev=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFTargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/TargetHandler.h Tue Jan 29 16:03:39 2013
@@ -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 <unordered_map>
 
 namespace lld {
-template <class ELFT> class ELFDefinedAtom;
 namespace elf {
-template <class ELFT> class ELFTargetLayout;
-template <class ELFT> class ELFHeader;
+template <class ELFT> class ELFDefinedAtom;
+template <class ELFT> class Header;
 template <class ELFT> class Section;
+template <class ELFT> 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 ELFT> class ELFTargetAtomHandler {
+template <class ELFT> class TargetAtomHandler {
 public:
   typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym;
 
   virtual DefinedAtom::ContentType contentType(
-      const lld::ELFDefinedAtom<ELFT> *atom) const {
+      const ELFDefinedAtom<ELFT> *atom) const {
     return atom->contentType();
   }
 
@@ -52,17 +52,17 @@ public:
   }
 
   virtual DefinedAtom::ContentPermissions contentPermissions(
-      const lld::ELFDefinedAtom<ELFT> *atom) const {
+      const ELFDefinedAtom<ELFT> *atom) const {
     return atom->permissions();
   }
 };
 
 /// \brief An interface to override functions that are provided by the 
 /// the default ELF Layout
-template <class ELFT> class ELFTargetHandler : public ELFTargetHandlerBase {
+template <class ELFT> 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<ELFT> *elfHeader) = 0;
+  virtual void setHeaderInfo(Header<ELFT> *Header) = 0;
 
-  /// ELFTargetLayout 
-  virtual ELFTargetLayout<ELFT> &targetLayout() = 0;
+  /// TargetLayout 
+  virtual TargetLayout<ELFT> &targetLayout() = 0;
 
-  /// ELFTargetAtomHandler
-  virtual ELFTargetAtomHandler<ELFT> &targetAtomHandler() = 0;
+  /// TargetAtomHandler
+  virtual TargetAtomHandler<ELFT> &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

Copied: lld/trunk/lib/ReaderWriter/ELF/TargetLayout.h (from r173824, lld/trunk/lib/ReaderWriter/ELF/ELFTargetLayout.h)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/TargetLayout.h?p2=lld/trunk/lib/ReaderWriter/ELF/TargetLayout.h&p1=lld/trunk/lib/ReaderWriter/ELF/ELFTargetLayout.h&r1=173824&r2=173838&rev=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFTargetLayout.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/TargetLayout.h Tue Jan 29 16:03:39 2013
@@ -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 ELFT> class ELFTargetLayout : public DefaultELFLayout<ELFT> {
+template <class ELFT> class TargetLayout : public DefaultLayout<ELFT> {
 public:
-  ELFTargetLayout(ELFTargetInfo &targetInfo)
+  TargetLayout(ELFTargetInfo &targetInfo)
       : DefaultELFLayout<ELFT>(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<ELFT> *section) const = 0;
+  virtual Layout::SegmentType segmentType(Section<ELFT> *section) const = 0;
 
   /// Returns true/false depending on whether the section has a Output
   //  segment or not

Copied: lld/trunk/lib/ReaderWriter/ELF/Targets.h (from r173824, lld/trunk/lib/ReaderWriter/ELF/ELFTargets.h)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Targets.h?p2=lld/trunk/lib/ReaderWriter/ELF/Targets.h&p1=lld/trunk/lib/ReaderWriter/ELF/ELFTargets.h&r1=173824&r2=173838&rev=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFTargets.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Targets.h Tue Jan 29 16:03:39 2013
@@ -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

Copied: lld/trunk/lib/ReaderWriter/ELF/Writer.cpp (from r173824, lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Writer.cpp?p2=lld/trunk/lib/ReaderWriter/ELF/Writer.cpp&p1=lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp&r1=173824&r2=173838&rev=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Writer.cpp Tue Jan 29 16:03:39 2013
@@ -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 ELFT>
-class ELFExecutableWriter;
+class ExecutableWriter;
 
 //===----------------------------------------------------------------------===//
-//  ELFExecutableWriter Class
+//  ExecutableWriter Class
 //===----------------------------------------------------------------------===//
 template<class ELFT>
-class ELFExecutableWriter : public ELFWriter {
+class ExecutableWriter : public ELFWriter {
 public:
   typedef Elf_Shdr_Impl<ELFT> Elf_Shdr;
   typedef Elf_Sym_Impl<ELFT> 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<KindHandler> _referenceKindHandler;
   AtomToAddress _atomToAddressMap;
   llvm::BumpPtrAllocator _chunkAllocate;
-  DefaultELFLayout<ELFT> *_layout;
-  ELFHeader<ELFT> *_elfHeader;
-  ELFProgramHeader<ELFT> *_programHeader;
-  ELFSymbolTable<ELFT> * _symtab;
-  ELFStringTable<ELFT> *_strtab;
-  ELFStringTable<ELFT> *_shstrtab;
-  ELFSectionHeader<ELFT> *_shdrtab;
-  CRuntimeFileELF<ELFT> _runtimeFile;
+  DefaultLayout<ELFT> *_layout;
+  Header<ELFT> *_Header;
+  ProgramHeader<ELFT> *_programHeader;
+  SymbolTable<ELFT> * _symtab;
+  StringTable<ELFT> *_strtab;
+  StringTable<ELFT> *_shstrtab;
+  SectionHeader<ELFT> *_shdrtab;
+  CRuntimeFile<ELFT> _runtimeFile;
 };
 
 //===----------------------------------------------------------------------===//
-//  ELFExecutableWriter
+//  ExecutableWriter
 //===----------------------------------------------------------------------===//
 template<class ELFT>
-ELFExecutableWriter<ELFT>::ELFExecutableWriter(const ELFTargetInfo &ti)
+ExecutableWriter<ELFT>::ExecutableWriter(const ELFTargetInfo &ti)
   : _targetInfo(ti)
   , _referenceKindHandler(KindHandler::makeHandler(
                               ti.getTriple().getArch(), ti.isLittleEndian()))
   , _runtimeFile(ti) {
-  _layout = new DefaultELFLayout<ELFT>(ti);
+  _layout = new DefaultLayout<ELFT>(ti);
 }
 
 template<class ELFT>
-void ELFExecutableWriter<ELFT>::buildChunks(const lld::File &file){
+void ExecutableWriter<ELFT>::buildChunks(const File &file){
   for (const DefinedAtom *definedAtom : file.defined() ) {
     _layout->addAtom(definedAtom);
   }
@@ -93,7 +93,7 @@ void ELFExecutableWriter<ELFT>::buildChu
 }
 
 template<class ELFT>
-void ELFExecutableWriter<ELFT>::buildSymbolTable () {
+void ExecutableWriter<ELFT>::buildSymbolTable () {
   for (auto sec : _layout->sections())
     if (auto section = dyn_cast<Section<ELFT>>(sec))
       for (const auto &atom : section->atoms())
@@ -102,7 +102,7 @@ void ELFExecutableWriter<ELFT>::buildSym
 
 template<class ELFT>
 void
-ELFExecutableWriter<ELFT>::addAbsoluteUndefinedSymbols(const lld::File &file) {
+ExecutableWriter<ELFT>::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<ELFT>::addAbsoluteUn
 }
 
 template<class ELFT>
-void ELFExecutableWriter<ELFT>::buildAtomToAddressMap () {
+void ExecutableWriter<ELFT>::buildAtomToAddressMap () {
   for (auto sec : _layout->sections())
     if (auto section = dyn_cast<Section<ELFT>>(sec))
       for (const auto &atom : section->atoms())
@@ -123,7 +123,7 @@ void ELFExecutableWriter<ELFT>::buildAto
 }
 
 template<class ELFT>
-void ELFExecutableWriter<ELFT>::buildSectionHeaderTable() {
+void ExecutableWriter<ELFT>::buildSectionHeaderTable() {
   for (auto mergedSec : _layout->mergedSections()) {
     if (mergedSec->kind() != Chunk<ELFT>::K_ELFSection)
       continue;
@@ -133,7 +133,7 @@ void ELFExecutableWriter<ELFT>::buildSec
 }
 
 template<class ELFT>
-void ELFExecutableWriter<ELFT>::assignSectionsWithNoSegments() {
+void ExecutableWriter<ELFT>::assignSectionsWithNoSegments() {
   for (auto mergedSec : _layout->mergedSections()) {
     if (mergedSec->kind() != Chunk<ELFT>::K_ELFSection)
       continue;
@@ -143,14 +143,14 @@ void ELFExecutableWriter<ELFT>::assignSe
   _layout->assignOffsetsForMiscSections();
   for (auto sec : _layout->sections())
     if (auto section = dyn_cast<Section<ELFT>>(sec))
-      if (!DefaultELFLayout<ELFT>::hasOutputSegment(section))
+      if (!DefaultLayout<ELFT>::hasOutputSegment(section))
         _shdrtab->updateSection(section);
 }
 
 /// \brief Add absolute symbols by default. These are linker added
 /// absolute symbols
 template<class ELFT>
-void ELFExecutableWriter<ELFT>::addDefaultAtoms() {
+void ExecutableWriter<ELFT>::addDefaultAtoms() {
   _runtimeFile.addUndefinedAtom(_targetInfo.getEntry());
   _runtimeFile.addAbsoluteAtom("__bss_start");
   _runtimeFile.addAbsoluteAtom("__bss_end");
@@ -164,7 +164,7 @@ void ELFExecutableWriter<ELFT>::addDefau
 
 /// \brief Hook in lld to add CRuntime file 
 template<class ELFT>
-void ELFExecutableWriter<ELFT>::addFiles(InputFiles &inputFiles) {
+void ExecutableWriter<ELFT>::addFiles(InputFiles &inputFiles) {
   addDefaultAtoms();
   inputFiles.prependFile(_runtimeFile);
 }
@@ -172,7 +172,7 @@ void ELFExecutableWriter<ELFT>::addFiles
 /// Finalize the value of all the absolute symbols that we 
 /// created
 template<class ELFT>
-void ELFExecutableWriter<ELFT>::finalizeDefaultAtomValues() {
+void ExecutableWriter<ELFT>::finalizeDefaultAtomValues() {
   auto bssStartAtomIter = _layout->findAbsoluteAtom("__bss_start");
   auto bssEndAtomIter = _layout->findAbsoluteAtom("__bss_end");
   auto underScoreEndAtomIter = _layout->findAbsoluteAtom("_end");
@@ -182,8 +182,8 @@ void ELFExecutableWriter<ELFT>::finalize
   auto realIpltStartIter = _layout->findAbsoluteAtom("__rela_iplt_start");
   auto realIpltEndIter = _layout->findAbsoluteAtom("__rela_iplt_end");
 
-  auto startEnd = [&](typename DefaultELFLayout<ELFT>::AbsoluteAtomIterT start,
-                      typename DefaultELFLayout<ELFT>::AbsoluteAtomIterT end,
+  auto startEnd = [&](typename DefaultLayout<ELFT>::AbsoluteAtomIterT start,
+                      typename DefaultLayout<ELFT>::AbsoluteAtomIterT end,
                       StringRef sec) -> void {
     auto section = _layout->findOutputSection(sec);
     if (section) {
@@ -218,7 +218,7 @@ void ELFExecutableWriter<ELFT>::finalize
 
 template<class ELFT>
 error_code
-ELFExecutableWriter<ELFT>::writeFile(const lld::File &file, StringRef path) {
+ExecutableWriter<ELFT>::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<ELFT>::writeFile(con
   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<ELFT>::writeFile(con
 }
 
 template<class ELFT>
-void ELFExecutableWriter<ELFT>::createDefaultSections() {
-  _elfHeader = new ELFHeader<ELFT>(_targetInfo);
-  _programHeader = new ELFProgramHeader<ELFT>(_targetInfo);
-  _layout->setELFHeader(_elfHeader);
+void ExecutableWriter<ELFT>::createDefaultSections() {
+  _Header = new Header<ELFT>(_targetInfo);
+  _programHeader = new ProgramHeader<ELFT>(_targetInfo);
+  _layout->setHeader(_Header);
   _layout->setProgramHeader(_programHeader);
 
-  _symtab = new ELFSymbolTable<
-      ELFT>(_targetInfo, ".symtab", DefaultELFLayout<ELFT>::ORDER_SYMBOL_TABLE);
-  _strtab = new ELFStringTable<
-      ELFT>(_targetInfo, ".strtab", DefaultELFLayout<ELFT>::ORDER_STRING_TABLE);
-  _shstrtab = new ELFStringTable<ELFT>(
-      _targetInfo, ".shstrtab", DefaultELFLayout<ELFT>::ORDER_SECTION_STRINGS);
-  _shdrtab = new ELFSectionHeader<
-      ELFT>(_targetInfo, DefaultELFLayout<ELFT>::ORDER_SECTION_HEADERS);
+  _symtab = new SymbolTable<
+      ELFT>(_targetInfo, ".symtab", DefaultLayout<ELFT>::ORDER_SYMBOL_TABLE);
+  _strtab = new StringTable<
+      ELFT>(_targetInfo, ".strtab", DefaultLayout<ELFT>::ORDER_STRING_TABLE);
+  _shstrtab = new StringTable<ELFT>(
+      _targetInfo, ".shstrtab", DefaultLayout<ELFT>::ORDER_SECTION_STRINGS);
+  _shdrtab = new SectionHeader<
+      ELFT>(_targetInfo, DefaultLayout<ELFT>::ORDER_SECTION_HEADERS);
   _layout->addSection(_symtab);
   _layout->addSection(_strtab);
   _layout->addSection(_shstrtab);
@@ -325,16 +325,16 @@ std::unique_ptr<Writer> createWriterELF(
 
   if (!TI.is64Bits() && TI.isLittleEndian())
     return std::unique_ptr<Writer>(new
-        elf::ELFExecutableWriter<ELFType<support::little, 4, false>>(TI));
+        elf::ExecutableWriter<ELFType<support::little, 4, false>>(TI));
   else if (TI.is64Bits() && TI.isLittleEndian())
     return std::unique_ptr<Writer>(new
-        elf::ELFExecutableWriter<ELFType<support::little, 8, true>>(TI));
+        elf::ExecutableWriter<ELFType<support::little, 8, true>>(TI));
   else if (!TI.is64Bits() && !TI.isLittleEndian())
     return std::unique_ptr<Writer>(new
-        elf::ELFExecutableWriter<ELFType<support::big, 4, false>>(TI));
+        elf::ExecutableWriter<ELFType<support::big, 4, false>>(TI));
   else if (TI.is64Bits() && !TI.isLittleEndian())
     return std::unique_ptr<Writer>(new
-        elf::ELFExecutableWriter<ELFType<support::big, 8, true>>(TI));
+        elf::ExecutableWriter<ELFType<support::big, 8, true>>(TI));
 
   llvm_unreachable("Invalid Options!");
 }

Copied: lld/trunk/lib/ReaderWriter/ELF/Writer.h (from r173824, lld/trunk/lib/ReaderWriter/ELF/ELFWriter.h)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Writer.h?p2=lld/trunk/lib/ReaderWriter/ELF/Writer.h&p1=lld/trunk/lib/ReaderWriter/ELF/ELFWriter.h&r1=173824&r2=173838&rev=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Writer.h Tue Jan 29 16:03:39 2013
@@ -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

Removed: lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp?rev=173837&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp (removed)
@@ -1,341 +0,0 @@
-//===- lib/ReaderWriter/ELF/WriterELF.cpp ---------------------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "lld/ReaderWriter/Writer.h"
-
-#include "DefaultELFLayout.h"
-#include "ExecutableAtoms.h"
-
-#include "lld/ReaderWriter/ELFTargetInfo.h"
-
-using namespace llvm;
-using namespace llvm::object;
-namespace lld {
-namespace elf {
-template<class ELFT>
-class ELFExecutableWriter;
-
-//===----------------------------------------------------------------------===//
-//  ELFExecutableWriter Class
-//===----------------------------------------------------------------------===//
-template<class ELFT>
-class ELFExecutableWriter : public ELFWriter {
-public:
-  typedef Elf_Shdr_Impl<ELFT> Elf_Shdr;
-  typedef Elf_Sym_Impl<ELFT> Elf_Sym;
-
-  ELFExecutableWriter(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 buildAtomToAddressMap();
-  void buildSymbolTable ();
-  void buildSectionHeaderTable();
-  void assignSectionsWithNoSegments();
-  void addAbsoluteUndefinedSymbols(const lld::File &File);
-  void addDefaultAtoms();
-  void addFiles(InputFiles&);
-  void finalizeDefaultAtomValues();
-
-  uint64_t addressOfAtom(const Atom *atom) {
-    return _atomToAddressMap[atom];
-  }
-
-  KindHandler *kindHandler() { return _referenceKindHandler.get(); }
-
-  void createDefaultSections();
-
-  const ELFTargetInfo &_targetInfo;
-
-  typedef llvm::DenseMap<const Atom*, uint64_t> AtomToAddress;
-  std::unique_ptr<KindHandler> _referenceKindHandler;
-  AtomToAddress _atomToAddressMap;
-  llvm::BumpPtrAllocator _chunkAllocate;
-  DefaultELFLayout<ELFT> *_layout;
-  ELFHeader<ELFT> *_elfHeader;
-  ELFProgramHeader<ELFT> *_programHeader;
-  ELFSymbolTable<ELFT> * _symtab;
-  ELFStringTable<ELFT> *_strtab;
-  ELFStringTable<ELFT> *_shstrtab;
-  ELFSectionHeader<ELFT> *_shdrtab;
-  CRuntimeFileELF<ELFT> _runtimeFile;
-};
-
-//===----------------------------------------------------------------------===//
-//  ELFExecutableWriter
-//===----------------------------------------------------------------------===//
-template<class ELFT>
-ELFExecutableWriter<ELFT>::ELFExecutableWriter(const ELFTargetInfo &ti)
-  : _targetInfo(ti)
-  , _referenceKindHandler(KindHandler::makeHandler(
-                              ti.getTriple().getArch(), ti.isLittleEndian()))
-  , _runtimeFile(ti) {
-  _layout = new DefaultELFLayout<ELFT>(ti);
-}
-
-template<class ELFT>
-void ELFExecutableWriter<ELFT>::buildChunks(const lld::File &file){
-  for (const DefinedAtom *definedAtom : file.defined() ) {
-    _layout->addAtom(definedAtom);
-  }
-  /// Add all the absolute atoms to the layout
-  for (const AbsoluteAtom *absoluteAtom : file.absolute()) {
-    _layout->addAtom(absoluteAtom);
-  }
-}
-
-template<class ELFT>
-void ELFExecutableWriter<ELFT>::buildSymbolTable () {
-  for (auto sec : _layout->sections())
-    if (auto section = dyn_cast<Section<ELFT>>(sec))
-      for (const auto &atom : section->atoms())
-        _symtab->addSymbol(atom._atom, section->ordinal(), atom._virtualAddr);
-}
-
-template<class ELFT>
-void
-ELFExecutableWriter<ELFT>::addAbsoluteUndefinedSymbols(const lld::File &file) {
-  // add all the absolute symbols that the layout contains to the output symbol
-  // table
-  for (auto &atom : _layout->absoluteAtoms())
-    _symtab->addSymbol(atom.absoluteAtom(), ELF::SHN_ABS, atom.value());
-  for (const UndefinedAtom *a : file.undefined())
-    _symtab->addSymbol(a, ELF::SHN_UNDEF);
-}
-
-template<class ELFT>
-void ELFExecutableWriter<ELFT>::buildAtomToAddressMap () {
-  for (auto sec : _layout->sections())
-    if (auto section = dyn_cast<Section<ELFT>>(sec))
-      for (const auto &atom : section->atoms())
-        _atomToAddressMap[atom._atom] = atom._virtualAddr;
-  // build the atomToAddressMap that contains absolute symbols too
-  for (auto &atom : _layout->absoluteAtoms())
-    _atomToAddressMap[atom.absoluteAtom()] = atom.value();
-}
-
-template<class ELFT>
-void ELFExecutableWriter<ELFT>::buildSectionHeaderTable() {
-  for (auto mergedSec : _layout->mergedSections()) {
-    if (mergedSec->kind() != Chunk<ELFT>::K_ELFSection)
-      continue;
-    if (mergedSec->hasSegment())
-      _shdrtab->appendSection(mergedSec);
-  }
-}
-
-template<class ELFT>
-void ELFExecutableWriter<ELFT>::assignSectionsWithNoSegments() {
-  for (auto mergedSec : _layout->mergedSections()) {
-    if (mergedSec->kind() != Chunk<ELFT>::K_ELFSection)
-      continue;
-    if (!mergedSec->hasSegment())
-      _shdrtab->appendSection(mergedSec);
-  }
-  _layout->assignOffsetsForMiscSections();
-  for (auto sec : _layout->sections())
-    if (auto section = dyn_cast<Section<ELFT>>(sec))
-      if (!DefaultELFLayout<ELFT>::hasOutputSegment(section))
-        _shdrtab->updateSection(section);
-}
-
-/// \brief Add absolute symbols by default. These are linker added
-/// absolute symbols
-template<class ELFT>
-void ELFExecutableWriter<ELFT>::addDefaultAtoms() {
-  _runtimeFile.addUndefinedAtom(_targetInfo.getEntry());
-  _runtimeFile.addAbsoluteAtom("__bss_start");
-  _runtimeFile.addAbsoluteAtom("__bss_end");
-  _runtimeFile.addAbsoluteAtom("_end");
-  _runtimeFile.addAbsoluteAtom("end");
-  _runtimeFile.addAbsoluteAtom("__init_array_start");
-  _runtimeFile.addAbsoluteAtom("__init_array_end");
-  _runtimeFile.addAbsoluteAtom("__rela_iplt_start");
-  _runtimeFile.addAbsoluteAtom("__rela_iplt_end");
-}
-
-/// \brief Hook in lld to add CRuntime file 
-template<class ELFT>
-void ELFExecutableWriter<ELFT>::addFiles(InputFiles &inputFiles) {
-  addDefaultAtoms();
-  inputFiles.prependFile(_runtimeFile);
-}
-
-/// Finalize the value of all the absolute symbols that we 
-/// created
-template<class ELFT>
-void ELFExecutableWriter<ELFT>::finalizeDefaultAtomValues() {
-  auto bssStartAtomIter = _layout->findAbsoluteAtom("__bss_start");
-  auto bssEndAtomIter = _layout->findAbsoluteAtom("__bss_end");
-  auto underScoreEndAtomIter = _layout->findAbsoluteAtom("_end");
-  auto endAtomIter = _layout->findAbsoluteAtom("end");
-  auto initArrayStartIter = _layout->findAbsoluteAtom("__init_array_start");
-  auto initArrayEndIter = _layout->findAbsoluteAtom("__init_array_end");
-  auto realIpltStartIter = _layout->findAbsoluteAtom("__rela_iplt_start");
-  auto realIpltEndIter = _layout->findAbsoluteAtom("__rela_iplt_end");
-
-  auto startEnd = [&](typename DefaultELFLayout<ELFT>::AbsoluteAtomIterT start,
-                      typename DefaultELFLayout<ELFT>::AbsoluteAtomIterT end,
-                      StringRef sec) -> void {
-    auto section = _layout->findOutputSection(sec);
-    if (section) {
-      start->setValue(section->virtualAddr());
-      end->setValue(section->virtualAddr() + section->memSize());
-    } else {
-      start->setValue(0);
-      end->setValue(0);
-    }
-  };
-
-  startEnd(initArrayStartIter, initArrayEndIter, ".init_array");
-  startEnd(realIpltStartIter, realIpltEndIter, ".rela.plt");
-
-  assert(!(bssStartAtomIter == _layout->absoluteAtoms().end() ||
-           bssEndAtomIter == _layout->absoluteAtoms().end() ||
-           underScoreEndAtomIter == _layout->absoluteAtoms().end() ||
-           endAtomIter == _layout->absoluteAtoms().end()) &&
-         "Unable to find the absolute atoms that have been added by lld");
-
-  auto phe = _programHeader->findProgramHeader(
-      llvm::ELF::PT_LOAD, llvm::ELF::PF_W, llvm::ELF::PF_X);
-
-  assert(!(phe == _programHeader->end()) &&
-         "Can't find a data segment in the program header!");
-
-  bssStartAtomIter->setValue((*phe)->p_vaddr + (*phe)->p_filesz);
-  bssEndAtomIter->setValue((*phe)->p_vaddr + (*phe)->p_memsz);
-  underScoreEndAtomIter->setValue((*phe)->p_vaddr + (*phe)->p_memsz);
-  endAtomIter->setValue((*phe)->p_vaddr + (*phe)->p_memsz);
-}
-
-template<class ELFT>
-error_code
-ELFExecutableWriter<ELFT>::writeFile(const lld::File &file, StringRef path) {
-  buildChunks(file);
-  // Create the default sections like the symbol table, string table, and the
-  // section string table
-  createDefaultSections();
-
-  // Set the Layout
-  _layout->assignSectionsToSegments();
-  _layout->assignFileOffsets();
-  _layout->assignVirtualAddress();
-
-  // Finalize the default value of symbols that the linker adds
-  finalizeDefaultAtomValues();
-
-  // Build the Atom To Address map for applying relocations
-  buildAtomToAddressMap();
-
-  // Create symbol table and section string table
-  buildSymbolTable();
-
-  // add other symbols
-  addAbsoluteUndefinedSymbols(file);
-
-  // Finalize the layout by calling the finalize() functions
-  _layout->finalize();
-
-  // build Section Header table
-  buildSectionHeaderTable();
-
-  // assign Offsets and virtual addresses
-  // for sections with no segments
-  assignSectionsWithNoSegments();
-
-  uint64_t totalSize = _shdrtab->fileOffset() + _shdrtab->fileSize();
-
-  OwningPtr<FileOutputBuffer> buffer;
-  error_code ec = FileOutputBuffer::create(path,
-                                           totalSize, buffer,
-                                           FileOutputBuffer::F_executable);
-  if (ec)
-    return ec;
-
-  _elfHeader->e_ident(ELF::EI_CLASS, _targetInfo.is64Bits() ? ELF::ELFCLASS64
-                                                            : ELF::ELFCLASS32);
-  _elfHeader->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());
-  uint64_t virtualAddr = 0;
-  _layout->findAtomAddrByName(_targetInfo.getEntry(), virtualAddr);
-  _elfHeader->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);
-  _programHeader->write(this, *buffer);
-
-  for (auto section : _layout->sections())
-    section->write(this, *buffer);
-
-  return buffer->commit();
-}
-
-template<class ELFT>
-void ELFExecutableWriter<ELFT>::createDefaultSections() {
-  _elfHeader = new ELFHeader<ELFT>(_targetInfo);
-  _programHeader = new ELFProgramHeader<ELFT>(_targetInfo);
-  _layout->setELFHeader(_elfHeader);
-  _layout->setProgramHeader(_programHeader);
-
-  _symtab = new ELFSymbolTable<
-      ELFT>(_targetInfo, ".symtab", DefaultELFLayout<ELFT>::ORDER_SYMBOL_TABLE);
-  _strtab = new ELFStringTable<
-      ELFT>(_targetInfo, ".strtab", DefaultELFLayout<ELFT>::ORDER_STRING_TABLE);
-  _shstrtab = new ELFStringTable<ELFT>(
-      _targetInfo, ".shstrtab", DefaultELFLayout<ELFT>::ORDER_SECTION_STRINGS);
-  _shdrtab = new ELFSectionHeader<
-      ELFT>(_targetInfo, DefaultELFLayout<ELFT>::ORDER_SECTION_HEADERS);
-  _layout->addSection(_symtab);
-  _layout->addSection(_strtab);
-  _layout->addSection(_shstrtab);
-  _shdrtab->setStringSection(_shstrtab);
-  _symtab->setStringSection(_strtab);
-  _layout->addSection(_shdrtab);
-}
-} // namespace elf
-
-std::unique_ptr<Writer> createWriterELF(const ELFTargetInfo &TI) {
-  using llvm::object::ELFType;
-  // Set the default layout to be the static executable layout
-  // We would set the layout to a dynamic executable layout
-  // if we came across any shared libraries in the process
-
-  if (!TI.is64Bits() && TI.isLittleEndian())
-    return std::unique_ptr<Writer>(new
-        elf::ELFExecutableWriter<ELFType<support::little, 4, false>>(TI));
-  else if (TI.is64Bits() && TI.isLittleEndian())
-    return std::unique_ptr<Writer>(new
-        elf::ELFExecutableWriter<ELFType<support::little, 8, true>>(TI));
-  else if (!TI.is64Bits() && !TI.isLittleEndian())
-    return std::unique_ptr<Writer>(new
-        elf::ELFExecutableWriter<ELFType<support::big, 4, false>>(TI));
-  else if (TI.is64Bits() && !TI.isLittleEndian())
-    return std::unique_ptr<Writer>(new
-        elf::ELFExecutableWriter<ELFType<support::big, 8, true>>(TI));
-
-  llvm_unreachable("Invalid Options!");
-}
-} // namespace lld

Removed: lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTarget.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTarget.h?rev=173837&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTarget.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTarget.h (removed)
@@ -1,9 +0,0 @@
-//===- lib/ReaderWriter/ELF/Hexagon/X86ELFTarget.h -----------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#include "X86ELFTargetInfo.h"

Removed: lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTargetInfo.h?rev=173837&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTargetInfo.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTargetInfo.h (removed)
@@ -1,34 +0,0 @@
-//===- lib/ReaderWriter/ELF/Hexagon/X86TargetInfo.h -----------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_READER_WRITER_ELF_X86_TARGETINFO_H
-#define LLD_READER_WRITER_ELF_X86_TARGETINFO_H
-
-#include "lld/ReaderWriter/ELFTargetInfo.h"
-#include "lld/Core/LinkerOptions.h"
-#include "llvm/Object/ELF.h"
-#include "llvm/Support/ELF.h"
-
-#include "DefaultELFTargetHandler.h"
-
-namespace lld {
-namespace elf {
-class X86ELFTargetInfo LLVM_FINAL : public ELFTargetInfo {
-public:
-  X86ELFTargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) {
-    _targetHandler = std::unique_ptr<ELFTargetHandlerBase>(
-        new DefaultELFTargetHandler<llvm::object::ELFType<llvm::support::little,
-                                                          4, false> >(*this));
-  }
-
-  virtual uint64_t getPageSize() const { return 0x1000; }
-};
-}      // elf
-}      // lld
-#endif // LLD_READER_WRITER_ELF_X86_TARGETINFO_H

Copied: lld/trunk/lib/ReaderWriter/ELF/X86/X86Target.h (from r173824, lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTarget.h)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86/X86Target.h?p2=lld/trunk/lib/ReaderWriter/ELF/X86/X86Target.h&p1=lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTarget.h&r1=173824&r2=173838&rev=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTarget.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86/X86Target.h Tue Jan 29 16:03:39 2013
@@ -1,4 +1,4 @@
-//===- lib/ReaderWriter/ELF/PPC/PPCELFTarget.h ---------------------------===//
+//===- lib/ReaderWriter/ELF/X86/X86Target.h -------------------------------===//
 //
 //                             The LLVM Linker
 //
@@ -6,4 +6,5 @@
 // License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
-#include "PPCELFTargetInfo.h"
+
+#include "X86TargetInfo.h"

Copied: lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetInfo.h (from r173824, lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTargetInfo.h)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetInfo.h?p2=lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetInfo.h&p1=lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTargetInfo.h&r1=173824&r2=173838&rev=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTargetInfo.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetInfo.h Tue Jan 29 16:03:39 2013
@@ -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<ELFTargetHandlerBase>(
-        new DefaultELFTargetHandler<llvm::object::ELFType<llvm::support::little,
+  X86TargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) {
+    _targetHandler = std::unique_ptr<TargetHandlerBase>(
+        new DefaultTargetHandler<llvm::object::ELFType<llvm::support::little,
                                                           4, false> >(*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

Removed: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTarget.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTarget.h?rev=173837&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTarget.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTarget.h (removed)
@@ -1,10 +0,0 @@
-//===- lib/ReaderWriter/ELF/Hexagon/X86ELFTarget.h -----------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "X86_64ELFTargetInfo.h"

Removed: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTargetInfo.h?rev=173837&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTargetInfo.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTargetInfo.h (removed)
@@ -1,53 +0,0 @@
-//===- lib/ReaderWriter/ELF/Hexagon/X86_64TargetInfo.h -----------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_READER_WRITER_ELF_X86_64_TARGETINFO_H
-#define LLD_READER_WRITER_ELF_X86_64_TARGETINFO_H
-
-#include "DefaultELFTargetHandler.h"
-
-#include "lld/Core/LinkerOptions.h"
-#include "lld/ReaderWriter/ELFTargetInfo.h"
-
-#include "llvm/Object/ELF.h"
-#include "llvm/Support/ELF.h"
-
-namespace lld {
-namespace elf {
-class X86_64ELFTargetInfo LLVM_FINAL : public ELFTargetInfo {
-public:
-  X86_64ELFTargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) {
-    _targetHandler = std::unique_ptr<ELFTargetHandlerBase>(
-        new DefaultELFTargetHandler<llvm::object::ELFType<llvm::support::little,
-                                                          8, false> >(*this));
-  }
-
-  virtual uint64_t getPageSize() const { return 0x1000; }
-
-  virtual void addPasses(PassManager &) const;
-
-  virtual uint64_t getBaseAddress() const {
-    if (_options._baseAddress == 0)
-      return 0x400000;
-    return _options._baseAddress;
-  }
-
-  virtual bool isRuntimeRelocation(const DefinedAtom &,
-                                   const Reference &r) const {
-    return r.kind() == llvm::ELF::R_X86_64_IRELATIVE;
-  }
-
-  virtual ErrorOr<int32_t> relocKindFromString(StringRef str) const;
-  virtual ErrorOr<std::string> stringFromRelocKind(int32_t kind) const;
-
-};
-} // elf
-} // lld
-
-#endif // LLD_READER_WRITER_ELF_X86_64_TARGETINFO_H

Copied: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64Target.h (from r173824, lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTarget.h)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64Target.h?p2=lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64Target.h&p1=lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTarget.h&r1=173824&r2=173838&rev=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTarget.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64Target.h Tue Jan 29 16:03:39 2013
@@ -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"

Modified: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp?rev=173838&r1=173837&r2=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp Tue Jan 29 16:03:39 2013
@@ -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<Pass>(new PLTPass(*this)));
 }
 
 #define LLD_CASE(name) .Case(#name, llvm::ELF::name)
 
-ErrorOr<int32_t> elf::X86_64ELFTargetInfo::relocKindFromString(StringRef str) const {
+ErrorOr<int32_t> elf::X86_64TargetInfo::relocKindFromString(
+    StringRef str) const {
   int32_t ret = llvm::StringSwitch<int32_t>(str)
     LLD_CASE(R_X86_64_NONE)
     LLD_CASE(R_X86_64_64)
@@ -185,7 +186,8 @@ ErrorOr<int32_t> elf::X86_64ELFTargetInf
 
 #define LLD_CASE(name) case llvm::ELF::name: return std::string(#name);
 
-ErrorOr<std::string> elf::X86_64ELFTargetInfo::stringFromRelocKind(int32_t kind) const {
+ErrorOr<std::string> elf::X86_64TargetInfo::stringFromRelocKind(
+    int32_t kind) const {
   switch (kind) {
   LLD_CASE(R_X86_64_NONE)
   LLD_CASE(R_X86_64_64)

Copied: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.h (from r173824, lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTargetInfo.h)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.h?p2=lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.h&p1=lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTargetInfo.h&r1=173824&r2=173838&rev=173838&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTargetInfo.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.h Tue Jan 29 16:03:39 2013
@@ -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<ELFTargetHandlerBase>(
-        new DefaultELFTargetHandler<llvm::object::ELFType<llvm::support::little,
+  X86_64TargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) {
+    _targetHandler = std::unique_ptr<TargetHandlerBase>(
+        new DefaultTargetHandler<llvm::object::ELFType<llvm::support::little,
                                                           8, false> >(*this));
   }
 





More information about the llvm-commits mailing list