<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">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.<div><br></div><div>In particular, LLVM throws unix signals instead of C++ exceptions while the header ErrorHandling.h contains the following warning (the last paragraph in particular):</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><span style="color: #000000">  </span>/// llvm_instal_error_handler - Installs a new error handler to be used</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><span style="color: #000000">  </span>/// whenever a serious (non-recoverable) error is encountered by LLVM.</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><span style="color: #000000">  </span>///</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><span style="color: #000000">  </span>/// (snip)</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><span style="color: #000000">  </span>///</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><span style="color: #000000">  </span>/// It is dangerous to naively use an error handler which throws an exception.</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><span style="color: #000000">  </span>/// Even though some applications desire to gracefully recover from arbitrary</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><span style="color: #000000">  </span>/// faults, blindly throwing exceptions through unfamiliar code isn't a way to</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><span style="color: #000000">  </span>/// achieve this.</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><font class="Apple-style-span" color="#000000"><br></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><font class="Apple-style-span" color="#000000">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? </font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><font class="Apple-style-span" color="#000000"><br></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><font class="Apple-style-span" color="#000000">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.</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><font class="Apple-style-span" color="#000000"><br></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><font class="Apple-style-span" color="#000000">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).</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><font class="Apple-style-span" color="#000000"><br></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><font class="Apple-style-span" color="#000000">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.</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><font class="Apple-style-span" color="#000000"><br></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><font class="Apple-style-span" color="#000000">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?</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><font class="Apple-style-span" color="#000000"><br></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><font class="Apple-style-span" color="#000000">Thanks in advance,</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><font class="Apple-style-span" color="#000000"><br></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><font class="Apple-style-span" color="#000000">Curtis</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><font class="Apple-style-span" color="#000000"><br></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><font class="Apple-style-span" color="#000000"><br></font></div></div></body></html>