<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Feb 1, 2015 at 8:32 PM, Lang Hames <span dir="ltr"><<a href="mailto:lhames@gmail.com" target="_blank">lhames@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: lhames<br>
Date: Sun Feb  1 22:32:17 2015<br>
New Revision: 227778<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=227778&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=227778&view=rev</a><br>
Log:<br>
[Orc] Make the ObjectLinkingLayer take ownership of object files until<br>
finalization time.<br>
<br>
As currently implemented, RuntimeDyldELF requires the original object<br>
file to be avaible when relocations are being resolved. This patch<br>
ensures that the ObjectLinkingLayer preserves it until then. In the<br>
future RuntimeDyldELF should be rewritten to remove this requirement, at<br>
which point this patch can be reverted.<br>
<br>
Regression test cases for Orc (which include coverage of this bug) will<br>
be committed shortly.<br>
<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h<br>
    llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h<br>
<br>
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h?rev=227778&r1=227777&r2=227778&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h?rev=227778&r1=227777&r2=227778&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h (original)<br>
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h Sun Feb  1 22:32:17 2015<br>
@@ -76,7 +76,12 @@ public:<br>
       Buffers.push_back(std::move(Buffer));<br>
     }<br>
<br>
-    return BaseLayer.addObjectSet(std::move(Objects), std::move(MM));<br>
+    ModuleSetHandleT H =<br>
+      BaseLayer.addObjectSet(Objects, std::move(MM));<br>
+<br>
+    BaseLayer.takeOwnershipOfBuffers(H, std::move(Buffers));</blockquote><div><br>Could you just keep ownership on this layer, rather than passing it down? </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+    return H;<br>
   }<br>
<br>
   /// @brief Remove the module set associated with the handle H.<br>
<br>
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h?rev=227778&r1=227777&r2=227778&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h?rev=227778&r1=227777&r2=227778&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h (original)<br>
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h Sun Feb  1 22:32:17 2015<br>
@@ -61,6 +61,7 @@ protected:<br>
       RTDyld->resolveRelocations();<br>
       RTDyld->registerEHFrames();<br>
       MM->finalizeMemory();<br>
+      OwnedBuffers.clear();<br>
       State = Finalized;<br>
     }<br>
<br>
@@ -70,10 +71,19 @@ protected:<br>
       RTDyld->mapSectionAddress(LocalAddress, TargetAddress);<br>
     }<br>
<br>
+    void takeOwnershipOfBuffer(std::unique_ptr<MemoryBuffer> B) {<br>
+      OwnedBuffers.push_back(std::move(B));<br>
+    }<br>
+<br>
   private:<br>
     std::unique_ptr<RTDyldMemoryManager> MM;<br>
     std::unique_ptr<RuntimeDyld> RTDyld;<br>
     enum { Raw, Finalizing, Finalized } State;<br>
+<br>
+    // FIXME: This ownership hack only exists because RuntimeDyldELF still<br>
+    //        wants to be able to inspect the original object when resolving<br>
+    //        relocations. As soon as that can be fixed this should be removed.<br>
+    std::vector<std::unique_ptr<MemoryBuffer>> OwnedBuffers;<br>
   };<br>
<br>
   typedef std::list<LinkedObjectSet> LinkedObjectSetListT;<br>
@@ -81,6 +91,16 @@ protected:<br>
 public:<br>
   /// @brief Handle to a set of loaded objects.<br>
   typedef LinkedObjectSetListT::iterator ObjSetHandleT;<br>
+<br>
+  // Ownership hack.<br>
+  // FIXME: Remove this as soon as RuntimeDyldELF can apply relocations without<br>
+  //        referencing the original object.<br>
+  template <typename OwningMBSet><br>
+  void takeOwnershipOfBuffers(ObjSetHandleT H, OwningMBSet MBs) {<br>
+    for (auto &MB : MBs)<br>
+      H->takeOwnershipOfBuffer(std::move(MB));<br>
+  }<br>
+<br>
 };<br>
<br>
 /// @brief Default (no-op) action to perform when loading objects.<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>