[llvm-commits] [lld] r173430 - in /lld/trunk: include/lld/Core/ include/lld/ReaderWriter/ lib/Driver/ lib/ReaderWriter/ lib/ReaderWriter/ELF/ lib/ReaderWriter/ELF/Hexagon/ lib/ReaderWriter/ELF/PPC/ lib/ReaderWriter/ELF/X86/ lib/ReaderWriter/ELF/X86_64/ lib/ReaderWriter/MachO/ lib/ReaderWriter/Native/ lib/ReaderWriter/PECOFF/ lib/ReaderWriter/YAML/ tools/lld-core/

Shankar Easwaran shankare at codeaurora.org
Thu Jan 24 23:39:18 PST 2013


Author: shankare
Date: Fri Jan 25 01:39:18 2013
New Revision: 173430

URL: http://llvm.org/viewvc/llvm-project?rev=173430&view=rev
Log:
add elf targethandler

Added:
    lld/trunk/lib/ReaderWriter/ELF/DefaultELFTargetHandler.h
    lld/trunk/lib/ReaderWriter/ELF/ELFTargetHandler.h
    lld/trunk/lib/ReaderWriter/ELF/ELFTargets.h
    lld/trunk/lib/ReaderWriter/ELF/FileELF.h
    lld/trunk/lib/ReaderWriter/ELF/Hexagon/
    lld/trunk/lib/ReaderWriter/ELF/Hexagon/CMakeLists.txt
    lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTarget.h
    lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTargetInfo.h
    lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.cpp
    lld/trunk/lib/ReaderWriter/ELF/PPC/
    lld/trunk/lib/ReaderWriter/ELF/PPC/CMakeLists.txt
    lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTarget.h
    lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTargetInfo.h
    lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetInfo.cpp
    lld/trunk/lib/ReaderWriter/ELF/X86/
    lld/trunk/lib/ReaderWriter/ELF/X86/CMakeLists.txt
    lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTarget.h
    lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTargetInfo.h
    lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetInfo.cpp
    lld/trunk/lib/ReaderWriter/ELF/X86_64/
    lld/trunk/lib/ReaderWriter/ELF/X86_64/CMakeLists.txt
    lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTarget.h
    lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTargetInfo.h
    lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.cpp
Modified:
    lld/trunk/include/lld/Core/ArchiveLibraryFile.h
    lld/trunk/include/lld/Core/File.h
    lld/trunk/include/lld/Core/Resolver.h
    lld/trunk/include/lld/Core/SharedLibraryFile.h
    lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h
    lld/trunk/include/lld/ReaderWriter/Reader.h
    lld/trunk/include/lld/ReaderWriter/Simple.h
    lld/trunk/lib/Driver/Targets.cpp
    lld/trunk/lib/ReaderWriter/ELF/AtomsELF.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/ReaderELF.cpp
    lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp
    lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp
    lld/trunk/lib/ReaderWriter/MachO/StubsPass.hpp
    lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp
    lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
    lld/trunk/lib/ReaderWriter/ReaderArchive.cpp
    lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
    lld/trunk/tools/lld-core/TestingHelpers.hpp
    lld/trunk/tools/lld-core/lld-core.cpp

Modified: lld/trunk/include/lld/Core/ArchiveLibraryFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/ArchiveLibraryFile.h?rev=173430&r1=173429&r2=173430&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/ArchiveLibraryFile.h (original)
+++ lld/trunk/include/lld/Core/ArchiveLibraryFile.h Fri Jan 25 01:39:18 2013
@@ -39,9 +39,16 @@
   /// specified name and return the File object for that member, or nullptr.
   virtual const File *find(StringRef name, bool dataSymbolOnly) const = 0;
 
+  virtual const TargetInfo &getTargetInfo() const { return _targetInfo; }
+
 protected:
   /// only subclasses of ArchiveLibraryFile can be instantiated 
-  ArchiveLibraryFile(StringRef path) : File(path) { }
+  ArchiveLibraryFile(const TargetInfo &ti, StringRef path)
+      : File(path), _targetInfo(ti) {
+  }
+
+private:
+  const TargetInfo &_targetInfo;
 };
 
 } // namespace lld

Modified: lld/trunk/include/lld/Core/File.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/File.h?rev=173430&r1=173429&r2=173430&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/File.h (original)
+++ lld/trunk/include/lld/Core/File.h Fri Jan 25 01:39:18 2013
@@ -14,6 +14,7 @@
 #include "lld/Core/DefinedAtom.h"
 #include "lld/Core/range.h"
 #include "lld/Core/SharedLibraryAtom.h"
+#include "lld/Core/TargetInfo.h"
 #include "lld/Core/UndefinedAtom.h"
 
 #include "llvm/ADT/StringRef.h"
@@ -152,11 +153,12 @@
   /// all AbsoluteAtoms in this File.
   virtual const atom_collection<AbsoluteAtom> &absolute() const = 0;
 
+  virtual const TargetInfo &getTargetInfo() const = 0;
+
 protected:
   /// \brief only subclasses of File can be instantiated 
   File(StringRef p) : _path(p), _ordinal(UINT64_MAX) {}
 
-
   /// \brief This is a convenience class for File subclasses which manage their
   /// atoms as a simple std::vector<>.
   template <typename T>
@@ -217,14 +219,18 @@
   /// \brief Add an atom to the file. Invalidates iterators for all returned
   /// containters.
   virtual void addAtom(const Atom&) = 0;
-  
-  typedef range<std::vector<const DefinedAtom*>::iterator>  DefinedAtomRange;
+
+  typedef range<std::vector<const DefinedAtom *>::iterator> DefinedAtomRange;
   virtual DefinedAtomRange definedAtoms() = 0;
-  
+
+  virtual const TargetInfo &getTargetInfo() const { return _targetInfo; }
 
 protected:
   /// \brief only subclasses of MutableFile can be instantiated 
-  MutableFile(StringRef p) : File(p) {}
+  MutableFile(const TargetInfo &ti, StringRef p) : File(p), _targetInfo(ti) {}
+
+private:
+  const TargetInfo &_targetInfo;
 };
 } // end namespace lld
 

