[RuntimeDyld] Add a notifyObjectLoaded method to RuntimeDyld::MemoryManager.
authorLang Hames <lhames@gmail.com>
Sun, 10 Jan 2016 23:59:41 +0000 (23:59 +0000)
committerLang Hames <lhames@gmail.com>
Sun, 10 Jan 2016 23:59:41 +0000 (23:59 +0000)
This is a more generic version of the MCJITMemoryManager::notifyObjectLoaded
method: It provides only a RuntimeDyld reference (rather than an
ExecutionEngine), and so can be used with ORC JIT stacks.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257296 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ExecutionEngine/RTDyldMemoryManager.h
include/llvm/ExecutionEngine/RuntimeDyld.h
lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp

index 207bad06c23965cf8e421e918ecc370ff77c0509..c5006962550e174ba7b616ebb5cc5b5e1e6d0e77 100644 (file)
@@ -30,6 +30,10 @@ class ExecutionEngine;
 
 class MCJITMemoryManager : public RuntimeDyld::MemoryManager {
 public:
+
+  // Don't hide the notifyObjectLoaded method from RuntimeDyld::MemoryManager.
+  using RuntimeDyld::MemoryManager::notifyObjectLoaded;
+
   /// This method is called after an object has been loaded into memory but
   /// before relocations are applied to the loaded sections.  The object load
   /// may have been initiated by MCJIT to resolve an external symbol for another
index fe736bb00cce3a9672caed59f0d0348faeefc6bf..100e97b8b3d9f6ee4c7b49b2f01f987cb02d3be8 100644 (file)
@@ -155,6 +155,20 @@ public:
     /// Returns true if an error occurred, false otherwise.
     virtual bool finalizeMemory(std::string *ErrMsg = nullptr) = 0;
 
+    /// This method is called after an object has been loaded into memory but
+    /// before relocations are applied to the loaded sections.
+    ///
+    /// Memory managers which are preparing code for execution in an external
+    /// address space can use this call to remap the section addresses for the
+    /// newly loaded object.
+    ///
+    /// For clients that do not need access to an ExecutionEngine instance this
+    /// method should be preferred to its cousin
+    /// MCJITMemoryManager::notifyObjectLoaded as this method is compatible with
+    /// ORC JIT stacks.
+    virtual void notifyObjectLoaded(RuntimeDyld &RTDyld,
+                                    const object::ObjectFile &Obj) {}
+
   private:
     virtual void anchor();
     bool FinalizationLocked;
index 716e7f0c0979aa6fa8d1673c4b0c708d6c9d386c..d16b2db24e1a0e71b5768ebff41bbf2085d8e8d0 100644 (file)
@@ -940,7 +940,9 @@ RuntimeDyld::loadObject(const ObjectFile &Obj) {
   if (!Dyld->isCompatibleFile(Obj))
     report_fatal_error("Incompatible object format!");
 
-  return Dyld->loadObject(Obj);
+  auto LoadedObjInfo = Dyld->loadObject(Obj);
+  MemMgr.notifyObjectLoaded(*this, Obj);
+  return LoadedObjInfo;
 }
 
 void *RuntimeDyld::getSymbolLocalAddress(StringRef Name) const {