[LLVMdev] call/link to host program function

Duncan Sands baldrick at free.fr
Tue Nov 13 00:12:47 PST 2012


Hi,

On 12/11/12 20:05, edA-qa mort-ora-y wrote:
> I would like to have my IR call a function which exists in the host
> program (the one which is creating the ExecutionEngine). I don't see
> from the docs on Linker, ExecutionEngine, or Module how I would go about
> doing this.
>
> That is, I have a function like this in my C++ code:
> 	void callback( int64_t object, int32_t value );
> I would like to produce IR which links back to this function and thus
> can call back into the hosting code.
>
> The IR is built at runtime in the same program hosting this function. I
> use the JIT execution engine and then call runFunction.

if you add a declaration for your callback in the IR, and add some calls
to it, the symbol should be automatically resolved by the JIT as far as I
know (you may need to have built with libffi support).

Ciao, Duncan.




More information about the llvm-dev mailing list