Modified: lld/trunk/include/lld/Core/Resolver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Resolver.h?rev=173430&r1=173429&r2=173430&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Resolver.h (original)
+++ lld/trunk/include/lld/Core/Resolver.h Fri Jan 25 01:39:18 2013
@@ -29,12 +29,10 @@
 class Resolver : public InputFiles::Handler {
 public:
   Resolver(const TargetInfo &ti, const InputFiles &inputs)
-    : _targetInfo(ti)
-    , _inputFiles(inputs)
-    , _symbolTable(ti)
-    , _haveLLVMObjs(false)
-    , _addToFinalSection(false)
-    , _completedInitialObjectFiles(false) {}
+      : _targetInfo(ti), _inputFiles(inputs), _symbolTable(ti), _result(ti),
+        _haveLLVMObjs(false), _addToFinalSection(false),
+        _completedInitialObjectFiles(false) {
+  }
 
   // InputFiles::Handler methods
   virtual void doDefinedAtom(const class DefinedAtom&);
@@ -65,13 +63,12 @@
   void markLive(const Atom &atom);
   void addAtoms(const std::vector<const DefinedAtom *>&);
 
-
   class MergedFile : public MutableFile {
   public:
-    MergedFile() : MutableFile("<linker-internal>") { }
+    MergedFile(const TargetInfo &ti) : MutableFile(ti, "<linker-internal>") {}
 
-  virtual const atom_collection<DefinedAtom>& defined() const {
-    return _definedAtoms;
+    virtual const atom_collection<DefinedAtom> &defined() const {
+      return _definedAtoms;
   }
   virtual const atom_collection<UndefinedAtom>& undefined() const {
       return _undefinedAtoms;

Modified: lld/trunk/include/lld/Core/SharedLibraryFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/SharedLibraryFile.h?rev=173430&r1=173429&r2=173430&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/SharedLibraryFile.h (original)
+++ lld/trunk/include/lld/Core/SharedLibraryFile.h Fri Jan 25 01:39:18 2013
@@ -40,11 +40,16 @@
   /// Check if the shared library exports a symbol with the specified name.
   /// If so, return a SharedLibraryAtom which represents that exported
   /// symbol.  Otherwise return nullptr.
-  virtual const SharedLibraryAtom *exports(StringRef name, 
-                                          bool dataSymbolOnly) const;
+  virtual const SharedLibraryAtom *exports(StringRef name,
+                                           bool dataSymbolOnly) const;
 protected:
   /// only subclasses of SharedLibraryFile can be instantiated 
-  SharedLibraryFile(StringRef path) : File(path) { }
+  SharedLibraryFile(const TargetInfo &ti, StringRef path)
+      : File(path), _targetInfo(ti) {
+  }
+
+private:
+  const TargetInfo &_targetInfo;
 };
 
 } // namespace lld

Modified: lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h?rev=173430&r1=173429&r2=173430&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h (original)
+++ lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h Fri Jan 25 01:39:18 2013
@@ -11,10 +11,20 @@
 #define LLD_READER_WRITER_ELF_TARGET_INFO_H
 
 #include "lld/Core/TargetInfo.h"
+#include "llvm/Object/ELF.h"
+#include "llvm/Support/ELF.h"
 
 #include <memory>
 
 namespace lld {
+
+namespace elf { template <typename ELFT> class ELFTargetHandler; }
+
+class ELFTargetHandlerBase {
+public:
+  virtual ~ELFTargetHandlerBase() {}
+};
+
 class ELFTargetInfo : public TargetInfo {
 protected:
   ELFTargetInfo(const LinkerOptions &lo) : TargetInfo(lo) {}
@@ -24,6 +34,15 @@
   uint16_t getOutputMachine() const;
 
   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());
+  }
+
+protected:
+  std::unique_ptr<ELFTargetHandlerBase> _targetHandler;
 };
 } // end namespace lld
 

Modified: lld/trunk/include/lld/ReaderWriter/Reader.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/Reader.h?rev=173430&r1=173429&r2=173430&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/Reader.h (original)
+++ lld/trunk/include/lld/ReaderWriter/Reader.h Fri Jan 25 01:39:18 2013
@@ -18,6 +18,7 @@
 #include <vector>
 
 namespace lld {
+class ELFTargetInfo;
 class File;
 class LinkerInput;
 struct LinkerOptions;
@@ -51,9 +52,9 @@
   const LinkerOptions &_options;
 };
 
-typedef ErrorOr<Reader&> ReaderFunc(const LinkerInput &);
+typedef ErrorOr<Reader &> ReaderFunc(const LinkerInput &);
 
