<div dir="ltr"><span style="color:rgb(0,0,0);font-family:Courier;font-size:12px">Hi</span><div class="" style="color:rgb(0,0,0);font-family:Courier;font-size:12px"><br class=""></div><div class="" style="color:rgb(0,0,0);font-family:Courier;font-size:12px">I’ve previously used the ExecutionEngine::addGlobalMapping to make existing functions available to my JITed code. </div><div class="" style="color:rgb(0,0,0);font-family:Courier;font-size:12px"><br class=""></div><div class="" style="color:rgb(0,0,0);font-family:Courier;font-size:12px">I’m currently using ORC, as MCJIT does not appear to be maintained any longer (the kaleidoscope examples have not worked for some time with MCJIT). </div><div class="" style="color:rgb(0,0,0);font-family:Courier;font-size:12px"><br class=""></div><div class="" style="color:rgb(0,0,0);font-family:Courier;font-size:12px">I’m using just the basic ORC CompileLayer directly. </div><div class="" style="color:rgb(0,0,0);font-family:Courier;font-size:12px"><br class=""></div><div class="" style="color:rgb(0,0,0);font-family:Courier;font-size:12px">So, I’ve essentially copied the ExecutionEngine::addGlobalMapping related function to my JIT context, and I create a lambda resolver as such:</div><div class="" style="color:rgb(0,0,0);font-family:Courier;font-size:12px"><br class=""></div><div class="" style="color:rgb(0,0,0);font-family:Courier;font-size:12px">JITContext::addModule(…) {</div><div class="" style="color:rgb(0,0,0);font-family:Courier;font-size:12px"><br class=""></div><div class="" style="color:rgb(0,0,0);font-family:Courier;font-size:12px"><div class="" style="margin:0px"><span class="" style="color:rgb(147,26,104)">auto</span> Resolver = createLambdaResolver(</div><div class="" style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">             </span>[&](<span class="" style="color:rgb(147,26,104)">const</span> std::<span class="" style="color:rgb(0,97,65)">string</span> &name) {</div><div class="" style="margin:0px"><br class=""></div><div class="" style="margin:0px;min-height:15px"><span class="Apple-tab-span" style="white-space:pre">    </span><span class="" style="color:rgb(78,144,114)">// look up first in JIT'ed code</span></div><div class="" style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">      </span><span class="" style="color:rgb(147,26,104)">if</span> (<span class="" style="color:rgb(147,26,104)">auto</span> sym = findMangledSymbol(name)) {</div><div class="" style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">          </span><span class="" style="color:rgb(147,26,104)">return</span> <span class="" style="color:rgb(0,97,65)">RuntimeDyld</span>::<span class="" style="color:rgb(0,97,65)">SymbolInfo</span>(sym.getAddress(),</div><div class="" style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">                              </span>sym.getFlags());</div><div class="" style="margin:0px;color:rgb(0,97,65)"><span class="" style="color:rgb(0,0,0)"><span class="Apple-tab-span" style="white-space:pre">                </span></span><span class="" style="color:rgb(147,26,104)">return</span><span class="" style="color:rgb(0,0,0)"> </span>RuntimeDyld<span class="" style="color:rgb(0,0,0)">::</span>SymbolInfo<span class="" style="color:rgb(0,0,0)">(</span><span class="" style="color:rgb(147,26,104)">nullptr</span><span class="" style="color:rgb(0,0,0)">);</span></div><div class="" style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">   </span>}</div><div class="" style="margin:0px;min-height:15px"><br class=""></div><div class="" style="margin:0px;color:rgb(78,144,114)"><span class="" style="color:rgb(0,0,0)"><span class="Apple-tab-span" style="white-space:pre">        </span></span>// look up in added globals</div><div class="" style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">     </span><span class="" style="color:rgb(147,26,104)">if</span> (<span class="" style="color:rgb(147,26,104)">auto</span> addr = getPointerToGlobalMapping(name)) {</div><div class="" style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">         </span><span class="" style="color:rgb(147,26,104)">return</span> <span class="" style="color:rgb(0,97,65)">RuntimeDyld</span>::<span class="" style="color:rgb(0,97,65)">SymbolInfo</span>(addr, JITSymbolFlags::<span class="" style="color:rgb(3,38,204)">Exported</span>);</div><div class="" style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">     </span>}</div><div class="" style="margin:0px;min-height:15px"><br class=""></div><div class="" style="margin:0px;color:rgb(78,144,114)"><span class="" style="color:rgb(0,0,0)"><span class="Apple-tab-span" style="white-space:pre">        </span></span>// finally try to look up existing process symbols, note</div><div class="" style="margin:0px;color:rgb(78,144,114)"><span class="" style="color:rgb(0,0,0)"><span class="Apple-tab-span" style="white-space:pre">        </span></span>// this works for symbols loaded in shared libraries, but</div><div class="" style="margin:0px;color:rgb(78,144,114)"><span class="" style="color:rgb(0,0,0)"><span class="Apple-tab-span" style="white-space:pre">       </span></span>// does NOT seem to find symbols declared in the executable.</div><div class="" style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">    </span><span class="" style="color:rgb(147,26,104)">if</span> (<span class="" style="color:rgb(147,26,104)">auto</span> Addr =</div><div class="" style="margin:0px;color:rgb(121,61,147)"><span class="" style="color:rgb(0,0,0)"><span class="Apple-tab-span" style="white-space:pre">                    </span></span><span class="" style="color:rgb(0,97,65)">RTDyldMemoryManager</span><span class="" style="color:rgb(0,0,0)">::</span>getSymbolAddressInProcess<span class="" style="color:rgb(0,0,0)">(name)) {</span></div><div class="" style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">          </span><span class="" style="color:rgb(147,26,104)">return</span> <span class="" style="color:rgb(0,97,65)">RuntimeDyld</span>::<span class="" style="color:rgb(0,97,65)">SymbolInfo</span>(Addr, JITSymbolFlags::<span class="" style="color:rgb(3,38,204)">Exported</span>);</div><div class="" style="margin:0px"><span class="Apple-tab-span" style="white-space:pre">     </span>}</div><div class="" style="margin:0px">},</div><div class="" style="margin:0px">[](<span class="" style="color:rgb(147,26,104)">const</span> std::<span class="" style="color:rgb(0,97,65)">string</span> &S) { <span class="" style="color:rgb(147,26,104)">return</span> <span class="" style="color:rgb(147,26,104)">nullptr</span>; }</div><div class="" style="margin:0px">);</div></div><div class="" style="color:rgb(0,0,0);font-family:Courier;font-size:12px;margin:0px">}</div><div class="" style="color:rgb(0,0,0);font-family:Courier;font-size:12px;margin:0px"><br class=""></div><div class="" style="color:rgb(0,0,0);font-family:Courier;font-size:12px;margin:0px">Here the getPointerToGlobalMapping function looks in a uint64 StringMap into which values are added via the addGlobalMapping functions. </div><div class="" style="color:rgb(0,0,0);font-family:Courier;font-size:12px;margin:0px"><br class=""></div><div class="" style="color:rgb(0,0,0);font-family:Courier;font-size:12px;margin:0px"><br class=""></div><div class="" style="color:rgb(0,0,0);font-family:Courier;font-size:12px;margin:0px">This approach seems to be working, but my question is do you suppose there any are issues with such an approach? </div><div class="" style="color:rgb(0,0,0);font-family:Courier;font-size:12px;margin:0px"><br class=""></div><div class="" style="color:rgb(0,0,0);font-family:Courier;font-size:12px;margin:0px">The troubling thing is why doesn’t  <span class="" style="color:rgb(0,97,65)">RTDyldMemoryManager</span>::<span class="" style="color:rgb(121,61,147)">getSymbolAddressInProcess</span>(name)) return an address for a symbol that is defined in either a static library, or in the executable itself. </div><div class="" style="color:rgb(0,0,0);font-family:Courier;font-size:12px;margin:0px"><br class=""></div><div class="" style="color:rgb(0,0,0);font-family:Courier;font-size:12px;margin:0px">If this approach is correct, in adding the global values to the context, and looking them up the lambda resolver, in addition to looking up external symbols, and considering that the ORC kaleidoscope examples do in fact allow external function calls (which are broken currently), should they be fixed with this approach?</div></div>