[lld] r200173 - [ELF] Separate ELFReader classes for subclassing
Shankar Easwaran
shankare at codeaurora.org
Sun Jan 26 16:45:57 PST 2014
Author: shankare
Date: Sun Jan 26 18:45:57 2014
New Revision: 200173
URL: http://llvm.org/viewvc/llvm-project?rev=200173&view=rev
Log:
[ELF] Separate ELFReader classes for subclassing
Added:
lld/trunk/lib/ReaderWriter/ELF/ELFReader.h
- copied, changed from r200172, lld/trunk/lib/ReaderWriter/ELF/Reader.cpp
Modified:
lld/trunk/lib/ReaderWriter/ELF/ELFFile.h
lld/trunk/lib/ReaderWriter/ELF/Reader.cpp
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFFile.h?rev=200173&r1=200172&r2=200173&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFFile.h Sun Jan 26 18:45:57 2014
@@ -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
Copied: lld/trunk/lib/ReaderWriter/ELF/ELFReader.h (from r200172, lld/trunk/lib/ReaderWriter/ELF/Reader.cpp)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFReader.h?p2=lld/trunk/lib/ReaderWriter/ELF/ELFReader.h&p1=lld/trunk/lib/ReaderWriter/ELF/Reader.cpp&r1=200172&r2=200173&rev=200173&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Reader.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFReader.h Sun Jan 26 18:45:57 2014
@@ -1,4 +1,4 @@
-//===- lib/ReaderWriter/ELF/Reader.cpp ------------------------------------===//
+//===- lib/ReaderWriter/ELF/ELFReader.h -----------------------------------===//
//
// The LLVM Linker
//
@@ -6,48 +6,18 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-///
-/// \file
-/// \brief Defines the ELF Reader and all helper sub classes to consume an ELF
-/// file and produces atoms out of it.
-///
-//===----------------------------------------------------------------------===//
-#include "lld/ReaderWriter/Reader.h"
+#ifndef LLD_READER_WRITER_ELF_READER_H
+#define LLD_READER_WRITER_ELF_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 <map>
-#include <vector>
-
-using llvm::support::endianness;
-using namespace llvm::object;
-
namespace lld {
-namespace {
+namespace elf {
struct DynamicFileCreateELFTraits {
typedef llvm::ErrorOr<std::unique_ptr<lld::SharedLibraryFile>> result_type;
@@ -83,12 +53,11 @@ public:
virtual error_code
parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
std::vector<std::unique_ptr<File>> &result) const {
- error_code ec;
std::size_t maxAlignment =
1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart()));
- auto f = createELF<ELFFileCreateELFTraits>(getElfArchType(&*mb),
- maxAlignment, std::move(mb),
- _atomizeStrings, _handler);
+ 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));
@@ -115,7 +84,8 @@ public:
std::size_t maxAlignment =
1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart()));
auto f = createELF<DynamicFileCreateELFTraits>(
- getElfArchType(&*mb), maxAlignment, std::move(mb), _useUndefines);
+ llvm::object::getElfArchType(&*mb), maxAlignment, std::move(mb),
+ _useUndefines);
if (error_code ec = f.getError())
return ec;
result.push_back(std::move(*f));
@@ -126,24 +96,7 @@ private:
bool _useUndefines;
};
-} // anonymous
-
-// This dynamic registration of a handler causes support for all ELF
-// architectures to be pulled into the linker. If we want to support making a
-// linker that only supports one ELF architecture, we'd need to change this
-// to have a different registration method for each architecture.
-void Registry::addSupportELFObjects(bool atomizeStrings,
- TargetHandlerBase *handler) {
-
- // Tell registry about the ELF object file parser.
- add(std::unique_ptr<Reader>(new 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)));
-}
+} // namespace elf
+} // namespace lld
-} // end namespace lld
+#endif // LLD_READER_WRITER_ELF_READER_H
Modified: lld/trunk/lib/ReaderWriter/ELF/Reader.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Reader.cpp?rev=200173&r1=200172&r2=200173&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Reader.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Reader.cpp Sun Jan 26 18:45:57 2014
@@ -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
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
More information about the llvm-commits
mailing list