-std::unique_ptr<Reader> createReaderELF(const TargetInfo &,
+std::unique_ptr<Reader> createReaderELF(const ELFTargetInfo &,
                                         std::function<ReaderFunc>);
 std::unique_ptr<Reader> createReaderMachO(const TargetInfo &,
                                           std::function<ReaderFunc>);

Modified: lld/trunk/include/lld/ReaderWriter/Simple.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/Simple.h?rev=173430&r1=173429&r2=173430&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/Simple.h (original)
+++ lld/trunk/include/lld/ReaderWriter/Simple.h Fri Jan 25 01:39:18 2013
@@ -23,7 +23,7 @@
 namespace lld {
 class SimpleFile : public MutableFile {
 public:
-  SimpleFile(StringRef path) : MutableFile(path) {}
+  SimpleFile(const TargetInfo &ti, StringRef path) : MutableFile(ti, path) {}
 
   virtual void addAtom(const Atom &atom) {
     if (const DefinedAtom *defAtom = dyn_cast<DefinedAtom>(&atom)) {

Modified: lld/trunk/lib/Driver/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/Targets.cpp?rev=173430&r1=173429&r2=173430&view=diff
==============================================================================
--- lld/trunk/lib/Driver/Targets.cpp (original)
+++ lld/trunk/lib/Driver/Targets.cpp Fri Jan 25 01:39:18 2013
@@ -33,12 +33,12 @@
 public:
   ELFTarget(std::unique_ptr<ELFTargetInfo> ti)
       : Target(std::unique_ptr<TargetInfo>(ti.get())),
-        _elfTargetInfo(*ti.release()),
-        _readerELF(createReaderELF(
-            *_targetInfo, std::bind(&ELFTarget::getReader, this, _1))),
+        _elfTargetInfo(*ti.release()), _readerELF(createReaderELF(
+            _elfTargetInfo, std::bind(&ELFTarget::getReader, this, _1))),
         _readerYAML(createReaderYAML(*_targetInfo)),
         _writer(createWriterELF(_elfTargetInfo)),
-        _writerYAML(createWriterYAML(*_targetInfo)) {}
+        _writerYAML(createWriterYAML(*_targetInfo)) {
+  }
 
   virtual ErrorOr<lld::Reader&> getReader(const LinkerInput &input) {
     auto kind = input.getKind();

Modified: lld/trunk/lib/ReaderWriter/ELF/AtomsELF.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/AtomsELF.h?rev=173430&r1=173429&r2=173430&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/AtomsELF.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/AtomsELF.h Fri Jan 25 01:39:18 2013
@@ -1,15 +1,20 @@
-#ifndef LLD_ELFATOMS_H_
-#define LLD_ELFATOMS_H_
+#ifndef LLD_ELFATOMS_H
+#define LLD_ELFATOMS_H
 
 #include "lld/Core/LLVM.h"
+#include "ELFTargetHandler.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 {
+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:
@@ -76,21 +81,14 @@
   typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym;
 
 public:
-  ELFAbsoluteAtom(const File &file,
-                  llvm::StringRef name,
-                  const Elf_Sym *symbol,
-                  uint64_t value)
-    : _owningFile(file)
-    , _name(name)
-    , _symbol(symbol)
-    , _value(value)
-  {}
-
-  virtual const class File &file() const {
-    return _owningFile;
+  ELFAbsoluteAtom(const FileELF<ELFT> &file, llvm::StringRef name,
+                  const Elf_Sym *symbol, uint64_t value)
+      : _owningFile(file), _name(name), _symbol(symbol), _value(value) {
   }
 
-  virtual Scope scope() const {
+  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)
@@ -108,7 +106,7 @@
   }
 
 private:
-  const File &_owningFile;
+  const FileELF<ELFT> &_owningFile;
   llvm::StringRef _name;
   const Elf_Sym *_symbol;
   uint64_t _value;
@@ -121,13 +119,9 @@
   typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym;
 
 public:
-  ELFUndefinedAtom(const File &file,
-                   llvm::StringRef name,
+  ELFUndefinedAtom(const FileELF<ELFT> &file, llvm::StringRef name,
                    const Elf_Sym *symbol)
-    : _owningFile(file)
-    , _name(name)
-    , _symbol(symbol)
-  {}
+      : _owningFile(file), _name(name), _symbol(symbol) {}
 
   virtual const class File &file() const {
     return _owningFile;
@@ -236,6 +230,17 @@
     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 =
+          static_cast<const ELFTargetInfo &>(_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;
 

Modified: lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt?rev=173430&r1=173429&r2=173430&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt (original)
+++ lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt Fri Jan 25 01:39:18 2013
@@ -1,3 +1,21 @@
+file(GLOB all_valid_subdirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*/CMakeLists.txt")
+
+foreach(dir ${all_valid_subdirs})
+    message(STATUS "AUTOADD ELFTarget = ${dir}")
+    if(${dir} MATCHES "^([^/]*)//CMakeLists.txt")
+        string(REGEX REPLACE "^([^/]*)//CMakeLists.txt" "\\1" dir_trimmed ${dir})
+        include_directories(AFTER 
+                            ${CMAKE_CURRENT_SOURCE_DIR}/${dir_trimmed})
+    endif()
+endforeach(dir)
+
+foreach(dir ${all_valid_subdirs})
+    if(${dir} MATCHES "^([^/]*)//CMakeLists.txt")
+        string(REGEX REPLACE "^([^/]*)//CMakeLists.txt" "\\1" dir_trimmed ${dir})
+        add_subdirectory(${dir_trimmed})
+    endif()
+endforeach(dir)
+
 add_lld_library(lldELF
   ELFTargetInfo.cpp
   HexagonReference.cpp

Added: lld/trunk/lib/ReaderWriter/ELF/DefaultELFTargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/DefaultELFTargetHandler.h?rev=173430&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/DefaultELFTargetHandler.h (added)
+++ lld/trunk/lib/ReaderWriter/ELF/DefaultELFTargetHandler.h Fri Jan 25 01:39:18 2013
@@ -0,0 +1,69 @@
+//===- 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 "lld/ReaderWriter/ELFTargetInfo.h"
+
+#include "lld/Core/LinkerOptions.h"
+
+#include "llvm/ADT/Triple.h"
+#include "llvm/Support/ELF.h"
+
+#include "DefaultELFLayout.h"
+#include "ELFTargetHandler.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

Added: lld/trunk/lib/ReaderWriter/ELF/ELFTargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFTargetHandler.h?rev=173430&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFTargetHandler.h (added)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFTargetHandler.h Fri Jan 25 01:39:18 2013
@@ -0,0 +1,142 @@
+//===- 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.
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLD_READER_WRITER_ELF_TARGETHANDLER_H
+#define LLD_READER_WRITER_ELF_TARGETHANDLER_H
+
+#include "lld/Core/LinkerOptions.h"
+#include "lld/Core/LLVM.h"
+#include "lld/Core/TargetInfo.h"
+#include "lld/ReaderWriter/ELFTargetInfo.h"
+#include "DefaultELFLayout.h"
+#include "AtomsELF.h"
+
+#include <memory>
+#include <vector>
+
+/// \brief All ELF targets would want to override the way the ELF file gets
+/// processed by the linker. This class serves as an interface which would be
+/// used to derive the needed functionality of a particular target/platform.
+
+/// \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 
+
+namespace lld {
+
+template <class ELFT> class ELFDefinedAtom;
+
+namespace elf {
+
+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 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> &layout)
+      : _targetInfo(targetInfo), _layout(layout) {
+  }
+
+  /// 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;
+
+private:
+  const ELFTargetInfo &_targetInfo;
+  const DefaultELFLayout<ELFT> &_layout;
+};
+
+/// \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) {}
+
+  /// 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;
+
+protected:
+  const ELFTargetInfo &_targetInfo;
+};
+
+} // 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=173430&r1=173429&r2=173430&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp Fri Jan 25 01:39:18 2013
@@ -14,6 +14,9 @@
 #include "llvm/ADT/Triple.h"
 #include "llvm/Support/ELF.h"
 
+#include "ELFTargetHandler.h"
+#include "ELFTargets.h"
+
 namespace lld {
 uint16_t ELFTargetInfo::getOutputType() const {
   switch (_options._outputKind) {
@@ -49,38 +52,18 @@
   }
 }
 
-class X86ELFTargetInfo LLVM_FINAL : public ELFTargetInfo {
-public:
-  X86ELFTargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) {}
-
-  virtual uint64_t getPageSize() const { return 0x1000; }
-};
-
-class HexagonELFTargetInfo LLVM_FINAL : public ELFTargetInfo {
-public:
-  HexagonELFTargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) {}
-
-  virtual uint64_t getPageSize() const { return 0x1000; }
-};
-
-class PPCELFTargetInfo LLVM_FINAL : public ELFTargetInfo {
-public:
-  PPCELFTargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) {}
-
-  virtual bool isLittleEndian() const { return false; }
-
-  virtual uint64_t getPageSize() const { return 0x1000; }
-};
-
 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));
   case llvm::Triple::x86_64:
-    return std::unique_ptr<ELFTargetInfo>(new X86ELFTargetInfo(lo));
+    return std::unique_ptr<
+        ELFTargetInfo>(new lld::elf::X86_64ELFTargetInfo(lo));
   case llvm::Triple::hexagon:
-    return std::unique_ptr<ELFTargetInfo>(new HexagonELFTargetInfo(lo));
+    return std::unique_ptr<
+        ELFTargetInfo>(new lld::elf::HexagonELFTargetInfo(lo));
   case llvm::Triple::ppc:
-    return std::unique_ptr<ELFTargetInfo>(new PPCELFTargetInfo(lo));
+    return std::unique_ptr<ELFTargetInfo>(new lld::elf::PPCELFTargetInfo(lo));
   default:
     return std::unique_ptr<ELFTargetInfo>();
   }

Added: lld/trunk/lib/ReaderWriter/ELF/ELFTargets.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFTargets.h?rev=173430&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFTargets.h (added)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFTargets.h Fri Jan 25 01:39:18 2013
@@ -0,0 +1,17 @@
+//===- 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 "X86ELFTarget.h"
+#include "X86_64ELFTarget.h"
+#include "HexagonELFTarget.h"
+#include "PPCELFTarget.h"
+
+#endif

Modified: lld/trunk/lib/ReaderWriter/ELF/ExecutableAtoms.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ExecutableAtoms.h?rev=173430&r1=173429&r2=173430&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ExecutableAtoms.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ExecutableAtoms.h Fri Jan 25 01:39:18 2013
@@ -10,13 +10,13 @@
 #ifndef LLD_READER_WRITER_ELF_EXECUTABLE_ATOM_H_
 #define LLD_READER_WRITER_ELF_EXECUTABLE_ATOM_H_
 
-
 #include "lld/Core/DefinedAtom.h"
-#include "lld/Core/UndefinedAtom.h"
 #include "lld/Core/File.h"
 #include "lld/Core/Reference.h"
+#include "lld/Core/UndefinedAtom.h"
 #include "lld/ReaderWriter/Writer.h"
 #include "AtomsELF.h"
+#include "FileELF.h"
 
 namespace lld {
 namespace elf {
@@ -26,12 +26,11 @@
 /// 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 CRuntimeFile : public File {
+template <class ELFT> class CRuntimeFileELF : public FileELF<ELFT> {
 public:
   typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym;
-  CRuntimeFile(const ELFTargetInfo &) : File("C runtime") {}
-  
+  CRuntimeFileELF(const ELFTargetInfo &ti) : FileELF<ELFT>(ti, "C runtime") {}
+
   /// \brief add a global absolute atom
   void addAbsoluteAtom(const StringRef symbolName) {
     Elf_Sym *symbol = new(_allocator.Allocate<Elf_Sym>()) Elf_Sym;
@@ -64,19 +63,19 @@
     _undefinedAtoms._atoms.push_back(newAtom);
   }
 
-  const atom_collection<DefinedAtom> &defined() const {
+  const File::atom_collection<DefinedAtom> &defined() const {
     return _definedAtoms;
   }
 
-  const atom_collection<UndefinedAtom> &undefined() const {
+  const File::atom_collection<UndefinedAtom> &undefined() const {
     return _undefinedAtoms;
   }
 
-  const atom_collection<SharedLibraryAtom> &sharedLibrary() const {
+  const File::atom_collection<SharedLibraryAtom> &sharedLibrary() const {
     return _sharedLibraryAtoms;
   }
 
-  const atom_collection<AbsoluteAtom> &absolute() const {
+  const File::atom_collection<AbsoluteAtom> &absolute() const {
     return _absoluteAtoms;
   }
 
@@ -87,10 +86,10 @@
 
 private:
   llvm::BumpPtrAllocator _allocator;
-  atom_collection_vector<DefinedAtom>       _definedAtoms;
-  atom_collection_vector<UndefinedAtom>     _undefinedAtoms;
-  atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
-  atom_collection_vector<AbsoluteAtom>      _absoluteAtoms;
+  File::atom_collection_vector<DefinedAtom> _definedAtoms;
+  File::atom_collection_vector<UndefinedAtom> _undefinedAtoms;
+  File::atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
+  File::atom_collection_vector<AbsoluteAtom> _absoluteAtoms;
 };
 
 } // namespace elf

Added: lld/trunk/lib/ReaderWriter/ELF/FileELF.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/FileELF.h?rev=173430&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/FileELF.h (added)
+++ lld/trunk/lib/ReaderWriter/ELF/FileELF.h Fri Jan 25 01:39:18 2013
@@ -0,0 +1,333 @@
+//===- 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 "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/ErrorOr.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/ELF.h"
+#include "llvm/Support/Endian.h"
+#include "llvm/Support/ErrorHandling.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 "AtomsELF.h"
+
+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) {
+    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<llvm::StringRef,
+           std::vector<const Elf_Rela *> > _relocationAddendRefences;
+  std::map<llvm::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 // LLD_READER_WRITER_FILE_ELF_H

Added: lld/trunk/lib/ReaderWriter/ELF/Hexagon/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/CMakeLists.txt?rev=173430&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/CMakeLists.txt (added)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/CMakeLists.txt Fri Jan 25 01:39:18 2013
@@ -0,0 +1,5 @@
+add_lld_library(lldHexagonELFTarget
+  HexagonTargetInfo.cpp
+  )
+
+target_link_libraries(lldHexagonELFTarget)

Added: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTarget.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTarget.h?rev=173430&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTarget.h (added)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTarget.h Fri Jan 25 01:39:18 2013
@@ -0,0 +1,9 @@
+//===- 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"

Added: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTargetInfo.h?rev=173430&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTargetInfo.h (added)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFTargetInfo.h Fri Jan 25 01:39:18 2013
@@ -0,0 +1,36 @@
+//===- 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

Added: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.cpp?rev=173430&view=auto
==============================================================================
    (empty)

Added: lld/trunk/lib/ReaderWriter/ELF/PPC/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/PPC/CMakeLists.txt?rev=173430&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/PPC/CMakeLists.txt (added)
+++ lld/trunk/lib/ReaderWriter/ELF/PPC/CMakeLists.txt Fri Jan 25 01:39:18 2013
@@ -0,0 +1,5 @@
+add_lld_library(lldPPCELFTarget
+  PPCTargetInfo.cpp
+  )
+
+target_link_libraries(lldPPCELFTarget)

Added: lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTarget.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTarget.h?rev=173430&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTarget.h (added)
+++ lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTarget.h Fri Jan 25 01:39:18 2013
@@ -0,0 +1,9 @@
+//===- 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"

Added: lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTargetInfo.h?rev=173430&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTargetInfo.h (added)
+++ lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFTargetInfo.h Fri Jan 25 01:39:18 2013
@@ -0,0 +1,38 @@
+//===- 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

Added: lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetInfo.cpp?rev=173430&view=auto
==============================================================================
    (empty)

Modified: lld/trunk/lib/ReaderWriter/ELF/ReaderELF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ReaderELF.cpp?rev=173430&r1=173429&r2=173430&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ReaderELF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ReaderELF.cpp Fri Jan 25 01:39:18 2013
@@ -15,7 +15,6 @@
 
 #include "lld/ReaderWriter/Reader.h"
 
-#include "lld/Core/File.h"
 #include "lld/Core/Reference.h"
 #include "lld/ReaderWriter/ELFTargetInfo.h"
 #include "lld/ReaderWriter/ReaderArchive.h"
@@ -39,6 +38,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/system_error.h"
 #include "AtomsELF.h"
+#include "FileELF.h"
 
 #include <map>
 #include <vector>
@@ -48,292 +48,16 @@
 using namespace llvm::object;
 
 namespace {
-/// \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 FileELF : public File {
-  typedef Elf_Sym_Impl<ELFT> Elf_Sym;
-  typedef Elf_Shdr_Impl<ELFT> Elf_Shdr;
-  typedef Elf_Rel_Impl<ELFT, false> Elf_Rel;
-  typedef Elf_Rel_Impl<ELFT, true> Elf_Rela;
-
-public:
-  FileELF(std::unique_ptr<llvm::MemoryBuffer> MB, llvm::error_code &EC)
-      : File(MB->getBufferIdentifier()) {
-    llvm::OwningPtr<Binary> binaryFile;
-    EC = createBinary(MB.release(), binaryFile);
-    if (EC)
-      return;
-
-    // Point Obj to correct class and bitwidth ELF object
-    _objFile.reset(llvm::dyn_cast<ELFObjectFile<ELFT>>(binaryFile.get()));
-
-    if (!_objFile) {
-      EC = make_error_code(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.
-    section_iterator sit(_objFile->begin_sections());
-    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.
-    symbol_iterator it(_objFile->begin_symbols());
-    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 = 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;
-
-        // 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;
-  }
-
-  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<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<llvm::StringRef,
-           std::vector<const Elf_Rela *>> _relocationAddendRefences;
-  std::map<llvm::StringRef,
-           std::vector<const Elf_Rel *>> _relocationReferences;
-  std::vector<ELFReference<ELFT> *> _references;
-  llvm::DenseMap<const Elf_Sym *, Atom *> _symbolToAtomMapping;
-  llvm::BumpPtrAllocator _readerStorage;
-};
-
 /// \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 TargetInfo & ti, std::function<ReaderFunc> read)
-      : Reader(ti),
-        _readerArchive(ti, read) {}
+  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) {
+                       std::vector<std::unique_ptr<File> > &result) {
     using llvm::object::ELFType;
     llvm::sys::LLVMFileType fileType =
         llvm::sys::IdentifyFileType(mb->getBufferStart(),
@@ -353,41 +77,41 @@
       if (Ident.first == llvm::ELF::ELFCLASS32 &&
           Ident.second == llvm::ELF::ELFDATA2LSB) {
         if (MaxAlignment >= 4)
-          f.reset(new FileELF<ELFType<llvm::support::little, 4, false>>(
-                          std::move(mb), ec));
+          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>>(
-                          std::move(mb), ec));
+          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>>(
-                          std::move(mb), ec));
+          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>>(
-                          std::move(mb), ec));
+          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>>(
-                          std::move(mb), ec));
+          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>>(
-                          std::move(mb), ec));
+          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>>(
-                          std::move(mb), ec));
+          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>>(
-                          std::move(mb), ec));
+          f.reset(new FileELF<ELFType<llvm::support::little, 2, true> >(
+                          _elfTargetInfo, std::move(mb), ec));
         else
           llvm_unreachable("Invalid alignment for ELF file!");
       }
@@ -410,13 +134,14 @@
   }
 
 private:
+  const ELFTargetInfo &_elfTargetInfo;
   ReaderArchive _readerArchive;
 };
 } // end anon namespace.
 
 namespace lld {
-std::unique_ptr<Reader> createReaderELF(const TargetInfo & ti,
+std::unique_ptr<Reader> createReaderELF(const ELFTargetInfo &eti,
                                         std::function<ReaderFunc> read) {
-  return std::unique_ptr<Reader>(new ReaderELF(ti, std::move(read)));
+  return std::unique_ptr<Reader>(new ReaderELF(eti, std::move(read)));
 }
 } // end namespace lld

Modified: lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp?rev=173430&r1=173429&r2=173430&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp Fri Jan 25 01:39:18 2013
@@ -64,7 +64,7 @@
   ELFStringTable<ELFT> *_strtab;
   ELFStringTable<ELFT> *_shstrtab;
   ELFSectionHeader<ELFT> *_shdrtab;
-  CRuntimeFile<ELFT> _runtimeFile;
+  CRuntimeFileELF<ELFT> _runtimeFile;
 };
 
 //===----------------------------------------------------------------------===//

Added: lld/trunk/lib/ReaderWriter/ELF/X86/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86/CMakeLists.txt?rev=173430&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86/CMakeLists.txt (added)
+++ lld/trunk/lib/ReaderWriter/ELF/X86/CMakeLists.txt Fri Jan 25 01:39:18 2013
@@ -0,0 +1,5 @@
+add_lld_library(lldX86ELFTarget
+  X86TargetInfo.cpp
+  )
+
+target_link_libraries(lldX86ELFTarget)

Added: lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTarget.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTarget.h?rev=173430&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTarget.h (added)
+++ lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTarget.h Fri Jan 25 01:39:18 2013
@@ -0,0 +1,9 @@
+//===- 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"

Added: lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTargetInfo.h?rev=173430&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTargetInfo.h (added)
+++ lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFTargetInfo.h Fri Jan 25 01:39:18 2013
@@ -0,0 +1,34 @@
+//===- 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

Added: lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetInfo.cpp?rev=173430&view=auto
==============================================================================
    (empty)

Added: lld/trunk/lib/ReaderWriter/ELF/X86_64/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/CMakeLists.txt?rev=173430&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/CMakeLists.txt (added)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/CMakeLists.txt Fri Jan 25 01:39:18 2013
@@ -0,0 +1,5 @@
+add_lld_library(lldX86_64ELFTarget
+  X86_64TargetInfo.cpp
+  )
+
+target_link_libraries(lldX86_64ELFTarget)

Added: 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=173430&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTarget.h (added)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTarget.h Fri Jan 25 01:39:18 2013
@@ -0,0 +1,9 @@
+//===- 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"

Added: 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=173430&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTargetInfo.h (added)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFTargetInfo.h Fri Jan 25 01:39:18 2013
@@ -0,0 +1,37 @@
+//===- 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 "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 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; }
+
+};
+} // elf
+} // lld
+
+#endif // LLD_READER_WRITER_ELF_X86_64_TARGETINFO_H

