<div dir="ltr"><a class="GWVZpf gW" id="IloFPc-0" href="mailto:lhames@gmail.com" tabindex="-1">+Lang Hames</a>, Master Regent of the Three <No, Two sir> JITs<br><br><div class="gmail_quote"><div dir="ltr">On Thu, Jul 28, 2016 at 12:31 PM Sean Ogden via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I needed to be able to update stub pointers for hot functions that get recompiled in a lazy JIT that uses CompileOnDemandLayer.  In order to do this I added a method that allows pointers to be updated but does not expose any of the other internals of the COD layer.<div><br></div><div>Does anyone have a cleaner way to do this?  Has something to facilitate this already been added?  Would it be possible to merge this in?<br><div><br></div><div><div><font color="#333333">diff --git a/CompileOnDemandLayer.h b/CompileOnDemandLayer.h</font></div><div><font color="#333333">index bd192b8..4aa3362 100644</font></div><div><font color="#333333">--- a/CompileOnDemandLayer.h</font></div><div><font color="#333333">+++ b/CompileOnDemandLayer.h</font></div><div><font color="#333333">@@ -429,6 +429,28 @@ private:</font></div><div><font color="#333333">     return CalledAddr;</font></div><div><font color="#333333">   }</font></div><div><font color="#333333"><br></font></div><div><font color="#333333">+public:</font></div><div><font color="#333333">+  TargetAddress updatePointer(std::string FuncName, TargetAddress FnBodyAddr) {</font></div><div><font color="#333333">+    //Find out which logical dylib contains our symbol</font></div><div><font color="#333333">+    auto LDI = LogicalDylibs.begin();</font></div><div><font color="#333333">+    for (auto LDE = LogicalDylibs.end(); LDI != LDE; ++LDI) {</font></div><div><font color="#333333">+        if (auto LMResources = LDI->getLogicalModuleResourcesForSymbol(FuncName, false)) {</font></div><div><font color="#333333">+            Module &SrcM = LMResources->SourceModule->getResource();</font></div><div><font color="#333333">+            std::string CalledFnName = mangle(FuncName, SrcM.getDataLayout());</font></div><div><font color="#333333">+            if (auto EC = LMResources->StubsMgr->updatePointer(CalledFnName, FnBodyAddr)) {</font></div><div><font color="#333333">+                return 0;</font></div><div><font color="#333333">+            }</font></div><div><font color="#333333">+            else</font></div><div><font color="#333333">+                return FnBodyAddr;</font></div><div><font color="#333333">+        }</font></div><div><font color="#333333">+    }</font></div><div><font color="#333333">+    return 0;</font></div><div><font color="#333333">+  }</font></div><div><font color="#333333">+</font></div><div><font color="#333333">+private:</font></div></div><div><font color="#333333"><br></font></div><div><font color="#333333"><br></font></div><div><font color="#333333"><div>diff --git a/LogicalDylib.h b/LogicalDylib.h</div><div>index 84e3bf5..2e35cfd 100644</div><div>--- a/LogicalDylib.h</div><div>+++ b/LogicalDylib.h</div><div>@@ -17,6 +17,8 @@</div><div> #include "JITSymbol.h"</div><div> #include <string></div><div> #include <vector></div><div>+#include "llvm/IR/Mangler.h"</div><div>+#include "llvm/Support/raw_ostream.h"</div><div><br></div><div> namespace llvm {</div><div> namespace orc {</div><div>@@ -77,6 +79,24 @@ public:</div><div>     return LMH->Resources;</div><div>   }</div><div><br></div><div>+  static std::string mangle(StringRef Name, const DataLayout &DL) {</div><div>+    std::string MangledName;</div><div>+    {</div><div>+      raw_string_ostream MangledNameStream(MangledName);</div><div>+      Mangler::getNameWithPrefix(MangledNameStream, Name, DL);</div><div>+    }</div><div>+    return MangledName;</div><div>+  }</div><div>+</div><div>+  LogicalModuleResources* getLogicalModuleResourcesForSymbol(const std::string &Name, bool ExportedSymbolsOnly) {</div><div>+    for (auto LMI = LogicalModules.begin(), LME = LogicalModules.end();</div><div>+         LMI != LME; ++LMI)</div><div>+      if (auto Sym = findSymbolInLogicalModule(LMI, mangle(Name,LMI->Resources.SourceModule->getResource().getDataLayout()), ExportedSymbolsOnly))</div><div>+          return &LMI->Resources;</div><div>+    return nullptr;</div><div>+  }</div><div>+</div><div>+</div><div><br></div><div><br></div><div><br></div></font></div><div><br></div></div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>