[llvm] r213435 - [MCJIT] Add a 'decodeAddend' method to RuntimeDyldMachO and teach

Lang Hames lhames at gmail.com
Fri Jul 18 17:19:17 PDT 2014


Author: lhames
Date: Fri Jul 18 19:19:17 2014
New Revision: 213435

URL: http://llvm.org/viewvc/llvm-project?rev=213435&view=rev
Log:
[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.


Modified:
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp?rev=213435&r1=213434&r2=213435&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp Fri Jul 18 19:19:17 2014
@@ -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<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;
+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(

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h?rev=213435&r1=213434&r2=213435&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h Fri Jul 18 19:19:17 2014
@@ -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 <typename Impl>
 class RuntimeDyldMachOCRTPBase : public RuntimeDyldMachO {
 private:
   Impl &impl() { return static_cast<Impl &>(*this); }
-  const Impl &impl() const { 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;
+    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) {}





More information about the llvm-commits mailing list