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

Jan Rehders cmdkeen at gmx.de
Sat Jun 30 09:25:14 PDT 2007


Hi,

> If I recall correctly, in Linux you get the message:
>
> PPCJITInfo.cpp:382: failed assertion `ResultPtr >= -(1 << 23) &&
> ResultPtr < (1 << 23) && "Relocation out of range!"'
>
>
> Right? But on OS X you don't have this messsage?

Not exactly. There seem to be two problems. Your patch fixes one of  
them: in OS X I got the above error message when I first called a  
native function using EE->runFunction and the tried to call it again  
using a CallInst. This is fixed by your suggested patch, thank you

The other problem is that LLVM does not find any native functions in  
Linux/x86. When I try to call them using a CallInst I simply get a  
message telling me I tried to call a non-existing function and the  
abort()s. I can only call standard C functions like printf. When the  
function is provided by a loaded dll or its part of the .exe it is  
not found. The -rdynamic did not solve this either. However, the  
functions in question are found using dlsym. I currently have no idea  
how to solve this (see my previous message for various attempts and  
their results)

I will submit two bug reports when I receive my bugzilla password

Greetings,
Jan

> Here's a temporary fix until I find time to investigate on this:
>
> In function PPCISelLowering::LowerCALL, comment the lines:
>
>   if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
>     Callee = DAG.getTargetGlobalAddress(G->getGlobal(),
> Callee.getValueType());
>
> This will force an indirect call, and won't use the jump-size  
> limitation
> of the bl instruction.
>
> Let me know if this helps.
>
> Cheers,
> Nicolas
>
> Jan Rehders wrote:
>> Hi,
>>
>> attached is a small testcase I did. It builds two LLVM functions  
>> which
>> both call two native functions get5 and get6. The native functions  
>> are
>> in the exe and in the dll. On OS X it works like a charm. On Linux
>> none of the two functions can be called.
>>
>> Maybe someone can try them or have a look at it to see if there is
>> something obviously wrong
>>
>> greetings,
>> Jan
>>
>>
>>
>> --------------------------------------------------------------------- 
>> ---
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
>
> _______________________________________________
> 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