Added: 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=173430&view=auto
==============================================================================
    (empty)

Modified: lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp?rev=173430&r1=173429&r2=173430&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp Fri Jan 25 01:39:18 2013
@@ -29,7 +29,7 @@
 class CRuntimeFile : public SimpleFile {
 public:
     CRuntimeFile(const MachOTargetInfo &ti) 
-      : SimpleFile("C runtime"), _undefMain(*this, "_main") {
+      : SimpleFile(ti, "C runtime"), _undefMain(*this, "_main") {
       // only main executables need _main
       if (ti.getLinkerOptions()._outputKind == OutputKind::Executable)
         this->addAtom(_undefMain);

Modified: lld/trunk/lib/ReaderWriter/MachO/StubsPass.hpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/StubsPass.hpp?rev=173430&r1=173429&r2=173430&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/StubsPass.hpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/StubsPass.hpp Fri Jan 25 01:39:18 2013
@@ -30,11 +30,12 @@
 class StubsPass : public lld::StubsPass {
 public:
   StubsPass(const MachOTargetInfo &ti) 
-    : _targetInfo(ti),
-      _kindHandler(KindHandler::makeHandler(_targetInfo.getTriple().getArch())),
-      _helperCommonAtom(nullptr),
-      _helperCacheAtom(nullptr),
-      _helperBinderAtom(nullptr) {
+    : _targetInfo(ti)
+    , _kindHandler(KindHandler::makeHandler(_targetInfo.getTriple().getArch()))
+    , _file(ti)
+    , _helperCommonAtom(nullptr)
+    , _helperCacheAtom(nullptr)
+    , _helperBinderAtom(nullptr) {
   }
 
   virtual bool noTextRelocs() {
@@ -147,8 +148,8 @@
 
   class File : public SimpleFile {
   public:
-      File() : SimpleFile("MachO Stubs pass") {
-      }
+    File(const MachOTargetInfo &ti) : SimpleFile(ti, "MachO Stubs pass") {
+    }
   };
 
   const MachOTargetInfo                          &_targetInfo;

Modified: lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp?rev=173430&r1=173429&r2=173430&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp (original)
+++ lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp Fri Jan 25 01:39:18 2013
@@ -246,11 +246,11 @@
 
   /// Instantiates a File object from a native object file.  Ownership
   /// of the MemoryBuffer is transfered to the resulting File object.
-  static error_code make(std::unique_ptr<llvm::MemoryBuffer> &mb,
-                         StringRef path,
-                         std::vector<std::unique_ptr<lld::File>> &result) {
-    const uint8_t* const base =
-                       reinterpret_cast<const uint8_t*>(mb->getBufferStart());
+  static error_code make(
+      const TargetInfo &ti, std::unique_ptr<llvm::MemoryBuffer> &mb,
+      StringRef path, std::vector<std::unique_ptr<lld::File> > &result) {
+    const uint8_t *const base =
+        reinterpret_cast<const uint8_t *>(mb->getBufferStart());
     const NativeFileHeader* const header =
                        reinterpret_cast<const NativeFileHeader*>(base);
     const NativeChunk *const chunks =
@@ -264,17 +264,16 @@
     if ( header->fileSize > fileSize )
       return make_error_code(native_reader_error::file_too_short);
 
-    DEBUG_WITH_TYPE("ReaderNative", llvm::dbgs() 
-                    << " Native File Header:"
-                    << " fileSize=" << header->fileSize
-                    << " chunkCount=" << header->chunkCount
-                    << "\n");
+    DEBUG_WITH_TYPE("ReaderNative",
+                    llvm::dbgs() << " Native File Header:" << " fileSize="
+                                 << header->fileSize << " chunkCount="
+                                 << header->chunkCount << "\n");
 
     // instantiate NativeFile object and add values to it as found
-    std::unique_ptr<File> file(new File(std::move(mb), path));
+    std::unique_ptr<File> file(new File(ti, std::move(mb), path));
 
     // process each chunk
-    for(uint32_t i=0; i < header->chunkCount; ++i) {
+    for (uint32_t i = 0; i < header->chunkCount; ++i) {
       error_code ec;
       const NativeChunk* chunk = &chunks[i];
       // sanity check chunk is within file
@@ -373,9 +372,10 @@
   virtual const atom_collection<SharedLibraryAtom>& sharedLibrary() const {
       return _sharedLibraryAtoms;
   }
-  virtual const atom_collection<AbsoluteAtom>& absolute() const {
-      return _absoluteAtoms;
+  virtual const atom_collection<AbsoluteAtom> &absolute() const {
+    return _absoluteAtoms;
   }
+  virtual const TargetInfo &getTargetInfo() const { return _targetInfo; }
 
 private:
   friend class NativeDefinedAtomV1;
@@ -728,25 +728,18 @@
     assert(index > _targetsTableCount);
     _targetsTable[index] = newAtom;
   }
-  
-
 
   // private constructor, only called by make()
-  File(std::unique_ptr<llvm::MemoryBuffer> mb, StringRef path) :
-    lld::File(path),
-    _buffer(std::move(mb)),  // Reader now takes ownership of buffer
-    _header(nullptr),
-    _targetsTable(nullptr),
-    _targetsTableCount(0),
-    _strings(nullptr),
-    _stringsMaxOffset(0),
-    _addends(nullptr),
-    _addendsMaxIndex(0),
-    _contentStart(nullptr),
-    _contentEnd(nullptr)
-  {
-    _header = reinterpret_cast<const NativeFileHeader*>
-                                                  (_buffer->getBufferStart());
+  File(const TargetInfo &ti, std::unique_ptr<llvm::MemoryBuffer> mb,
+       StringRef path)
+      : lld::File(path),
+        _buffer(std::move(mb)), // Reader now takes ownership of buffer
+        _header(nullptr), _targetsTable(nullptr), _targetsTableCount(0),
+        _strings(nullptr), _stringsMaxOffset(0), _addends(nullptr),
+        _addendsMaxIndex(0), _contentStart(nullptr), _contentEnd(nullptr),
+        _targetInfo(ti) {
+    _header =
+        reinterpret_cast<const NativeFileHeader *>(_buffer->getBufferStart());
   }
 
   template <typename T>
@@ -805,13 +798,13 @@
   const char*                     _strings;
   uint32_t                        _stringsMaxOffset;
   const Reference::Addend*        _addends;
-  uint32_t                        _addendsMaxIndex;
-  const uint8_t*                  _contentStart;
-  const uint8_t*                  _contentEnd;
+  uint32_t _addendsMaxIndex;
+  const uint8_t *_contentStart;
+  const uint8_t *_contentEnd;
+  const TargetInfo &_targetInfo;
 };
 
-
-inline const class lld::File& NativeDefinedAtomV1::file() const {
+inline const class lld::File &NativeDefinedAtomV1::file() const {
   return *_file;
 }
 
@@ -929,10 +922,11 @@
 public:
   Reader(const TargetInfo &ti)
    : lld::Reader(ti) {}
-  
-  virtual error_code parseFile(std::unique_ptr<MemoryBuffer> mb, 
-                               std::vector<std::unique_ptr<lld::File>> &result) {
-    return File::make(mb, mb->getBufferIdentifier(), result);
+
+  virtual error_code parseFile(
+      std::unique_ptr<MemoryBuffer> mb,
+      std::vector<std::unique_ptr<lld::File> > &result) {
+    return File::make(_targetInfo, mb, mb->getBufferIdentifier(), result);
   }
 };
 } // end namespace native

Modified: lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp?rev=173430&r1=173429&r2=173430&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp Fri Jan 25 01:39:18 2013
@@ -211,8 +211,9 @@
 
 class FileCOFF : public File {
 public:
-  FileCOFF(std::unique_ptr<llvm::MemoryBuffer> MB, llvm::error_code &EC)
-    : File(MB->getBufferIdentifier()) {
+  FileCOFF(const TargetInfo &ti, std::unique_ptr<llvm::MemoryBuffer> MB,
+           llvm::error_code &EC)
+      : File(MB->getBufferIdentifier()), _targetInfo(ti) {
     llvm::OwningPtr<llvm::object::Binary> Bin;
     EC = llvm::object::createBinary(MB.release(), Bin);
     if (EC)
@@ -350,13 +351,16 @@
     return AbsoluteAtoms;
   }
 
+  virtual const TargetInfo &getTargetInfo() const { return _targetInfo; }
+
 private:
   std::unique_ptr<const llvm::object::COFFObjectFile> Obj;
-  atom_collection_vector<DefinedAtom>       DefinedAtoms;
+  atom_collection_vector<DefinedAtom> DefinedAtoms;
   atom_collection_vector<UndefinedAtom>     UndefinedAtoms;
   atom_collection_vector<SharedLibraryAtom> SharedLibraryAtoms;
-  atom_collection_vector<AbsoluteAtom>      AbsoluteAtoms;
+  atom_collection_vector<AbsoluteAtom> AbsoluteAtoms;
   llvm::BumpPtrAllocator AtomStorage;
+  const TargetInfo &_targetInfo;
 };
 
 
@@ -366,9 +370,9 @@
   ReaderCOFF(const TargetInfo &ti) : Reader(ti) {}
 
   error_code parseFile(std::unique_ptr<MemoryBuffer> mb,
-                       std::vector<std::unique_ptr<File>> &result) {
+                       std::vector<std::unique_ptr<File> > &result) {
     llvm::error_code ec;
-    std::unique_ptr<File> f(new FileCOFF(std::move(mb), ec));
+    std::unique_ptr<File> f(new FileCOFF(_targetInfo, std::move(mb), ec));
     if (ec) {
       return ec;
     }

Modified: lld/trunk/lib/ReaderWriter/ReaderArchive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ReaderArchive.cpp?rev=173430&r1=173429&r2=173430&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ReaderArchive.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ReaderArchive.cpp Fri Jan 25 01:39:18 2013
@@ -134,10 +134,10 @@
 public:
   /// only subclasses of ArchiveLibraryFile can be instantiated 
   FileArchive(const TargetInfo &ti,
-              std::function<ErrorOr<Reader&> (const LinkerInput &)> getReader,
-              std::unique_ptr<llvm::MemoryBuffer> mb,
-              error_code &ec)
-      : ArchiveLibraryFile(mb->getBufferIdentifier()), _getReader(getReader) {
+              std::function<ErrorOr<Reader &>(const LinkerInput &)> getReader,
+              std::unique_ptr<llvm::MemoryBuffer> mb, error_code &ec)
+      : ArchiveLibraryFile(ti, mb->getBufferIdentifier()),
+        _getReader(getReader) {
     std::unique_ptr<llvm::object::Archive> archive_obj(
         new llvm::object::Archive(mb.release(), ec));
     if (ec)

Modified: lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp?rev=173430&r1=173429&r2=173430&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp (original)
+++ lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp Fri Jan 25 01:39:18 2013
@@ -269,19 +269,15 @@
 // type to make template matching work, so invent RefKind.
 LLVM_YAML_STRONG_TYPEDEF(lld::Reference::Kind, RefKind)
 
-
 } // namespace anon
 
-
-LLVM_YAML_IS_SEQUENCE_VECTOR(ArchMember);
-LLVM_YAML_IS_SEQUENCE_VECTOR(const lld::Reference*)
-
-// Always write DefinedAtoms content bytes as a flow sequence.
-LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(ImplicitHex8);
-
-// for compatibility with gcc-4.7 in C++11 mode, add extra namespace
-namespace llvm {
-namespace yaml { 
+LLVM_YAML_IS_SEQUENCE_VECTOR(ArchMember)
+    LLVM_YAML_IS_SEQUENCE_VECTOR(const lld::Reference *)
+    // Always write DefinedAtoms content bytes as a flow sequence.
+    LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(ImplicitHex8)
+    // for compatibility with gcc-4.7 in C++11 mode, add extra namespace
+    namespace llvm {
+  namespace yaml { 
 
 // This is a custom formatter for RefKind
 template<>
@@ -607,17 +603,21 @@
 // YAML conversion for const lld::File*
 template <>
 struct MappingTraits<const lld::File*> {
-  
-  class NormArchiveFile : public lld::ArchiveLibraryFile {
-  public:
-    NormArchiveFile(IO &io) : ArchiveLibraryFile(""), _path() {
-    }
-    NormArchiveFile(IO &io, const lld::File *file) 
-      : ArchiveLibraryFile(file->path()), 
-        _path(file->path()) {
+
+    class NormArchiveFile : public lld::ArchiveLibraryFile {
+    public:
+      NormArchiveFile(IO &io)
+          : ArchiveLibraryFile(((ContextInfo *)io.getContext())->_targetInfo,
+                               ""),
+            _path() {
+      }
+      NormArchiveFile(IO &io, const lld::File *file)
+          : ArchiveLibraryFile(((ContextInfo *)io.getContext())->_targetInfo,
+                               file->path()),
+            _path(file->path()) {
         // If we want to support writing archives, this constructor would
         // need to populate _members.
-    }
+      }
 
     const lld::File *denormalize(IO &io) {
       return this;
@@ -665,19 +665,16 @@
     StringRef                _path;
     std::vector<ArchMember>  _members;
   };
-  
-  
-  class NormalizedFile : public lld::File {
-  public:
-    NormalizedFile(IO &io) : File(""), _rnb(nullptr) {
-    }
-    NormalizedFile(IO &io, const lld::File *file) 
-      : File(file->path()), 
-        _rnb(new RefNameBuilder(*file)),
-        _path(file->path()) {
-      for (const lld::DefinedAtom *a : file->defined())
-        _definedAtoms.push_back(a);
-      for (const lld::UndefinedAtom *a : file->undefined())
+
+    class NormalizedFile : public lld::File {
+    public:
+      NormalizedFile(IO &io) : File(""), _IO(io), _rnb(nullptr) {}
+      NormalizedFile(IO &io, const lld::File *file)
+          : File(file->path()), _IO(io), _rnb(new RefNameBuilder(*file)),
+            _path(file->path()) {
+        for (const lld::DefinedAtom *a : file->defined())
+          _definedAtoms.push_back(a);
+        for (const lld::UndefinedAtom *a : file->undefined())
         _undefinedAtoms.push_back(a);
       for (const lld::SharedLibraryAtom *a : file->sharedLibrary())
         _sharedLibraryAtoms.push_back(a);
@@ -695,12 +692,16 @@
     virtual const atom_collection<lld::SharedLibraryAtom> &sharedLibrary()const{
       return _sharedLibraryAtoms;
     }
-    virtual const atom_collection<lld::AbsoluteAtom> &absolute() const {
-      return _absoluteAtoms;
-    }
-    
-    // Allocate a new copy of this string and keep track of allocations
-    // in _stringCopies, so they can be freed when File is destroyed.
+      virtual const atom_collection<lld::AbsoluteAtom> &absolute() const {
+        return _absoluteAtoms;
+      }
+
+      virtual const TargetInfo &getTargetInfo() const {
+        return ((ContextInfo *)_IO.getContext())->_targetInfo;
+      }
+
+      // Allocate a new copy of this string and keep track of allocations
+      // in _stringCopies, so they can be freed when File is destroyed.
     StringRef copyString(StringRef str) {
       // We want _stringCopies to own the string memory so it is deallocated
       // when the File object is destroyed.  But we need a StringRef that
@@ -709,12 +710,13 @@
       memcpy(s.get(), str.data(), str.size());
       llvm::StringRef r = llvm::StringRef(s.get(), str.size());
       _stringCopies.push_back(std::move(s));
-      return r;
-    }
-    
-    RefNameBuilder                    *_rnb;
-    StringRef                          _path;
-    AtomList<lld::DefinedAtom>         _definedAtoms;
+        return r;
+      }
+
+      IO &_IO;
+      RefNameBuilder *_rnb;
+      StringRef _path;
+      AtomList<lld::DefinedAtom> _definedAtoms;
     AtomList<lld::UndefinedAtom>       _undefinedAtoms;
     AtomList<lld::SharedLibraryAtom>   _sharedLibraryAtoms;
     AtomList<lld::AbsoluteAtom>        _absoluteAtoms;

Modified: lld/trunk/tools/lld-core/TestingHelpers.hpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/tools/lld-core/TestingHelpers.hpp?rev=173430&r1=173429&r2=173430&view=diff
==============================================================================
--- lld/trunk/tools/lld-core/TestingHelpers.hpp (original)
+++ lld/trunk/tools/lld-core/TestingHelpers.hpp Fri Jan 25 01:39:18 2013
@@ -224,7 +224,7 @@
 
 class TestingPassFile : public MutableFile {
 public:
-  TestingPassFile() : MutableFile("Testing pass") {}
+  TestingPassFile(const TargetInfo &ti) : MutableFile(ti, "Testing pass") {}
 
   virtual void addAtom(const Atom &atom) {
     if (const DefinedAtom *defAtom = dyn_cast<DefinedAtom>(&atom))
@@ -280,6 +280,9 @@
 
 class TestingStubsPass : public StubsPass {
 public:
+  TestingStubsPass(const TargetInfo &ti) : _file(TestingPassFile(ti))
+  {}
+
   virtual bool noTextRelocs() {
     return true;
   }
@@ -310,6 +313,9 @@
 
 class TestingGOTPass : public GOTPass {
 public:
+  TestingGOTPass(const TargetInfo &ti) : _file(TestingPassFile(ti))
+  {}
+
   virtual bool noTextRelocs() {
     return true;
   }

Modified: lld/trunk/tools/lld-core/lld-core.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/tools/lld-core/lld-core.cpp?rev=173430&r1=173429&r2=173430&view=diff
==============================================================================
--- lld/trunk/tools/lld-core/lld-core.cpp (original)
+++ lld/trunk/tools/lld-core/lld-core.cpp Fri Jan 25 01:39:18 2013
@@ -166,9 +166,9 @@
 
   virtual void addPasses(PassManager &pm) const {
     if (_doStubs)
-      pm.add(std::unique_ptr<Pass>(new TestingStubsPass));
+      pm.add(std::unique_ptr<Pass>(new TestingStubsPass(*this)));
     if (_doGOT)
-      pm.add(std::unique_ptr<Pass>(new TestingGOTPass));
+      pm.add(std::unique_ptr<Pass>(new TestingGOTPass(*this)));
     if (_doOrder)
       pm.add(std::unique_ptr<Pass>(new OrderPass));
   }





More information about the llvm-commits mailing list