forked from OSchip/llvm-project
[ELF] Remove duplicate code.
The base class ELFObjectReader/ELFDSOReader implement the canParse functionaity with this change. llvm-svn: 220261
This commit is contained in:
parent
d5a55037e1
commit
322d0df309
|
@ -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
|
||||
|
|
|
@ -18,9 +18,9 @@ target_link_libraries(lldELF ${cmake_2_8_12_INTERFACE}
|
|||
|
||||
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)
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -27,34 +27,30 @@ struct MipsELFFileCreateTraits {
|
|||
}
|
||||
};
|
||||
|
||||
class MipsELFObjectReader : public ELFObjectReader {
|
||||
struct MipsDynamicFileCreateELFTraits {
|
||||
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::MipsDynamicFile<ELFT>::create(std::move(mb), useUndefines);
|
||||
}
|
||||
};
|
||||
|
||||
class MipsELFObjectReader
|
||||
: public ELFObjectReader<Mips32ElELFType, MipsELFFileCreateTraits> {
|
||||
public:
|
||||
MipsELFObjectReader(bool atomizeStrings) : ELFObjectReader(atomizeStrings) {}
|
||||
MipsELFObjectReader(bool atomizeStrings)
|
||||
: ELFObjectReader<Mips32ElELFType, MipsELFFileCreateTraits>(
|
||||
atomizeStrings, llvm::ELF::EM_MIPS) {}
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 MipsELFDSOReader
|
||||
: public ELFDSOReader<Mips32ElELFType, MipsDynamicFileCreateELFTraits> {
|
||||
public:
|
||||
MipsELFDSOReader(bool useUndefines)
|
||||
: ELFDSOReader<Mips32ElELFType, MipsDynamicFileCreateELFTraits>(
|
||||
useUndefines, llvm::ELF::EM_MIPS) {}
|
||||
};
|
||||
|
||||
} // namespace elf
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue