I'm developing an OpenGL shader-like language, using LLVM as the JIT engine.
For some circumstances or exceptions I would like to abort the script, by
throwing an exception back to the code that called the
Initially I had problems throwing exceptions from functions called from the
JIT code, where the JIT code would handle the exceptions, but this was
solved by setting llvm::ExceptionHandling to true. However, now I'm trying
to abort the script all together, by throwing an (by the script) unhandled
As a proof-of-concept I used the online demo generator to generate C++ code
for the following script;
I added llvm::ExceptionHandling = true, an ExecutionEngine and
try/catch(...) statements around the runFunction, and changed the
setTargetTriple to the correct value ("i386-apple-darwin"). The result is
the same to all my other experiments, in that it aborts with the message
"terminate called after throwing an instance of 'int'".
If I add a function that calls the same test() function (embraced by
try/catch(...)) from within the JIT, the exception is handled properly
within that function.
The questions are;
a) Is this a feasible way of aborting runnning JIT code,
b) Should it work, and if so, what am I doing wrong.
c) If not, are there any alternatives to abort running JIT code, even over
nested functions (apart from generating stubs function with try/catch
constructs to call the user-defined function.
Thanks in advance for your response,
PS: The stack backtrace is as follows;
#0 0x94586e42 in __kill ()
#1 0x94586e34 in kill$UNIX2003 ()
#2 0x945f923a in raise ()
#3 0x94605679 in abort ()
#4 0x91754005 in __gnu_cxx::__verbose_terminate_handler ()
#5 0x9175210c in __gxx_personality_v0 ()
#6 0x9175214b in std::terminate ()
#7 0x91752261 in __cxa_throw ()
#8 0x02080045 in ?? ()
#9 0x000056ef in main (argc=1, argv=0xbffff82c) at
PPS: I also tried to longjmp from the JIT code, back to my code, but this
ofcourse violates a lot of C++ stack cleanup rules.