[LLVMdev] How to call native functions from bytecode run in JIT?

Jan Rehders cmdkeen at gmx.de
Wed Jun 13 06:00:16 PDT 2007


Hi,

I was able to try this on linux again. Unfortunately it doesn't work  
at all (neither using runFunction nor a CallInst). It simply says  
function called get5 not known. Calling printf the same way works,  
though. On linux the function is exported as "get5" from the  
executable while it is called "_get5" on OS X. I could not spot any  
other differences.. any thoughts?

greetings,
Jan

On 12. Jun 2007, at 23:08, Jan Rehders wrote:

> Hi,
>
>> Okay.  If the function exists in your application's address space
>> already,
>> just name the LLVM function the same name as the native function
>> and the
>> JIT should find it an do the right thing.  This is how it finds
>> printf and
>> a variety of other things.  You don't need to call  
>> addGlobalMapping at
>> all.
>
> Looking at the output of "nm codegen1" I realized that "get5" was a C+
> + function whose name was mangled to "__Z4get5v". Surrounding it by
> extern "C" helped a lot :) Now the function is found by the JIT and I
> can call it using EE->runFunction als well as using a CallInst.
>
>> Does this work?
>
> However, one strange effet remains: if I first call the function
> using EE->runFunction and then try to call it using a CallInst inside
> another function I get the old "relocation" error in PPCJITInfo.cpp,
> again. Using a CallInst first, then runFunction and then a CallInst
> again works, though. For my project this is probably a non-issue but
> it might indicate some problem in either my code or LLVM - any ideas?
>
> Anyway, thank you all for the helpful comments. I'd surely yielded to
> despair without your help :)
>
> - Jan
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list