<div dir="ltr">Hi, <div><br></div><div>I was getting started with writing my own JIT compiler, starting with the KaleidoscopeJIT example available from the LLVM git repository ( <a href="https://github.com/llvm-mirror/llvm/blob/master/examples/Kaleidoscope/include/KaleidoscopeJIT.h">https://github.com/llvm-mirror/llvm/blob/master/examples/Kaleidoscope/include/KaleidoscopeJIT.h</a> ).</div><div><br></div><div>However, even without any modifications to the example, I noticed that global variables are not being found by the lookup function in KaleidoscopeJIT.h </div><div><br></div><div>Is the way to lookup global variables somewhat different from that of the lookup for local variables and functions that works in the KaleidoscopeJIT example?</div><div><br></div><div><div class="gmail-s-prose gmail-js-post-body" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;font-size:15px;vertical-align:baseline;box-sizing:inherit;width:642px"><p style="padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;clear:both">I have an IR code generated that looks like this</p><p style="padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;clear:both">```</p><pre class="gmail-lang-cpp gmail-s-code-block gmail-hljs" style="padding:12px;border:0px;font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:1.30769;font-size:13px;vertical-align:baseline;box-sizing:inherit;width:auto;max-height:600px;overflow:auto;border-radius:5px"><code style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;background-color:transparent;white-space:inherit">ModuleID = <span class="gmail-hljs-string" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">'my jit module'</span>
source_filename = <span class="gmail-hljs-string" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">"my jit module"</span>
target datalayout = <span class="gmail-hljs-string" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"</span>
%g = type { <span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">double</span>, <span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">double</span> }
@r = common global %g
define <span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">double</span> @b() {
entry_b:
%p = alloca %g, align <span class="gmail-hljs-number" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">8</span>
%<span class="gmail-hljs-number" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">0</span> = getelementptr %g, %g* %p, i32 <span class="gmail-hljs-number" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">0</span>, i32 <span class="gmail-hljs-number" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">1</span>
store <span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">double</span> <span class="gmail-hljs-number" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">1.170000e+02</span>, <span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">double</span>* %<span class="gmail-hljs-number" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">0</span>, align <span class="gmail-hljs-number" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">8</span>
%<span class="gmail-hljs-number" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">1</span> = load %g, %g* %p, align <span class="gmail-hljs-number" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">8</span>
store %g %<span class="gmail-hljs-number" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">1</span>, %g* @r, align <span class="gmail-hljs-number" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">8</span>
%<span class="gmail-hljs-number" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">2</span> = load <span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">double</span>, <span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">double</span>* %<span class="gmail-hljs-number" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">0</span>, align <span class="gmail-hljs-number" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">8</span>
ret <span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">double</span> %<span class="gmail-hljs-number" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">2</span>
}
</code></pre><p style="padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;clear:both">```</p><p style="padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;clear:both">However, when the JIT compiler tries to compile the function "b", I get an error saying</p><p style="padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;clear:both">```</p><pre class="gmail-lang-sh gmail-s-code-block gmail-hljs gmail-bash" style="padding:12px;border:0px;font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:1.30769;font-size:13px;vertical-align:baseline;box-sizing:inherit;width:auto;max-height:600px;overflow:auto;border-radius:5px"><code style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;background-color:transparent;white-space:inherit">Failure value returned from cantFail wrapped call
Symbols not found: [ _r ]
</code></pre><p style="padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;clear:both">```</p><p style="padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;clear:both">The error occurs when trying to compile the IR code line</p><p style="padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;clear:both">```</p><pre class="gmail-lang-cpp gmail-s-code-block gmail-hljs" style="padding:12px;border:0px;font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:1.30769;font-size:13px;vertical-align:baseline;box-sizing:inherit;width:auto;max-height:600px;overflow:auto;border-radius:5px"><code style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;background-color:transparent;white-space:inherit">store %g %<span class="gmail-hljs-number" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">1</span>, %g* @r, align <span class="gmail-hljs-number" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">8</span>
</code></pre><p style="padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;clear:both">```</p><p style="padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;clear:both">as the JIT is not able to find the symbol corresponding to the global variable "r" in the symbol table of the JIT.</p><p style="padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;clear:both">The relevant lines from the Kaleidoscope JIT seem to be</p><p style="padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;clear:both">```</p><pre class="gmail-lang-cpp gmail-s-code-block gmail-hljs" style="padding:12px;border:0px;font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:1.30769;font-size:13px;vertical-align:baseline;box-sizing:inherit;width:auto;max-height:600px;overflow:auto;border-radius:5px"><code style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;background-color:transparent;white-space:inherit"> <span class="gmail-hljs-function" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">JITSymbol <span class="gmail-hljs-title" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">findSymbol</span><span class="gmail-hljs-params" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">(<span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">const</span> <span class="gmail-hljs-built_in" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">std</span>::<span class="gmail-hljs-built_in" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">string</span> Name)</span> </span>{
<span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">return</span> findMangledSymbol(mangle(Name));
}
<span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">private</span>:
<span class="gmail-hljs-function" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit"><span class="gmail-hljs-built_in" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">std</span>::<span class="gmail-hljs-built_in" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">string</span> <span class="gmail-hljs-title" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">mangle</span><span class="gmail-hljs-params" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">(<span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">const</span> <span class="gmail-hljs-built_in" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">std</span>::<span class="gmail-hljs-built_in" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">string</span> &Name)</span> </span>{
<span class="gmail-hljs-built_in" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">std</span>::<span class="gmail-hljs-built_in" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">string</span> MangledName;
{
<span class="gmail-hljs-function" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">raw_string_ostream <span class="gmail-hljs-title" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">MangledNameStream</span><span class="gmail-hljs-params" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">(MangledName)</span></span>;
Mangler::getNameWithPrefix(MangledNameStream, Name, DL);
}
<span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">return</span> MangledName;
}
<span class="gmail-hljs-function" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">JITSymbol <span class="gmail-hljs-title" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">findMangledSymbol</span><span class="gmail-hljs-params" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">(<span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">const</span> <span class="gmail-hljs-built_in" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">std</span>::<span class="gmail-hljs-built_in" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">string</span> &Name)</span> </span>{
<span class="gmail-hljs-comment" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">// ...</span>
<span class="gmail-hljs-comment" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">// Search modules in reverse order: from last added to first added.</span>
<span class="gmail-hljs-comment" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">// This is the opposite of the usual search order for dlsym, but makes more</span>
<span class="gmail-hljs-comment" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">// sense in a REPL where we want to bind to the newest available definition.</span>
<span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">for</span> (<span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">auto</span> H : make_range(ModuleKeys.rbegin(), ModuleKeys.rend()))
<span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">if</span> (<span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">auto</span> Sym = CompileLayer.findSymbolIn(H, Name, ExportedSymbolsOnly))
<span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">return</span> Sym;
<span class="gmail-hljs-comment" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">// ... </span>
<span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">return</span> <span class="gmail-hljs-literal" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">nullptr</span>;
}
</code></pre><p style="padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;clear:both">```</p><p style="padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;clear:both">The symbol name for "r", gets mangled to "_r" and is looked up in the module. When not found, nullptr is returned by the findMangledSymbol function. When debugging with breakpoints, I can see that nullptr is indeed being returned.</p><p style="padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;clear:both">Is there some modification that needs to be done to the above JIT lookup in order to find global variables, is there a separate symbol table or different mangling that is required?</p><p style="padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;clear:both">Could you point me to the right document sources or the right modifications that might be required?</p><p style="padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;clear:both">The way I call the JIT compiler on the module is:</p><pre class="gmail-lang-cpp gmail-s-code-block gmail-hljs" style="margin-top:0px;margin-bottom:0px;padding:12px;border:0px;font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:1.30769;font-size:13px;vertical-align:baseline;box-sizing:inherit;width:auto;max-height:600px;overflow:auto;border-radius:5px"><code style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;background-color:transparent;white-space:inherit"> TheJIT->addModule(<span class="gmail-hljs-built_in" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">std</span>::move(TheModule));
<span class="gmail-hljs-comment" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">// evaluate things from the module</span>
<span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">auto</span> ExprSymbol = TheJIT->findSymbol(<span class="gmail-hljs-string" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">"b"</span>);
assert(ExprSymbol && <span class="gmail-hljs-string" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">"Function not found"</span>);
<span class="gmail-hljs-comment" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">// Get the symbol's address and cast it to the right type</span>
<span class="gmail-hljs-comment" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">// call the function b</span>
<span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">double</span> (*FP)() = (<span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">double</span> (*)())(<span class="gmail-hljs-keyword" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">intptr_t</span>)llvm::cantFail(ExprSymbol.getAddress()); <span class="gmail-hljs-comment" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit">// (THIS IS WHERE THE ERROR IS ENCOUNTERED)</span>
</code></pre></div><div class="gmail-mt24 gmail-mb12" style="margin:24px 0px 12px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-size:13px;vertical-align:baseline;box-sizing:inherit"><div class="gmail-post-taglist gmail-grid gmail-gs4 gmail-gsy gmail-fd-column" style="padding:0px;border:0px;font-family:Arial,"Helvetica Neue",Helvetica,sans-serif;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;display:flex;clear:both;color:rgb(231,232,235)"><div class="gmail-grid gmail-ps-relative" style="margin:2px 0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;font-variant-caps:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseline;box-sizing:inherit;display:flex"></div></div><br class="gmail-Apple-interchange-newline"></div></div></div>