From: Lang Hames Date: Sat, 19 Jul 2014 00:19:17 +0000 (+0000) Subject: [MCJIT] Add a 'decodeAddend' method to RuntimeDyldMachO and teach X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=e8cfb5988ff42f7c03f1f722b8a8d018e978bcd0 [MCJIT] Add a 'decodeAddend' method to RuntimeDyldMachO and teach getBasicRelocationEntry to use this rather than 'memcpy' to get the relocation addend. Targets with non-trivial addend encodings (E.g. AArch64) can override decodeAddend to handle immediates with interesting encodings. No functional change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213435 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp index d062b10db15..aba67f2e69e 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp @@ -27,28 +27,11 @@ using namespace llvm::object; namespace llvm { -RelocationEntry -RuntimeDyldMachO::getBasicRelocationEntry(unsigned SectionID, - ObjectImage &ObjImg, - const relocation_iterator &RI) const { - - const MachOObjectFile &Obj = - static_cast(*ObjImg.getObjectFile()); - MachO::any_relocation_info RelInfo = - Obj.getRelocation(RI->getRawDataRefImpl()); - - const SectionEntry &Section = Sections[SectionID]; - bool IsPCRel = Obj.getAnyRelocationPCRel(RelInfo); - unsigned Size = Obj.getAnyRelocationLength(RelInfo); - uint64_t Offset; - RI->getOffset(Offset); - uint8_t *LocalAddress = Section.Address + Offset; - unsigned NumBytes = 1 << Size; +uint64_t RuntimeDyldMachO::decodeAddend(uint8_t *LocalAddress, unsigned NumBytes, + uint32_t RelType) const { uint64_t Addend = 0; memcpy(&Addend, LocalAddress, NumBytes); - uint32_t RelType = Obj.getAnyRelocationType(RelInfo); - - return RelocationEntry(SectionID, Offset, RelType, Addend, IsPCRel, Size); + return Addend; } RelocationValueRef RuntimeDyldMachO::getRelocationValueRef( diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h index c8642826d4e..7d1dc0263db 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h @@ -51,11 +51,9 @@ protected: RuntimeDyldMachO(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {} - /// Parse the given relocation, which must be a non-scattered, and - /// return a RelocationEntry representing the information. The 'Addend' field - /// will contain the unmodified instruction immediate. - RelocationEntry getBasicRelocationEntry(unsigned SectionID, ObjectImage &Obj, - const relocation_iterator &RI) const; + /// Extract the addend encoded in the instruction. + uint64_t decodeAddend(uint8_t *LocalAddress, unsigned NumBytes, + uint32_t RelType) const; /// Construct a RelocationValueRef representing the relocation target. /// For Symbols in known sections, this will return a RelocationValueRef @@ -117,7 +115,33 @@ template class RuntimeDyldMachOCRTPBase : public RuntimeDyldMachO { private: Impl &impl() { return static_cast(*this); } - const Impl &impl() const { return static_cast(*this); } + const Impl &impl() const { return static_cast(*this); } + +protected: + + /// Parse the given relocation, which must be a non-scattered, and + /// return a RelocationEntry representing the information. The 'Addend' field + /// will contain the unmodified instruction immediate. + RelocationEntry getBasicRelocationEntry(unsigned SectionID, + ObjectImage &ObjImg, + const relocation_iterator &RI) const { + const MachOObjectFile &Obj = + static_cast(*ObjImg.getObjectFile()); + MachO::any_relocation_info RelInfo = + Obj.getRelocation(RI->getRawDataRefImpl()); + + const SectionEntry &Section = Sections[SectionID]; + bool IsPCRel = Obj.getAnyRelocationPCRel(RelInfo); + unsigned Size = Obj.getAnyRelocationLength(RelInfo); + uint64_t Offset; + RI->getOffset(Offset); + uint8_t *LocalAddress = Section.Address + Offset; + unsigned NumBytes = 1 << Size; + uint32_t RelType = Obj.getAnyRelocationType(RelInfo); + uint64_t Addend = impl().decodeAddend(LocalAddress, NumBytes, RelType); + + return RelocationEntry(SectionID, Offset, RelType, Addend, IsPCRel, Size); + } public: RuntimeDyldMachOCRTPBase(RTDyldMemoryManager *mm) : RuntimeDyldMachO(mm) {}