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/
Jan Rehders
2007-Jun-12 21:08 UTC
[LLVMdev] How to call native functions from bytecode run in JIT?
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
Jan Rehders
2007-Jun-13 13:00 UTC
[LLVMdev] How to call native functions from bytecode run in JIT?
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
Chris Lattner
2007-Jun-13 17:28 UTC
[LLVMdev] How to call native functions from bytecode run in JIT?
On Tue, 12 Jun 2007, Jan Rehders wrote:> 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.That would definitely do it :)>> 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?There definitely is a bug here: your initial code should have worked. That said, noone has stepped up to fix it, and I'm busy with many other things. If you'd like to dig in and fix the bug, that would be excellent :) -Chris -- http://nondot.org/sabre/ http://llvm.org/
Apparently Analagous 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?