[lld] r220261 - [ELF] Remove duplicate code.
Shankar Easwaran
shankarke at gmail.com
Mon Oct 20 20:12:57 PDT 2014
Author: shankare
Date: Mon Oct 20 22:12:57 2014
New Revision: 220261
URL: http://llvm.org/viewvc/llvm-project?rev=220261&view=rev
Log:
[ELF] Remove duplicate code.
The base class ELFObjectReader/ELFDSOReader implement the canParse functionaity
with this change.
Modified:
lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64ELFReader.h
lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt
lld/trunk/lib/ReaderWriter/ELF/DefaultTargetHandler.h
lld/trunk/lib/ReaderWriter/ELF/ELFReader.h
lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFReader.h
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFReader.h
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h
lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFReader.h
lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFReader.h
lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFReader.h
Modified: lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64ELFReader.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64ELFReader.h?rev=220261&r1=220260&r2=220261&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64ELFReader.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64ELFReader.h Mon Oct 20 22:12:57 2014
@@ -40,65 +40,20 @@ struct AArch64ELFFileCreateELFTraits {
}
};
-class AArch64ELFObjectReader : public ELFObjectReader {
+class AArch64ELFObjectReader
+ : public ELFObjectReader<AArch64ELFType, AArch64ELFFileCreateELFTraits> {
public:
AArch64ELFObjectReader(bool atomizeStrings)
- : ELFObjectReader(atomizeStrings) {}
-
- bool canParse(file_magic magic, StringRef ext,
- const MemoryBuffer &buf) const override {
- const uint8_t *data =
- reinterpret_cast<const uint8_t *>(buf.getBuffer().data());
- const llvm::object::Elf_Ehdr_Impl<AArch64ELFType> *elfHeader =
- reinterpret_cast<const llvm::object::Elf_Ehdr_Impl<AArch64ELFType> *>(
- data);
- return ELFObjectReader::canParse(magic, ext, buf) &&
- elfHeader->e_machine == llvm::ELF::EM_AARCH64;
- }
-
- std::error_code
- parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
- std::vector<std::unique_ptr<File>> &result) const override {
- std::size_t maxAlignment =
- 1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart()));
- auto f = createELF<AArch64ELFFileCreateELFTraits>(
- llvm::object::getElfArchType(mb->getBuffer()), maxAlignment,
- std::move(mb), _atomizeStrings);
- if (std::error_code ec = f.getError())
- return ec;
- result.push_back(std::move(*f));
- return std::error_code();
- }
+ : ELFObjectReader<AArch64ELFType, AArch64ELFFileCreateELFTraits>(
+ atomizeStrings, llvm::ELF::EM_AARCH64) {}
};
-class AArch64ELFDSOReader : public ELFDSOReader {
+class AArch64ELFDSOReader
+ : public ELFDSOReader<AArch64ELFType, AArch64DynamicFileCreateELFTraits> {
public:
- AArch64ELFDSOReader(bool useUndefines) : ELFDSOReader(useUndefines) {}
-
- bool canParse(file_magic magic, StringRef ext,
- const MemoryBuffer &buf) const override {
- const uint8_t *data =
- reinterpret_cast<const uint8_t *>(buf.getBuffer().data());
- const llvm::object::Elf_Ehdr_Impl<AArch64ELFType> *elfHeader =
- reinterpret_cast<const llvm::object::Elf_Ehdr_Impl<AArch64ELFType> *>(
- data);
- return ELFDSOReader::canParse(magic, ext, buf) &&
- elfHeader->e_machine == llvm::ELF::EM_AARCH64;
- }
-
- std::error_code
- parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
- std::vector<std::unique_ptr<File>> &result) const override {
- std::size_t maxAlignment =
- 1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart()));
- auto f = createELF<AArch64DynamicFileCreateELFTraits>(
- llvm::object::getElfArchType(mb->getBuffer()), maxAlignment,
- std::move(mb), _useUndefines);
- if (std::error_code ec = f.getError())
- return ec;
- result.push_back(std::move(*f));
- return std::error_code();
- }
+ AArch64ELFDSOReader(bool useUndefines)
+ : ELFDSOReader<AArch64ELFType, AArch64DynamicFileCreateELFTraits>(
+ useUndefines, llvm::ELF::EM_AARCH64) {}
};
} // namespace elf
Modified: lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt?rev=220261&r1=220260&r2=220261&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt (original)
+++ lld/trunk/lib/ReaderWriter/ELF/CMakeLists.txt Mon Oct 20 22:12:57 2014
@@ -18,9 +18,9 @@ target_link_libraries(lldELF ${cmake_2_8
include_directories(.)
-add_subdirectory(AArch64)
-add_subdirectory(Hexagon)
-add_subdirectory(Mips)
-add_subdirectory(PPC)
add_subdirectory(X86)
add_subdirectory(X86_64)
+add_subdirectory(PPC)
+add_subdirectory(Mips)
+add_subdirectory(Hexagon)
+add_subdirectory(AArch64)
Modified: lld/trunk/lib/ReaderWriter/ELF/DefaultTargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/DefaultTargetHandler.h?rev=220261&r1=220260&r2=220261&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/DefaultTargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/DefaultTargetHandler.h Mon Oct 20 22:12:57 2014
@@ -27,17 +27,11 @@ public:
DefaultTargetHandler(ELFLinkingContext &context)
: TargetHandler<ELFT>(context) {}
- const TargetRelocationHandler<ELFT> &getRelocationHandler() const {
- llvm_unreachable("Target should provide implementation for function ");
- }
+ const TargetRelocationHandler<ELFT> &getRelocationHandler() const = 0;
- virtual std::unique_ptr<Reader> getObjReader(bool atomizeStrings) {
- return std::unique_ptr<Reader>(new ELFObjectReader(atomizeStrings));
- }
+ virtual std::unique_ptr<Reader> getObjReader(bool atomizeStrings) = 0;
- virtual std::unique_ptr<Reader> getDSOReader(bool useShlibUndefines) {
- return std::unique_ptr<Reader>(new ELFDSOReader(useShlibUndefines));
- }
+ virtual std::unique_ptr<Reader> getDSOReader(bool useShlibUndefines) = 0;
virtual std::unique_ptr<Writer> getWriter() = 0;
};
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFReader.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFReader.h?rev=220261&r1=220260&r2=220261&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFReader.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFReader.h Mon Oct 20 22:12:57 2014
@@ -18,33 +18,18 @@
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) {
- return lld::elf::ELFFile<ELFT>::create(std::move(mb), atomizeStrings);
- }
-};
-
+template <typename ELFT, typename ELFTraitsT>
class ELFObjectReader : public Reader {
public:
- ELFObjectReader(bool atomizeStrings) : _atomizeStrings(atomizeStrings) {}
+ typedef llvm::object::Elf_Ehdr_Impl<ELFT> Elf_Ehdr;
+
+ ELFObjectReader(bool atomizeStrings, uint64_t machine)
+ : _atomizeStrings(atomizeStrings), _machine(machine) {}
bool canParse(file_magic magic, StringRef,
- const MemoryBuffer &) const override {
- return (magic == llvm::sys::fs::file_magic::elf_relocatable);
+ const MemoryBuffer &buf) const override {
+ return (magic == llvm::sys::fs::file_magic::elf_relocatable &&
+ elfHeader(buf)->e_machine == _machine);
}
std::error_code
@@ -52,26 +37,38 @@ public:
std::vector<std::unique_ptr<File>> &result) const override {
std::size_t maxAlignment =
1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart()));
- auto f = createELF<ELFFileCreateELFTraits>(
- llvm::object::getElfArchType(mb->getBuffer()), maxAlignment,
- std::move(mb), _atomizeStrings);
+ auto f =
+ createELF<ELFTraitsT>(llvm::object::getElfArchType(mb->getBuffer()),
+ maxAlignment, std::move(mb), _atomizeStrings);
if (std::error_code ec = f.getError())
return ec;
result.push_back(std::move(*f));
return std::error_code();
}
+ const Elf_Ehdr *elfHeader(const MemoryBuffer &buf) const {
+ const uint8_t *data =
+ reinterpret_cast<const uint8_t *>(buf.getBuffer().data());
+ return (reinterpret_cast<const Elf_Ehdr *>(data));
+ }
+
protected:
bool _atomizeStrings;
+ uint64_t _machine;
};
+template <typename ELFT, typename ELFTraitsT>
class ELFDSOReader : public Reader {
public:
- ELFDSOReader(bool useUndefines) : _useUndefines(useUndefines) {}
+ typedef llvm::object::Elf_Ehdr_Impl<ELFT> Elf_Ehdr;
+
+ ELFDSOReader(bool useUndefines, uint64_t machine)
+ : _useUndefines(useUndefines), _machine(machine) {}
bool canParse(file_magic magic, StringRef,
- const MemoryBuffer &) const override {
- return (magic == llvm::sys::fs::file_magic::elf_shared_object);
+ const MemoryBuffer &buf) const override {
+ return (magic == llvm::sys::fs::file_magic::elf_shared_object &&
+ elfHeader(buf)->e_machine == _machine);
}
std::error_code
@@ -79,17 +76,24 @@ public:
std::vector<std::unique_ptr<File>> &result) const override {
std::size_t maxAlignment =
1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart()));
- auto f = createELF<DynamicFileCreateELFTraits>(
- llvm::object::getElfArchType(mb->getBuffer()), maxAlignment,
- std::move(mb), _useUndefines);
+ auto f =
+ createELF<ELFTraitsT>(llvm::object::getElfArchType(mb->getBuffer()),
+ maxAlignment, std::move(mb), _useUndefines);
if (std::error_code ec = f.getError())
return ec;
result.push_back(std::move(*f));
return std::error_code();
}
+ const Elf_Ehdr *elfHeader(const MemoryBuffer &buf) const {
+ const uint8_t *data =
+ reinterpret_cast<const uint8_t *>(buf.getBuffer().data());
+ return (reinterpret_cast<const Elf_Ehdr *>(data));
+ }
+
protected:
bool _useUndefines;
+ uint64_t _machine;
};
} // namespace elf
Modified: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFReader.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFReader.h?rev=220261&r1=220260&r2=220261&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFReader.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFReader.h Mon Oct 20 22:12:57 2014
@@ -40,65 +40,20 @@ struct HexagonELFFileCreateELFTraits {
}
};
-class HexagonELFObjectReader : public ELFObjectReader {
+class HexagonELFObjectReader
+ : public ELFObjectReader<HexagonELFType, HexagonELFFileCreateELFTraits> {
public:
HexagonELFObjectReader(bool atomizeStrings)
- : ELFObjectReader(atomizeStrings) {}
-
- bool canParse(file_magic magic, StringRef ext,
- const MemoryBuffer &buf) const override {
- const uint8_t *data =
- reinterpret_cast<const uint8_t *>(buf.getBuffer().data());
- const llvm::object::Elf_Ehdr_Impl<HexagonELFType> *elfHeader =
- reinterpret_cast<const llvm::object::Elf_Ehdr_Impl<HexagonELFType> *>(
- data);
- return ELFObjectReader::canParse(magic, ext, buf) &&
- elfHeader->e_machine == llvm::ELF::EM_HEXAGON;
- }
-
- std::error_code
- parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
- std::vector<std::unique_ptr<File>> &result) const override {
- std::size_t maxAlignment =
- 1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart()));
- auto f = createELF<HexagonELFFileCreateELFTraits>(
- llvm::object::getElfArchType(mb->getBuffer()), maxAlignment,
- std::move(mb), _atomizeStrings);
- if (std::error_code ec = f.getError())
- return ec;
- result.push_back(std::move(*f));
- return std::error_code();
- }
+ : ELFObjectReader<HexagonELFType, HexagonELFFileCreateELFTraits>(
+ atomizeStrings, llvm::ELF::EM_HEXAGON) {}
};
-class HexagonELFDSOReader : public ELFDSOReader {
+class HexagonELFDSOReader
+ : public ELFDSOReader<HexagonELFType, HexagonDynamicFileCreateELFTraits> {
public:
- HexagonELFDSOReader(bool useUndefines) : ELFDSOReader(useUndefines) {}
-
- bool canParse(file_magic magic, StringRef ext,
- const MemoryBuffer &buf) const override {
- const uint8_t *data =
- reinterpret_cast<const uint8_t *>(buf.getBuffer().data());
- const llvm::object::Elf_Ehdr_Impl<HexagonELFType> *elfHeader =
- reinterpret_cast<const llvm::object::Elf_Ehdr_Impl<HexagonELFType> *>(
- data);
- return ELFDSOReader::canParse(magic, ext, buf) &&
- elfHeader->e_machine == llvm::ELF::EM_HEXAGON;
- }
-
- std::error_code
- parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
- std::vector<std::unique_ptr<File>> &result) const override {
- std::size_t maxAlignment =
- 1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart()));
- auto f = createELF<HexagonDynamicFileCreateELFTraits>(
- llvm::object::getElfArchType(mb->getBuffer()), maxAlignment,
- std::move(mb), _useUndefines);
- if (std::error_code ec = f.getError())
- return ec;
- result.push_back(std::move(*f));
- return std::error_code();
- }
+ HexagonELFDSOReader(bool useUndefines)
+ : ELFDSOReader<HexagonELFType, HexagonDynamicFileCreateELFTraits>(
+ useUndefines, llvm::ELF::EM_HEXAGON) {}
};
} // namespace elf
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h?rev=220261&r1=220260&r2=220261&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h Mon Oct 20 22:12:57 2014
@@ -241,6 +241,12 @@ private:
bool isMips64EL() const { return this->_objFile->isMips64EL(); }
};
+template <class ELFT> class MipsDynamicFile : public DynamicFile<ELFT> {
+public:
+ MipsDynamicFile(const MipsLinkingContext &context, StringRef name)
+ : DynamicFile<ELFT>(context, name) {}
+};
+
} // elf
} // lld
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFReader.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFReader.h?rev=220261&r1=220260&r2=220261&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFReader.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFReader.h Mon Oct 20 22:12:57 2014
@@ -27,34 +27,30 @@ struct MipsELFFileCreateTraits {
}
};
-class MipsELFObjectReader : public ELFObjectReader {
-public:
- MipsELFObjectReader(bool atomizeStrings) : ELFObjectReader(atomizeStrings) {}
+struct MipsDynamicFileCreateELFTraits {
+ typedef llvm::ErrorOr<std::unique_ptr<lld::SharedLibraryFile>> result_type;
- bool canParse(file_magic magic, StringRef ext,
- const MemoryBuffer &buf) const override {
- const uint8_t *data =
- reinterpret_cast<const uint8_t *>(buf.getBuffer().data());
- const llvm::object::Elf_Ehdr_Impl<Mips32ElELFType> *elfHeader =
- reinterpret_cast<const llvm::object::Elf_Ehdr_Impl<Mips32ElELFType> *>(
- data);
- return ELFObjectReader::canParse(magic, ext, buf) &&
- elfHeader->e_machine == llvm::ELF::EM_MIPS;
+ template <class ELFT>
+ static result_type create(std::unique_ptr<llvm::MemoryBuffer> mb,
+ bool useUndefines) {
+ return lld::elf::MipsDynamicFile<ELFT>::create(std::move(mb), useUndefines);
}
+};
- std::error_code
- parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
- std::vector<std::unique_ptr<File>> &result) const override {
- std::size_t maxAlignment =
- 1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart()));
- auto f = createELF<MipsELFFileCreateTraits>(
- llvm::object::getElfArchType(mb->getBuffer()), maxAlignment,
- std::move(mb), _atomizeStrings);
- if (std::error_code ec = f.getError())
- return ec;
- result.push_back(std::move(*f));
- return std::error_code();
- }
+class MipsELFObjectReader
+ : public ELFObjectReader<Mips32ElELFType, MipsELFFileCreateTraits> {
+public:
+ MipsELFObjectReader(bool atomizeStrings)
+ : ELFObjectReader<Mips32ElELFType, MipsELFFileCreateTraits>(
+ atomizeStrings, llvm::ELF::EM_MIPS) {}
+};
+
+class MipsELFDSOReader
+ : public ELFDSOReader<Mips32ElELFType, MipsDynamicFileCreateELFTraits> {
+public:
+ MipsELFDSOReader(bool useUndefines)
+ : ELFDSOReader<Mips32ElELFType, MipsDynamicFileCreateELFTraits>(
+ useUndefines, llvm::ELF::EM_MIPS) {}
};
} // namespace elf
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h?rev=220261&r1=220260&r2=220261&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h Mon Oct 20 22:12:57 2014
@@ -111,6 +111,10 @@ public:
return std::unique_ptr<Reader>(new MipsELFObjectReader(atomizeStrings));
}
+ std::unique_ptr<Reader> getDSOReader(bool useShlibUndefines) override {
+ return std::unique_ptr<Reader>(new MipsELFDSOReader(useShlibUndefines));
+ }
+
const MipsTargetRelocationHandler &getRelocationHandler() const override {
return *_relocationHandler;
}
Modified: lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFReader.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFReader.h?rev=220261&r1=220260&r2=220261&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFReader.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/PPC/PPCELFReader.h Mon Oct 20 22:12:57 2014
@@ -38,62 +38,20 @@ struct PPCELFFileCreateELFTraits {
}
};
-class PPCELFObjectReader : public ELFObjectReader {
+class PPCELFObjectReader
+ : public ELFObjectReader<PPCELFType, PPCELFFileCreateELFTraits> {
public:
- PPCELFObjectReader(bool atomizeStrings) : ELFObjectReader(atomizeStrings) {}
-
- bool canParse(file_magic magic, StringRef ext,
- const MemoryBuffer &buf) const override {
- const uint8_t *data =
- reinterpret_cast<const uint8_t *>(buf.getBuffer().data());
- const llvm::object::Elf_Ehdr_Impl<PPCELFType> *elfHeader =
- reinterpret_cast<const llvm::object::Elf_Ehdr_Impl<PPCELFType> *>(data);
- return ELFObjectReader::canParse(magic, ext, buf) &&
- elfHeader->e_machine == llvm::ELF::EM_PPC;
- }
-
- std::error_code
- parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
- std::vector<std::unique_ptr<File>> &result) const override {
- std::size_t maxAlignment =
- 1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart()));
- auto f = createELF<PPCELFFileCreateELFTraits>(
- llvm::object::getElfArchType(mb->getBuffer()), maxAlignment,
- std::move(mb), _atomizeStrings);
- if (std::error_code ec = f.getError())
- return ec;
- result.push_back(std::move(*f));
- return std::error_code();
- }
+ PPCELFObjectReader(bool atomizeStrings)
+ : ELFObjectReader<PPCELFType, PPCELFFileCreateELFTraits>(
+ atomizeStrings, llvm::ELF::EM_PPC) {}
};
-class PPCELFDSOReader : public ELFDSOReader {
+class PPCELFDSOReader
+ : public ELFDSOReader<PPCELFType, PPCDynamicFileCreateELFTraits> {
public:
- PPCELFDSOReader(bool useUndefines) : ELFDSOReader(useUndefines) {}
-
- bool canParse(file_magic magic, StringRef ext,
- const MemoryBuffer &buf) const override {
- const uint8_t *data =
- reinterpret_cast<const uint8_t *>(buf.getBuffer().data());
- const llvm::object::Elf_Ehdr_Impl<PPCELFType> *elfHeader =
- reinterpret_cast<const llvm::object::Elf_Ehdr_Impl<PPCELFType> *>(data);
- return ELFDSOReader::canParse(magic, ext, buf) &&
- elfHeader->e_machine == llvm::ELF::EM_PPC;
- }
-
- std::error_code
- parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
- std::vector<std::unique_ptr<File>> &result) const override {
- std::size_t maxAlignment =
- 1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart()));
- auto f = createELF<PPCDynamicFileCreateELFTraits>(
- llvm::object::getElfArchType(mb->getBuffer()), maxAlignment,
- std::move(mb), _useUndefines);
- if (std::error_code ec = f.getError())
- return ec;
- result.push_back(std::move(*f));
- return std::error_code();
- }
+ PPCELFDSOReader(bool useUndefines)
+ : ELFDSOReader<PPCELFType, PPCDynamicFileCreateELFTraits>(
+ useUndefines, llvm::ELF::EM_PPC) {}
};
} // namespace elf
Modified: lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFReader.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFReader.h?rev=220261&r1=220260&r2=220261&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFReader.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFReader.h Mon Oct 20 22:12:57 2014
@@ -38,62 +38,20 @@ struct X86ELFFileCreateELFTraits {
}
};
-class X86ELFObjectReader : public ELFObjectReader {
+class X86ELFObjectReader
+ : public ELFObjectReader<X86ELFType, X86ELFFileCreateELFTraits> {
public:
- X86ELFObjectReader(bool atomizeStrings) : ELFObjectReader(atomizeStrings) {}
-
- bool canParse(file_magic magic, StringRef ext,
- const MemoryBuffer &buf) const override {
- const uint8_t *data =
- reinterpret_cast<const uint8_t *>(buf.getBuffer().data());
- const llvm::object::Elf_Ehdr_Impl<X86ELFType> *elfHeader =
- reinterpret_cast<const llvm::object::Elf_Ehdr_Impl<X86ELFType> *>(data);
- return ELFObjectReader::canParse(magic, ext, buf) &&
- elfHeader->e_machine == llvm::ELF::EM_386;
- }
-
- std::error_code
- parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
- std::vector<std::unique_ptr<File>> &result) const override {
- std::size_t maxAlignment =
- 1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart()));
- auto f = createELF<X86ELFFileCreateELFTraits>(
- llvm::object::getElfArchType(mb->getBuffer()), maxAlignment,
- std::move(mb), _atomizeStrings);
- if (std::error_code ec = f.getError())
- return ec;
- result.push_back(std::move(*f));
- return std::error_code();
- }
+ X86ELFObjectReader(bool atomizeStrings)
+ : ELFObjectReader<X86ELFType, X86ELFFileCreateELFTraits>(
+ atomizeStrings, llvm::ELF::EM_386) {}
};
-class X86ELFDSOReader : public ELFDSOReader {
+class X86ELFDSOReader
+ : public ELFDSOReader<X86ELFType, X86DynamicFileCreateELFTraits> {
public:
- X86ELFDSOReader(bool useUndefines) : ELFDSOReader(useUndefines) {}
-
- bool canParse(file_magic magic, StringRef ext,
- const MemoryBuffer &buf) const override {
- const uint8_t *data =
- reinterpret_cast<const uint8_t *>(buf.getBuffer().data());
- const llvm::object::Elf_Ehdr_Impl<X86ELFType> *elfHeader =
- reinterpret_cast<const llvm::object::Elf_Ehdr_Impl<X86ELFType> *>(data);
- return ELFDSOReader::canParse(magic, ext, buf) &&
- elfHeader->e_machine == llvm::ELF::EM_386;
- }
-
- std::error_code
- parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
- std::vector<std::unique_ptr<File>> &result) const override {
- std::size_t maxAlignment =
- 1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart()));
- auto f = createELF<X86DynamicFileCreateELFTraits>(
- llvm::object::getElfArchType(mb->getBuffer()), maxAlignment,
- std::move(mb), _useUndefines);
- if (std::error_code ec = f.getError())
- return ec;
- result.push_back(std::move(*f));
- return std::error_code();
- }
+ X86ELFDSOReader(bool useUndefines)
+ : ELFDSOReader<X86ELFType, X86DynamicFileCreateELFTraits>(
+ useUndefines, llvm::ELF::EM_386) {}
};
} // namespace elf
Modified: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFReader.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFReader.h?rev=220261&r1=220260&r2=220261&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFReader.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFReader.h Mon Oct 20 22:12:57 2014
@@ -39,65 +39,20 @@ struct X86_64ELFFileCreateELFTraits {
}
};
-class X86_64ELFObjectReader : public ELFObjectReader {
+class X86_64ELFObjectReader
+ : public ELFObjectReader<X86_64ELFType, X86_64ELFFileCreateELFTraits> {
public:
X86_64ELFObjectReader(bool atomizeStrings)
- : ELFObjectReader(atomizeStrings) {}
-
- bool canParse(file_magic magic, StringRef ext,
- const MemoryBuffer &buf) const override {
- const uint8_t *data =
- reinterpret_cast<const uint8_t *>(buf.getBuffer().data());
- const llvm::object::Elf_Ehdr_Impl<X86_64ELFType> *elfHeader =
- reinterpret_cast<const llvm::object::Elf_Ehdr_Impl<X86_64ELFType> *>(
- data);
- return ELFObjectReader::canParse(magic, ext, buf) &&
- elfHeader->e_machine == llvm::ELF::EM_X86_64;
- }
-
- std::error_code
- parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
- std::vector<std::unique_ptr<File>> &result) const override {
- std::size_t maxAlignment =
- 1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart()));
- auto f = createELF<X86_64ELFFileCreateELFTraits>(
- llvm::object::getElfArchType(mb->getBuffer()), maxAlignment,
- std::move(mb), _atomizeStrings);
- if (std::error_code ec = f.getError())
- return ec;
- result.push_back(std::move(*f));
- return std::error_code();
- }
+ : ELFObjectReader<X86_64ELFType, X86_64ELFFileCreateELFTraits>(
+ atomizeStrings, llvm::ELF::EM_X86_64) {}
};
-class X86_64ELFDSOReader : public ELFDSOReader {
+class X86_64ELFDSOReader
+ : public ELFDSOReader<X86_64ELFType, X86_64DynamicFileCreateELFTraits> {
public:
- X86_64ELFDSOReader(bool useUndefines) : ELFDSOReader(useUndefines) {}
-
- bool canParse(file_magic magic, StringRef ext,
- const MemoryBuffer &buf) const override {
- const uint8_t *data =
- reinterpret_cast<const uint8_t *>(buf.getBuffer().data());
- const llvm::object::Elf_Ehdr_Impl<X86_64ELFType> *elfHeader =
- reinterpret_cast<const llvm::object::Elf_Ehdr_Impl<X86_64ELFType> *>(
- data);
- return ELFDSOReader::canParse(magic, ext, buf) &&
- elfHeader->e_machine == llvm::ELF::EM_X86_64;
- }
-
- std::error_code
- parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
- std::vector<std::unique_ptr<File>> &result) const override {
- std::size_t maxAlignment =
- 1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart()));
- auto f = createELF<X86_64DynamicFileCreateELFTraits>(
- llvm::object::getElfArchType(mb->getBuffer()), maxAlignment,
- std::move(mb), _useUndefines);
- if (std::error_code ec = f.getError())
- return ec;
- result.push_back(std::move(*f));
- return std::error_code();
- }
+ X86_64ELFDSOReader(bool useUndefines)
+ : ELFDSOReader<X86_64ELFType, X86_64DynamicFileCreateELFTraits>(
+ useUndefines, llvm::ELF::EM_X86_64) {}
};
} // namespace elf
More information about the llvm-commits
mailing list