[lld] r234074 - ELF: Teach File classes about their file magics.
Rui Ueyama
ruiu at google.com
Fri Apr 3 19:07:31 PDT 2015
Author: ruiu
Date: Fri Apr 3 21:07:30 2015
New Revision: 234074
URL: http://llvm.org/viewvc/llvm-project?rev=234074&view=rev
Log:
ELF: Teach File classes about their file magics.
So that we can remove one template parameter from ELFReader.
ELF port is heavily templatized, and I want to reduce the usage
where possible.
Modified:
lld/trunk/lib/ReaderWriter/ELF/DynamicFile.h
lld/trunk/lib/ReaderWriter/ELF/ELFFile.h
lld/trunk/lib/ReaderWriter/ELF/ELFReader.h
Modified: lld/trunk/lib/ReaderWriter/ELF/DynamicFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/DynamicFile.h?rev=234074&r1=234073&r2=234074&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/DynamicFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/DynamicFile.h Fri Apr 3 21:07:30 2015
@@ -45,6 +45,10 @@ public:
StringRef getDSOName() const override { return _soname; }
+ static bool canParse(file_magic magic) {
+ return magic == file_magic::elf_shared_object;
+ }
+
protected:
std::error_code doParse() override {
std::error_code ec;
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFFile.h?rev=234074&r1=234073&r2=234074&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFFile.h Fri Apr 3 21:07:30 2015
@@ -22,7 +22,6 @@ namespace elf {
/// \brief Read a binary, find out based on the symbol table contents what kind
/// of symbol it is and create corresponding atoms for it
template <class ELFT> class ELFFile : public File {
-
typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym;
typedef llvm::object::Elf_Shdr_Impl<ELFT> Elf_Shdr;
typedef llvm::object::Elf_Rel_Impl<ELFT, false> Elf_Rel;
@@ -102,6 +101,10 @@ public:
_ordinal(0), _doStringsMerge(ctx.mergeCommonStrings()),
_useWrap(ctx.wrapCalls().size()), _ctx(ctx) {}
+ static bool canParse(file_magic magic) {
+ return magic == file_magic::elf_relocatable;
+ }
+
virtual Reference::KindArch kindArch();
/// \brief Create symbols from LinkingContext.
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFReader.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFReader.h?rev=234074&r1=234073&r2=234074&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFReader.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFReader.h Fri Apr 3 21:07:30 2015
@@ -18,8 +18,7 @@
namespace lld {
namespace elf {
-template <typename ELFT, typename ContextT, template <typename> class FileT,
- int FileMagic>
+template <typename ELFT, typename ContextT, template <typename> class FileT>
class ELFReader : public Reader {
public:
typedef llvm::object::Elf_Ehdr_Impl<ELFT> Elf_Ehdr;
@@ -28,7 +27,8 @@ public:
bool canParse(file_magic magic, StringRef,
const MemoryBuffer &buf) const override {
- return magic == FileMagic && elfHeader(buf)->e_machine == ContextT::machine;
+ return (FileT<ELFT>::canParse(magic) &&
+ elfHeader(buf)->e_machine == ContextT::machine);
}
std::error_code
@@ -57,12 +57,10 @@ protected:
};
template <typename ELFT, typename ContextT, template <typename> class FileT>
-using ELFObjectReader = ELFReader<ELFT, ContextT, FileT,
- llvm::sys::fs::file_magic::elf_relocatable>;
+using ELFObjectReader = ELFReader<ELFT, ContextT, FileT>;
template <typename ELFT, typename ContextT>
-using ELFDSOReader = ELFReader<ELFT, ContextT, DynamicFile,
- llvm::sys::fs::file_magic::elf_shared_object>;
+using ELFDSOReader = ELFReader<ELFT, ContextT, DynamicFile>;
} // namespace elf
} // namespace lld
More information about the llvm-commits
mailing list