LLVM libraries and custom assertions.

Is there a simple method for compiling a custom assertion header/call into all the LLVM libraries? I want my application to be able to handle any thrown assertions (ie; as an exception) and recover or crash gracefully. I already have a custom header in place in the application’s source, however this doesn’t have an effect on [most of] the already compiled lib’s.

You can consider catching SIGABRT, or maybe LD_PRELOAD'ing an
implementation for abort (not sure if the latter is possible, but
should be easy to try out). I don't know how to do better than that
without recompiling LLVM.

Another option is to let LLVM's client register an "error handler"
that gets called instead of abort() on a failed assert, but you'll
have to change and rebuild LLVM to do this (and have a non-standard
assert definition). This can be a little cleaner, depending on what
you're trying to do. I don't have a good sense of what others think
of this, but I'll be for upstreaming a mechanism of this sort to LLVM.

-- Sanjoy

Catching the error and using your own handler should be no problem. There is stuff like install_fatal_error_handler() and the CrashRecoveryContext.

However llvm today isn't really designed/tested for recovery after an error, so your milage may vary.

- Matthias

Catching SIGABRT seems reasonable for a graceful crash, but I’m also already making use of LLVM’s internal fatal_error_handler. However said handler is only called for very specific things, the rest all use direct calls to assert, do I need to disable the LLVM_ENABLE_ASSERTIONS flag to change this?

I also just noticed however that there’s an exception handler flag too, which I didn’t notice before as it’s called “LLVM_ENABLE_EH”. Will be rebuilding now with that enabled and will see if it works how I want it to, but I have to question the sensibility of naming the flag like that when there’s already flags with much longer names…?

  • Paul