<div dir="ltr"><div>Hi Lang,</div><div><br></div>That's exactly what it was. <div><br></div><div>Thanks a heap.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 14, 2015 at 5:44 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"><div dir="ltr">Hi Tarun,<div><br></div><div>My first thought is that you might be adding a definition (e.g. @x = global i32 7) to your module, rather than an external declaration (e.g. @x = external global i32). Make sure you have the latter: If you provide a definition in your module it will shadow any definitions in your mapping, which would explain the behavior you're seeing.</div><div><br></div><div>Cheers,</div><div>Lang.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Mon, Sep 14, 2015 at 2:55 PM, Tarun Prabhu via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Hi,<div><br></div><div>I think this is probably easiest to explain with code (I only provided the essentials for clarity):</div><div><br></div><div>// begin file jit.cpp</div><div><br></div><div><div>int myglobal;</div><div><br></div><div>void printMyGlobal() {</div><div>  printf("myglobal: %d\n", myglobal);</div><div>}</div><div><br></div><div>int main(int argc, char *argv[]) {</div><div><br></div><div>  // This file, jit.cpp has been compiled to bitcode (clang -S -emit-llvm jit.cpp)</div><div>  // and is read into Module M here</div><div>  Module *M = ... <br></div><div>  ExecutionEngine *ee = ...</div><div><br></div><div>  myglobal = 42;</div><div><br></div><div>  ee->addGlobalMapping(M->getGlobalVariable("myglobal"), (void*)&myglobal);<br></div><div>  ee->finalizeObject();</div><div><br></div><div>  void(*fptr)() = (void(*)())ee->getFunctionAddress("printMyGlobal");<br></div><div>  fptr();</div><div>  printMyGlobal();<br></div></div><div>}</div><div><br></div><div>// end file jit.cpp</div><div><br></div><div>I compile this file (jit.cpp) into bitcode which I then load int M. M  also contains a global variable called myglobal. I want to "map" the myglobal variable in M to the global variable in the running program. The idea is that the value of myglobal inside the JIT'ted module will also be 42. However, as it is right now, when I run the code, I get:</div><div><br></div><div>myglobal: 0</div><div>myglobal: 42</div><div><br></div><div>The first is the JIT'ted printMyGlobal() and the second is the AOT'ed printMyGlobal(). But when I lookup the address of the global variable myglobal (ee->getGlobalValueAddress()), it is mapped to the correct address. Similarly, if I lookup ee->getGlobalValueAtAddress(), I get the expected result.</div><div><br></div><div>Am I missing an important step? Is what I am trying to do even possible? </div><div><br></div><div>Thanks for the help. </div><span><font color="#888888"><div><br></div><div>Tarun</div><div><br></div></font></span></div>
<br></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>
<br></blockquote></div><br></div>
</blockquote></div><br></div>