[LLVMdev] Can I get the value of the global variable defined in some module (JITing)

Kenneth Uildriks kennethuil at gmail.com
Wed May 18 05:42:46 PDT 2011


On Wed, May 18, 2011 at 4:29 AM, lost <lostfreeman at gmail.com> wrote:
> Ok, another explanation. In my runtime that uses LLVM as JIT engine, I
> have an instnace of GlobalVariable. The program I run in it writes
> some value to this variable. How can I read it?
>

Two possibilities:

1. Define the global as external in your IR, and use
ExecutionEngine::addGlobalMapping to link it to the address that your
host is writing to.  Be sure to use volatile reads, and use a volatile
pointer/global variable in your host.
2. Define the global variable as a normal global variable, and use
ExecutionEngine::getPointerToGlobal to get a pointer to it from the
JIT engine, and use that pointer in your host to write to the
variable.  Again, use volatile reads in IR and a volatile pointer in
your host.



More information about the llvm-dev mailing list