Chris Lattner
2007-Jun-11 22:47 UTC
[LLVMdev] How to call native functions from bytecode run in JIT?
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/
Jan Rehders
2007-Jun-12 01:37 UTC
[LLVMdev] How to call native functions from bytecode run in JIT?
Hi,> 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)?Yes. I create a Function with matching signature, calling conventions and external linkage which I pass together with the function's address to addGlobalMapping. I have an application which creates an execution engine and a module and creates some bytecode functions at runtime. I need to call back to some of the functions in the app (for a language runtime). What do you mean with "address space"? The function is part of the application but I don't see how LLVM would find it? If I remove the addGlobalMapping call, the function is not found at all - Jan
Andreas Eriksson
2007-Jun-12 13:25 UTC
[LLVMdev] How to call native functions from bytecode run in JIT?
Hi, I ran into the same issue some time ago, so you might find the following message from the mailing list useful. You probably want to look at some of the previous emails in the thread to get the background. http://lists.cs.uiuc.edu/pipermail/llvmdev/2006-September/006817.html / Andreas
Chris Lattner
2007-Jun-12 17:55 UTC
[LLVMdev] How to call native functions from bytecode run in JIT?
On Tue, 12 Jun 2007, Jan Rehders wrote:>> 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)? > > Yes. I create a Function with matching signature, calling conventions > and external linkage which I pass together with the function's > address to addGlobalMapping.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. Does this work? -Chris -- http://nondot.org/sabre/ http://llvm.org/
Reasonably Related Threads
- [LLVMdev] How to call native functions from bytecode run in JIT?
- [LLVMdev] How to call native functions from bytecode run in JIT?
- [LLVMdev] How to call native functions from bytecode run in JIT?
- [LLVMdev] How to call native functions from bytecode run in JIT?
- [LLVMdev] How to call native functions from bytecode run in JIT?