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

Chris Lattner sabre at nondot.org
Mon Jun 11 15:47:12 PDT 2007


On Mon, 11 Jun 2007, Jonas Maebe wrote:
> On 11 Jun 2007, at 22:35, Jan Rehders wrote:
>> It's inside PPCJITInfo::relocate but unfortunately I could not figure
>> out anything from the source. It looks like it's calculating new
>> addresses for functions which does not make much sense for a native
>> function, at all
>
> On the PPC, unconditional branches are limited to 24 bit signed
> displacements. When you call a function in a program, the compiler
> therefore will create a stub which will indirectly load the address
> of the function (the first time it's called, usually with the help of
> the dynamic linker) and then perform an indirect branch using this
> calculated address. This stub will be placed close to the call site,
> so the displacement to the stub will be in range.

Right.

> LLVM presumably needs to generate such stubs for native functions
> introduced at run time as well, which it may not yet do. I have not
> looked into the code though, so I can't really say for sure what goes
> wrong here.

The LLVM PPC JIT certainly does produce these stubs.  The 
PPCJITInfo::emitFunctionStub method is the one that actually creates them 
:)

Jan, how are you doing this?  Are you creating an external LLVM Function 
object named "get5", then using EE::addGlobalMapping?  If 'get5' exists in 
the address space, why not just let the JIT resolve it (which will then 
create the stub)?

-Chris

-- 
http://nondot.org/sabre/
http://llvm.org/



More information about the llvm-dev mailing list