summaryrefslogtreecommitdiffstats
path: root/lld/lib
diff options
context:
space:
mode:
authorShankar Easwaran <shankare@codeaurora.org>2014-01-27 00:45:57 +0000
committerShankar Easwaran <shankare@codeaurora.org>2014-01-27 00:45:57 +0000
commitd7de108cde0bf54e28aefceb363bdae946b5d51a (patch)
tree3d6dd56784226128fcc9c8d21a39b809486ef886 /lld/lib
parentf755ca16853d585315fa0ad57d403f1448788443 (diff)
downloadbcm5719-llvm-d7de108cde0bf54e28aefceb363bdae946b5d51a.tar.gz
bcm5719-llvm-d7de108cde0bf54e28aefceb363bdae946b5d51a.zip
[ELF] Separate ELFReader classes for subclassing
llvm-svn: 200173
Diffstat (limited to 'lld/lib')
-rw-r--r--lld/lib/ReaderWriter/ELF/ELFFile.h1
-rw-r--r--lld/lib/ReaderWriter/ELF/ELFReader.h102
-rw-r--r--lld/lib/ReaderWriter/ELF/Reader.cpp32
3 files changed, 107 insertions, 28 deletions
diff --git a/lld/lib/ReaderWriter/ELF/ELFFile.h b/lld/lib/ReaderWriter/ELF/ELFFile.h
index 32a12745a73..732c1c86b92 100644
--- a/lld/lib/ReaderWriter/ELF/ELFFile.h
+++ b/lld/lib/ReaderWriter/ELF/ELFFile.h
@@ -39,6 +39,7 @@
#include <unordered_map>
namespace lld {
+
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
diff --git a/lld/lib/ReaderWriter/ELF/ELFReader.h b/lld/lib/ReaderWriter/ELF/ELFReader.h
new file mode 100644
index 00000000000..cdd7a54d04c
--- /dev/null
+++ b/lld/lib/ReaderWriter/ELF/ELFReader.h
@@ -0,0 +1,102 @@
+//===- lib/ReaderWriter/ELF/ELFReader.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_READER_H
+#define LLD_READER_WRITER_ELF_READER_H
+
+#include "CreateELF.h"
+#include "DynamicFile.h"
+#include "ELFFile.h"
+
+#include "lld/ReaderWriter/Reader.h"
+
+namespace lld {
+namespace elf {
+
+struct DynamicFileCreateELFTraits {
+ typedef llvm::ErrorOr<std::unique_ptr<lld::SharedLibraryFile>> result_type;
+
+ template <class ELFT>
+ static result_type create(std::unique_ptr<llvm::MemoryBuffer> mb,
+ bool useUndefines) {
+ return lld::elf::DynamicFile<ELFT>::create(std::move(mb), useUndefines);
+ }
+};
+
+struct ELFFileCreateELFTraits {
+ typedef llvm::ErrorOr<std::unique_ptr<lld::File>> result_type;
+
+ template <class ELFT>
+ static result_type create(std::unique_ptr<llvm::MemoryBuffer> mb,
+ bool atomizeStrings, TargetHandlerBase *handler) {
+ return lld::elf::ELFFile<ELFT>::create(std::move(mb), atomizeStrings,
+ handler);
+ }
+};
+
+class ELFObjectReader : public Reader {
+public:
+ ELFObjectReader(bool atomizeStrings, TargetHandlerBase *handler)
+ : _atomizeStrings(atomizeStrings), _handler(handler) {}
+
+ virtual bool canParse(file_magic magic, StringRef,
+ const MemoryBuffer &) const {
+ return (magic == llvm::sys::fs::file_magic::elf_relocatable);
+ }
+
+ virtual error_code
+ parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
+ std::vector<std::unique_ptr<File>> &result) const {
+ std::size_t maxAlignment =
+ 1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart()));
+ auto f = createELF<ELFFileCreateELFTraits>(
+ llvm::object::getElfArchType(&*mb), maxAlignment, std::move(mb),
+ _atomizeStrings, _handler);
+ if (error_code ec = f.getError())
+ return ec;
+ result.push_back(std::move(*f));
+ return error_code::success();
+ }
+
+private:
+ bool _atomizeStrings;
+ TargetHandlerBase *_handler;
+};
+
+class ELFDSOReader : public Reader {
+public:
+ ELFDSOReader(bool useUndefines) : _useUndefines(useUndefines) {}
+
+ virtual bool canParse(file_magic magic, StringRef,
+ const MemoryBuffer &) const {
+ return (magic == llvm::sys::fs::file_magic::elf_shared_object);
+ }
+
+ virtual error_code
+ parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
+ std::vector<std::unique_ptr<File>> &result) const {
+ std::size_t maxAlignment =
+ 1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart()));
+ auto f = createELF<DynamicFileCreateELFTraits>(
+ llvm::object::getElfArchType(&*mb), maxAlignment, std::move(mb),
+ _useUndefines);
+ if (error_code ec = f.getError())
+ return ec;
+ result.push_back(std::move(*f));
+ return error_code::success();
+ }
+
+private:
+ bool _useUndefines;
+};
+
+} // namespace elf
+} // namespace lld
+
+#endif // LLD_READER_WRITER_ELF_READER_H
diff --git a/lld/lib/ReaderWriter/ELF/Reader.cpp b/lld/lib/ReaderWriter/ELF/Reader.cpp
index 62972334044..17bc546459b 100644
--- a/lld/lib/ReaderWriter/ELF/Reader.cpp
+++ b/lld/lib/ReaderWriter/ELF/Reader.cpp
@@ -13,32 +13,7 @@
///
//===----------------------------------------------------------------------===//
-#include "lld/ReaderWriter/Reader.h"
-
-#include "Atoms.h"
-#include "CreateELF.h"
-#include "DynamicFile.h"
-#include "ELFFile.h"
-
-#include "lld/Core/Reference.h"
-#include "lld/ReaderWriter/ELFLinkingContext.h"
-#include "lld/ReaderWriter/Reader.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 "ELFReader.h"
#include <map>
#include <vector>
@@ -136,14 +111,15 @@ void Registry::addSupportELFObjects(bool atomizeStrings,
TargetHandlerBase *handler) {
// Tell registry about the ELF object file parser.
- add(std::unique_ptr<Reader>(new ELFObjectReader(atomizeStrings, handler)));
+ add(std::unique_ptr<Reader>(
+ new elf::ELFObjectReader(atomizeStrings, handler)));
// Tell registry about the relocation name to number mapping for this arch.
handler->registerRelocationNames(*this);
}
void Registry::addSupportELFDynamicSharedObjects(bool useShlibUndefines) {
- add(std::unique_ptr<Reader>(new ELFDSOReader(useShlibUndefines)));
+ add(std::unique_ptr<Reader>(new elf::ELFDSOReader(useShlibUndefines)));
}
} // end namespace lld
OpenPOWER on IntegriCloud