[LLVMdev] Catching Signals While JIT'ing Code
Curtis Faith
curtis at curtisfaith.com
Fri Jun 18 06:33:12 PDT 2010
I'm trying to figure out the best way to handle signals raised during the execution of LLVM's optimization passes or the JIT'ing of code prior to running it.
In particular, LLVM throws unix signals instead of C++ exceptions while the header ErrorHandling.h contains the following warning (the last paragraph in particular):
/// llvm_instal_error_handler - Installs a new error handler to be used
/// whenever a serious (non-recoverable) error is encountered by LLVM.
///
/// (snip)
///
/// It is dangerous to naively use an error handler which throws an exception.
/// Even though some applications desire to gracefully recover from arbitrary
/// faults, blindly throwing exceptions through unfamiliar code isn't a way to
/// achieve this.
I must be naive because what I'd really like to do is throw an exception. I realize there are good reasons that this might not work so I understand the comment, however, I'm curious why LLVM didn't use C++ exceptions for error recovery rather than unix signals like SIGABRT?
I figured this must have come up a few times so I did the usual Google search but didn't find any definitive relevant discussions, though I found plenty of references to the fact that LLVM uses signals and other people who wondered why. I never found a good answer nor a definitive statement of the best approach for this particular case.
So, given the fact of the current design choice, which I'm in no real position to argue was a good one or a bad one since I don't know the criteria, I want to know the best way to handle signals generated while I'm JIT'ing LLVM IR that I generated from a scripting language that I parse and output to LLVM IR within my C++ engine (which also happens to reside within a Cocoa Objective-C application world).
Ideally, I'd like to catch the signal inside a single C++ function that calls the JIT'ing code and handles the error if something goes wrong. I don't want to have to take my process down in that event. This code will be running in the same process as the user GUI, some of the time, so I can't just kill the process when that is the case.
I know others must have faced the same issue when using LLVM for embedded scripting language JIT compilation. What's the best way to encapsulate and recover from errors that occur within the LLVM JIT framework whether because of my unintentional misuse of the IR or a bug in LLVM itself?
Thanks in advance,
Curtis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100618/4207354c/attachment.html>
More information about the llvm-dev
mailing list