[llvm] r215255 - [MCJIT] Simplify immediate decoding code in the RuntimeDyldMachO hierarchy.
Lang Hames
lhames at gmail.com
Fri Aug 8 16:12:23 PDT 2014
Author: lhames
Date: Fri Aug 8 18:12:22 2014
New Revision: 215255
URL: http://llvm.org/viewvc/llvm-project?rev=215255&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp?rev=215255&r1=215254&r2=215255&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp Fri Aug 8 18:12:22 2014
@@ -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;
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h?rev=215255&r1=215254&r2=215255&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h Fri Aug 8 18:12:22 2014
@@ -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) {}
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h?rev=215255&r1=215254&r2=215255&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h Fri Aug 8 18:12:22 2014
@@ -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));
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h?rev=215255&r1=215254&r2=215255&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h Fri Aug 8 18:12:22 2014
@@ -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));
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h?rev=215255&r1=215254&r2=215255&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h Fri Aug 8 18:12:22 2014
@@ -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));
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h?rev=215255&r1=215254&r2=215255&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h Fri Aug 8 18:12:22 2014
@@ -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));
More information about the llvm-commits
mailing list