I am using LLVM to compile script code and then executing using the JIT compiler via the runFunction() method. The script code is contained with a C++ program compiled with G++. I am having a problem when an intrinsic function (i.e. a function implemented in C++ which is called from the LLVM compiled script) throws a C++ exception. I want the exception to be caught by the C++ code that invoked the script. Instead it appears that no exception handler is found. Does anyone know of a way to throw C++ exceptions through LLVM JITed code? To illustrate the problem a bit better, consider this psuedo code. I want the exception thrown in intrinsic_function(), which is called from the LLVM compiled code, to be caught by the exception handler at the bottom of run_program(). void intrinsic_function() { throw runtime_error("unimplemented function"); } void run_program() { char *script_code = "call intrinsic_function();"; try { myFunction = compile(script_code); Engine->runFunction(myFunction); } catch (...) { // This is never reached. } } I suspect this is not going to be possible unless somehow GCC and LLVM used the same stack structure so that the exception handling code could unwind the stack through the JITed code. Thanks, Chris. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101026/e6f49763/attachment.html>
Renato Golin
2010-Oct-26 23:18 UTC
[LLVMdev] Throwing C++ exception through LLVM JITed code
On 26 October 2010 23:43, Chris <chris at k1w1.org> wrote:> I suspect this is not going to be possible unless somehow GCC and LLVM used > the same stack structure so that the exception handling code could unwind > the stack through the JITed code.That's pretty much it. The execution engine seems to support stack unwinding: http://old.nabble.com/C%2B%2B-Exception-Handling-Problem-td22427938.html You just need to turn exception handling on in the JITed code. -- cheers, --renato http://systemcall.org/ Reclaim your digital rights, eliminate DRM, learn more at http://www.defectivebydesign.org/what_is_drm
Duncan Sands
2010-Oct-27 06:40 UTC
[LLVMdev] Throwing C++ exception through LLVM JITed code
Hi Chris,> I am using LLVM to compile script code and then executing using the JIT compiler > via the runFunction() method. The script code is contained with a C++ program > compiled with G++. I am having a problem when an intrinsic function (i.e. a > function implemented in C++ which is called from the LLVM compiled script) > throws a C++ exception. I want the exception to be caught by the C++ code that > invoked the script. Instead it appears that no exception handler is found. > > Does anyone know of a way to throw C++ exceptions through LLVM JITed code?you have to explicitly turn on JIT support for exception handling. For example with the lli tool you can say that you want this by passing the -jit-enable-eh flag on the command line. Ciao, Duncan.
Garrison Venn
2010-Oct-27 12:45 UTC
[LLVMdev] Throwing C++ exception through LLVM JITed code
See ExceptionDemo.cpp in llvm/examples/ExceptionDemo. I believe your case is covered if I understand it correctly. To run this example make sure to run make with the environmental variable BUILD_EXAMPLES set to 1. Hope this helps Garrison On Oct 26, 2010, at 18:43, Chris wrote:> I am using LLVM to compile script code and then executing using the JIT compiler via the runFunction() method. The script code is contained with a C++ program compiled with G++. I am having a problem when an intrinsic function (i.e. a function implemented in C++ which is called from the LLVM compiled script) throws a C++ exception. I want the exception to be caught by the C++ code that invoked the script. Instead it appears that no exception handler is found. > > Does anyone know of a way to throw C++ exceptions through LLVM JITed code? > > To illustrate the problem a bit better, consider this psuedo code. I want the exception thrown in intrinsic_function(), which is called from the LLVM compiled code, to be caught by the exception handler at the bottom of run_program(). > > void intrinsic_function() { > throw runtime_error("unimplemented function"); > } > > void run_program() { > char *script_code = "call intrinsic_function();"; > > try { > myFunction = compile(script_code); > Engine->runFunction(myFunction); > } catch (...) { > // This is never reached. > } > } > > I suspect this is not going to be possible unless somehow GCC and LLVM used the same stack structure so that the exception handling code could unwind the stack through the JITed code. > > Thanks, Chris. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Seemingly Similar Threads
- [LLVMdev] Catching exceptions passed through a JIT ExecutionEngine
- [LLVMdev] Catching exceptions passed through a JIT ExecutionEngine
- [LLVMdev] Throwing an exception from JITed code, and catching in C++
- KDE and mounting CD's / DVD's without noexec
- Problem making usbhid-ups working on Centos 5.7