From 4d9c5397b4a3be747bdb73f1d24c3fdbaaf438fe Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Fri, 4 Jan 2013 20:36:28 +0000 Subject: [Object][ELF] Add a maximum alignment. This is used by createELFObjectFile to create a properly aligned reader. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171520 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp | 100 +++++++++++---------- 1 file changed, 51 insertions(+), 49 deletions(-) (limited to 'lib/ExecutionEngine') diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp index efb34df8c5..0a68f4e654 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp @@ -28,6 +28,8 @@ using namespace llvm; using namespace llvm::object; +using support::endianness; + namespace { static inline @@ -38,19 +40,22 @@ error_code check(error_code Err) { return Err; } -template -class DyldELFObject : public ELFObjectFile { - LLVM_ELF_IMPORT_TYPES(target_endianness, is64Bits) +template +class DyldELFObject + : public ELFObjectFile { + LLVM_ELF_IMPORT_TYPES(target_endianness, max_alignment, is64Bits) - typedef Elf_Shdr_Impl Elf_Shdr; - typedef Elf_Sym_Impl Elf_Sym; - typedef Elf_Rel_Impl Elf_Rel; - typedef Elf_Rel_Impl Elf_Rela; + typedef Elf_Shdr_Impl Elf_Shdr; + typedef Elf_Sym_Impl Elf_Sym; + typedef + Elf_Rel_Impl Elf_Rel; + typedef + Elf_Rel_Impl Elf_Rela; - typedef Elf_Ehdr_Impl Elf_Ehdr; + typedef Elf_Ehdr_Impl Elf_Ehdr; typedef typename ELFDataTypeTypedefHelper< - target_endianness, is64Bits>::value_type addr_type; + target_endianness, max_alignment, is64Bits>::value_type addr_type; public: DyldELFObject(MemoryBuffer *Wrapper, error_code &ec); @@ -60,24 +65,25 @@ public: // Methods for type inquiry through isa, cast and dyn_cast static inline bool classof(const Binary *v) { - return (isa >(v) - && classof(cast >(v))); + return (isa >(v) + && classof(cast >(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) {} @@ -113,17 +119,16 @@ 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)); @@ -133,14 +138,13 @@ void DyldELFObject::updateSectionAddress( 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. @@ -149,7 +153,6 @@ void DyldELFObject::updateSymbolAddress( } // namespace - namespace llvm { ObjectImage *RuntimeDyldELF::createObjectImage(ObjectBuffer *Buffer) { @@ -161,24 +164,24 @@ 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"); @@ -207,7 +210,7 @@ void RuntimeDyldELF::resolveX86_64Relocation(const SectionEntry &Section, case ELF::R_X86_64_32S: { Value += Addend; assert((Type == ELF::R_X86_64_32 && (Value <= UINT32_MAX)) || - (Type == ELF::R_X86_64_32S && + (Type == ELF::R_X86_64_32S && ((int64_t)Value <= INT32_MAX && (int64_t)Value >= INT32_MIN))); uint32_t TruncatedAddr = (Value & 0xFFFFFFFF); uint32_t *Target = reinterpret_cast(Section.Address + Offset); @@ -288,7 +291,7 @@ void RuntimeDyldELF::resolveARMRelocation(const SectionEntry &Section, default: llvm_unreachable("Not implemented relocation type!"); - // Write a 32bit value to relocation address, taking into account the + // Write a 32bit value to relocation address, taking into account the // implicit addend encoded in the target. case ELF::R_ARM_TARGET1 : case ELF::R_ARM_ABS32 : @@ -299,7 +302,7 @@ void RuntimeDyldELF::resolveARMRelocation(const SectionEntry &Section, // Last 4 bit should be shifted. case ELF::R_ARM_MOVW_ABS_NC : // We are not expecting any other addend in the relocation address. - // Using 0x000F0FFF because MOVW has its 16 bit immediate split into 2 + // Using 0x000F0FFF because MOVW has its 16 bit immediate split into 2 // non-contiguous fields. assert((*TargetPtr & 0x000F0FFF) == 0); Value = Value & 0xFFFF; @@ -550,7 +553,6 @@ void RuntimeDyldELF::resolvePPC64Relocation(const SectionEntry &Section, } } - void RuntimeDyldELF::resolveRelocation(const SectionEntry &Section, uint64_t Offset, uint64_t Value, @@ -630,9 +632,9 @@ void RuntimeDyldELF::processRelocationRef(const ObjRelocationInfo &Rel, // Default to 'true' in case isText fails (though it never does). bool isCode = true; si->isText(isCode); - Value.SectionID = findOrEmitSection(Obj, - (*si), - isCode, + Value.SectionID = findOrEmitSection(Obj, + (*si), + isCode, ObjSectionToID); Value.Addend = Addend; break; -- cgit v1.2.3-18-g5258