diff options
author | Lang Hames <lhames@gmail.com> | 2014-08-08 23:12:22 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2014-08-08 23:12:22 +0000 |
commit | 25d93099dda408e899f231dac0ba984884e84070 (patch) | |
tree | 3a1cfe4852e933225118bd36315cc4ec2fad9991 /llvm/lib | |
parent | 4c956fe12993d418dc49bc1eeb90229098039104 (diff) | |
download | bcm5719-llvm-25d93099dda408e899f231dac0ba984884e84070.tar.gz bcm5719-llvm-25d93099dda408e899f231dac0ba984884e84070.zip |
[MCJIT] Simplify immediate decoding code in the RuntimeDyldMachO hierarchy.
Cleanup only: no functional change.
This patch makes RuntimeDyldMachO targets directly responsible for decoding
immediates, rather than letting them implement catch a callback from generic
code. Since this is a very target specific operation, it makes sense to let the
target-specific code drive it.
llvm-svn: 215255
Diffstat (limited to 'llvm/lib')
6 files changed, 49 insertions, 44 deletions
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp index bae2471054d..986daef8a90 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp @@ -27,8 +27,10 @@ using namespace llvm::object; namespace llvm { -int64_t RuntimeDyldMachO::decodeAddend(uint8_t *LocalAddress, unsigned NumBytes, - MachO::RelocationInfoType) const { +int64_t RuntimeDyldMachO::memcpyAddend(const RelocationEntry &RE) const { + const SectionEntry &Section = Sections[RE.SectionID]; + uint8_t *LocalAddress = Section.Address + RE.Offset; + unsigned NumBytes = 1 << RE.Size; int64_t Addend = 0; memcpy(&Addend, LocalAddress, NumBytes); return Addend; diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h index 30f61e98e32..b18d167fab4 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h @@ -52,9 +52,31 @@ protected: RuntimeDyldMachO(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {} - /// Extract the addend encoded in the instruction. - int64_t decodeAddend(uint8_t *LocalAddress, unsigned NumBytes, - MachO::RelocationInfoType RelType) const; + /// This convenience method uses memcpy to extract a contiguous addend (the + /// addend size and offset are taken from the corresponding fields of the RE). + int64_t memcpyAddend(const RelocationEntry &RE) const; + + /// Given a relocation_iterator for a non-scattered relocation, construct a + /// RelocationEntry and fill in the common fields. The 'Addend' field is *not* + /// filled in, since immediate encodings are highly target/opcode specific. + /// For targets/opcodes with simple, contiguous immediates (e.g. X86) the + /// memcpyAddend method can be used to read the immediate. + RelocationEntry getRelocationEntry(unsigned SectionID, ObjectImage &ObjImg, + const relocation_iterator &RI) const { + const MachOObjectFile &Obj = + static_cast<const MachOObjectFile &>(*ObjImg.getObjectFile()); + MachO::any_relocation_info RelInfo = + Obj.getRelocation(RI->getRawDataRefImpl()); + + bool IsPCRel = Obj.getAnyRelocationPCRel(RelInfo); + unsigned Size = Obj.getAnyRelocationLength(RelInfo); + uint64_t Offset; + RI->getOffset(Offset); + MachO::RelocationInfoType RelType = + static_cast<MachO::RelocationInfoType>(Obj.getAnyRelocationType(RelInfo)); + + return RelocationEntry(SectionID, Offset, RelType, 0, IsPCRel, Size); + } /// Construct a RelocationValueRef representing the relocation target. /// For Symbols in known sections, this will return a RelocationValueRef @@ -119,33 +141,6 @@ private: Impl &impl() { return static_cast<Impl &>(*this); } const Impl &impl() const { return static_cast<const Impl &>(*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<const MachOObjectFile &>(*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; - MachO::RelocationInfoType RelType = - static_cast<MachO::RelocationInfoType>(Obj.getAnyRelocationType(RelInfo)); - int64_t Addend = impl().decodeAddend(LocalAddress, NumBytes, RelType); - - return RelocationEntry(SectionID, Offset, RelType, Addend, IsPCRel, Size); - } - public: RuntimeDyldMachOCRTPBase(RTDyldMemoryManager *mm) : RuntimeDyldMachO(mm) {} diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h index ffdb53a6b18..e7e8fa580ff 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h @@ -28,11 +28,13 @@ public: unsigned getStubAlignment() override { return 8; } /// Extract the addend encoded in the instruction / memory location. - int64_t decodeAddend(uint8_t *LocalAddress, unsigned NumBytes, - MachO::RelocationInfoType RelType) const { + int64_t decodeAddend(const RelocationEntry &RE) const { + const SectionEntry &Section = Sections[RE.SectionID]; + uint8_t *LocalAddress = Section.Address + RE.Offset; + unsigned NumBytes = 1 << RE.Size; int64_t Addend = 0; // Verify that the relocation has the correct size and alignment. - switch (RelType) { + switch (RE.RelType) { default: llvm_unreachable("Unsupported relocation type!"); case MachO::ARM64_RELOC_UNSIGNED: @@ -49,7 +51,7 @@ public: break; } - switch (RelType) { + switch (RE.RelType) { default: llvm_unreachable("Unsupported relocation type!"); case MachO::ARM64_RELOC_UNSIGNED: @@ -263,7 +265,8 @@ public: RelInfo = Obj.getRelocation(RelI->getRawDataRefImpl()); } - RelocationEntry RE(getBasicRelocationEntry(SectionID, ObjImg, RelI)); + RelocationEntry RE(getRelocationEntry(SectionID, ObjImg, RelI)); + RE.Addend = decodeAddend(RE); RelocationValueRef Value( getRelocationValueRef(ObjImg, RelI, RE, ObjSectionToID, Symbols)); diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h index b7bd0b9d04f..f784fa6b672 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h @@ -28,11 +28,13 @@ public: unsigned getStubAlignment() override { return 4; } - int64_t decodeAddend(uint8_t *LocalAddress, unsigned NumBytes, - MachO::RelocationInfoType RelType) const { - switch (RelType) { + int64_t decodeAddend(const RelocationEntry &RE) const { + const SectionEntry &Section = Sections[RE.SectionID]; + uint8_t *LocalAddress = Section.Address + RE.Offset; + + switch (RE.RelType) { default: - return ParentT::decodeAddend(LocalAddress, NumBytes, RelType); + return memcpyAddend(RE); case MachO::ARM_RELOC_BR24: { uint32_t Temp; memcpy(&Temp, LocalAddress, 4); @@ -55,7 +57,8 @@ public: if (Obj.isRelocationScattered(RelInfo)) return ++++RelI; - RelocationEntry RE(getBasicRelocationEntry(SectionID, ObjImg, RelI)); + RelocationEntry RE(getRelocationEntry(SectionID, ObjImg, RelI)); + RE.Addend = decodeAddend(RE); RelocationValueRef Value( getRelocationValueRef(ObjImg, RelI, RE, ObjSectionToID, Symbols)); diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h index 156287b3af1..e7389776e25 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h @@ -47,7 +47,8 @@ public: llvm_unreachable("Unhandled scattered relocation."); } - RelocationEntry RE(getBasicRelocationEntry(SectionID, ObjImg, RelI)); + RelocationEntry RE(getRelocationEntry(SectionID, ObjImg, RelI)); + RE.Addend = memcpyAddend(RE); RelocationValueRef Value( getRelocationValueRef(ObjImg, RelI, RE, ObjSectionToID, Symbols)); diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h index 9106f415422..4a6e76b5d15 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h @@ -38,7 +38,8 @@ public: assert(!Obj.isRelocationScattered(RelInfo) && "Scattered relocations not supported on X86_64"); - RelocationEntry RE(getBasicRelocationEntry(SectionID, ObjImg, RelI)); + RelocationEntry RE(getRelocationEntry(SectionID, ObjImg, RelI)); + RE.Addend = memcpyAddend(RE); RelocationValueRef Value( getRelocationValueRef(ObjImg, RelI, RE, ObjSectionToID, Symbols)); |