[Orc] Make the ObjectLinkingLayer take ownership of object files until
[oota-llvm.git] / include / llvm / ExecutionEngine / Orc / ObjectLinkingLayer.h
index 03b43aa3272d429369244148864a2b0c6bad202e..957fec40ad3239e007ddea8823d81431cdab9b99 100644 (file)
@@ -61,6 +61,7 @@ protected:
       RTDyld->resolveRelocations();
       RTDyld->registerEHFrames();
       MM->finalizeMemory();
+      OwnedBuffers.clear();
       State = Finalized;
     }
 
@@ -70,10 +71,19 @@ protected:
       RTDyld->mapSectionAddress(LocalAddress, TargetAddress);
     }
 
+    void takeOwnershipOfBuffer(std::unique_ptr<MemoryBuffer> B) {
+      OwnedBuffers.push_back(std::move(B));
+    }
+
   private:
     std::unique_ptr<RTDyldMemoryManager> MM;
     std::unique_ptr<RuntimeDyld> RTDyld;
     enum { Raw, Finalizing, Finalized } State;
+
+    // FIXME: This ownership hack only exists because RuntimeDyldELF still
+    //        wants to be able to inspect the original object when resolving
+    //        relocations. As soon as that can be fixed this should be removed.
+    std::vector<std::unique_ptr<MemoryBuffer>> OwnedBuffers;
   };
 
   typedef std::list<LinkedObjectSet> LinkedObjectSetListT;
@@ -81,6 +91,16 @@ protected:
 public:
   /// @brief Handle to a set of loaded objects.
   typedef LinkedObjectSetListT::iterator ObjSetHandleT;
+
+  // Ownership hack.
+  // FIXME: Remove this as soon as RuntimeDyldELF can apply relocations without
+  //        referencing the original object.
+  template <typename OwningMBSet>
+  void takeOwnershipOfBuffers(ObjSetHandleT H, OwningMBSet MBs) {
+    for (auto &MB : MBs)
+      H->takeOwnershipOfBuffer(std::move(MB));
+  }
+
 };
 
 /// @brief Default (no-op) action to perform when loading objects.