forked from OSchip/llvm-project
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. llvm-svn: 234074
This commit is contained in:
parent
22f0b3f1a5
commit
db9e9d83b6
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue