From ac97f5ce486d1ca2967607028eacddd860aaddd0 Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Tue, 15 Jan 2013 07:44:25 +0000 Subject: [Object][ELF] Simplify ELFObjectFile by using ELFType. This simplifies the usage and implementation of ELFObjectFile by using ELFType to replace: This does complicate the base ELF types as they must now use template template parameters to partially specialize for the 32 and 64bit cases. However these are only defined once. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172515 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp | 82 +++++++++++----------- 1 file changed, 41 insertions(+), 41 deletions(-) (limited to 'lib/ExecutionEngine') diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp index 1524b48..b8537b1 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp @@ -28,8 +28,6 @@ using namespace llvm; using namespace llvm::object; -using support::endianness; - namespace { static inline @@ -40,22 +38,22 @@ error_code check(error_code Err) { return Err; } -template +template class DyldELFObject - : public ELFObjectFile { - LLVM_ELF_IMPORT_TYPES(target_endianness, max_alignment, is64Bits) + : public ELFObjectFile { + LLVM_ELF_IMPORT_TYPES(ELFT) - typedef Elf_Shdr_Impl Elf_Shdr; - typedef Elf_Sym_Impl Elf_Sym; + typedef Elf_Shdr_Impl Elf_Shdr; + typedef Elf_Sym_Impl Elf_Sym; typedef - Elf_Rel_Impl Elf_Rel; + Elf_Rel_Impl Elf_Rel; typedef - Elf_Rel_Impl Elf_Rela; + Elf_Rel_Impl Elf_Rela; - typedef Elf_Ehdr_Impl Elf_Ehdr; + typedef Elf_Ehdr_Impl Elf_Ehdr; typedef typename ELFDataTypeTypedefHelper< - target_endianness, max_alignment, is64Bits>::value_type addr_type; + ELFT>::value_type addr_type; public: DyldELFObject(MemoryBuffer *Wrapper, error_code &ec); @@ -65,25 +63,25 @@ public: // Methods for type inquiry through isa, cast and dyn_cast static inline bool classof(const Binary *v) { - return (isa >(v) + return (isa >(v) && classof(cast >(v))); + >(v))); } static inline bool classof( - const ELFObjectFile *v) { + const ELFObjectFile *v) { return v->isDyldType(); } }; -template +template class ELFObjectImage : public ObjectImageCommon { protected: - DyldELFObject *DyldObj; + DyldELFObject *DyldObj; bool Registered; public: ELFObjectImage(ObjectBuffer *Input, - DyldELFObject *Obj) + DyldELFObject *Obj) : ObjectImageCommon(Input, Obj), DyldObj(Obj), Registered(false) {} @@ -119,16 +117,15 @@ class ELFObjectImage : public ObjectImageCommon { // The MemoryBuffer passed into this constructor is just a wrapper around the // actual memory. Ultimately, the Binary parent class will take ownership of // this MemoryBuffer object but not the underlying memory. -template -DyldELFObject - ::DyldELFObject(MemoryBuffer *Wrapper, error_code &ec) - : ELFObjectFile(Wrapper, ec) { +template +DyldELFObject::DyldELFObject(MemoryBuffer *Wrapper, error_code &ec) + : ELFObjectFile(Wrapper, ec) { this->isDyldELFObject = true; } -template -void DyldELFObject - ::updateSectionAddress(const SectionRef &Sec, uint64_t Addr) { +template +void DyldELFObject::updateSectionAddress(const SectionRef &Sec, + uint64_t Addr) { DataRefImpl ShdrRef = Sec.getRawDataRefImpl(); Elf_Shdr *shdr = const_cast( reinterpret_cast(ShdrRef.p)); @@ -138,13 +135,12 @@ void DyldELFObject shdr->sh_addr = static_cast(Addr); } -template -void DyldELFObject - ::updateSymbolAddress(const SymbolRef &SymRef, uint64_t Addr){ +template +void DyldELFObject::updateSymbolAddress(const SymbolRef &SymRef, + uint64_t Addr) { Elf_Sym *sym = const_cast( - ELFObjectFile - ::getSymbol(SymRef.getRawDataRefImpl())); + ELFObjectFile::getSymbol(SymRef.getRawDataRefImpl())); // This assumes the address passed in matches the target address bitness // The template-based type cast handles everything else. @@ -164,24 +160,28 @@ ObjectImage *RuntimeDyldELF::createObjectImage(ObjectBuffer *Buffer) { error_code ec; if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2LSB) { - DyldELFObject *Obj = - new DyldELFObject(Buffer->getMemBuffer(), ec); - return new ELFObjectImage(Buffer, Obj); + DyldELFObject > *Obj = + new DyldELFObject >( + Buffer->getMemBuffer(), ec); + return new ELFObjectImage >(Buffer, Obj); } else if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2MSB) { - DyldELFObject *Obj = - new DyldELFObject(Buffer->getMemBuffer(), ec); - return new ELFObjectImage(Buffer, Obj); + DyldELFObject > *Obj = + new DyldELFObject >( + Buffer->getMemBuffer(), ec); + return new ELFObjectImage >(Buffer, Obj); } else if (Ident.first == ELF::ELFCLASS64 && Ident.second == ELF::ELFDATA2MSB) { - DyldELFObject *Obj = - new DyldELFObject(Buffer->getMemBuffer(), ec); - return new ELFObjectImage(Buffer, Obj); + DyldELFObject > *Obj = + new DyldELFObject >( + Buffer->getMemBuffer(), ec); + return new ELFObjectImage >(Buffer, Obj); } else if (Ident.first == ELF::ELFCLASS64 && Ident.second == ELF::ELFDATA2LSB) { - DyldELFObject *Obj = - new DyldELFObject(Buffer->getMemBuffer(), ec); - return new ELFObjectImage(Buffer, Obj); + DyldELFObject > *Obj = + new DyldELFObject >( + Buffer->getMemBuffer(), ec); + return new ELFObjectImage >(Buffer, Obj); } else llvm_unreachable("Unexpected ELF format"); -- cgit v1.1