[LLVMdev] Exception handling with the LLVM makefile system

John McCall rjmccall at apple.com
Mon May 16 11:03:22 PDT 2011


On May 16, 2011, at 9:32 AM, Pablo Barrio wrote:

> On 05/16/2011 05:11 PM, Sebastian Redl wrote:
>> On 16.05.2011, at 08:44, Pablo Barrio wrote:
>> 
>>> Hi all,
>>> 
>>> I'm having trouble when trying to reuse some functions that use
>>> Boost::Exception into my LLVM-based application. As far as I know, LLVM
>>> turns off Exception handling (apparently for performance reasons), so I
>>> get the following link-time error in a few places:
>>> 
>>> "undefined reference to `boost::throw_exception(std::exception const&)"
>>> 
>>> When I compile the external code from outside the LLVM Makefile system,
>>> everything goes well. Is it possible to enable exception handling for
>>> some parts of the compilation? Just like turning on RTTI with
>>> "REQUIRES_RTTI=1" ? Removing exception handling from the functions is
>>> not an option, since I would have to tweak the Boost library internals.
>> Whatever the LLVM side of things, boost::throw_exception is a function that you, the user, have to implement when disabling exceptions. It's basically the "I want to throw an exception, so what should I really do?" callback.
>> 
>> Sebastian
> That's right, I wrote a throw_exception() function with the sole purpose 
> of avoiding error messages. However, I'm not really an expert on 
> exception handling: the function just prints out an error message. 
> boost::throw_exception allows handling exceptions just as when using the 
> C++ builtin "throw" features. The selection of either method is done by 
> defining BOOST_NO_EXCEPTIONS. I'd like to use the standard exceptions 
> instead of making my own. Do you think that's possible? Is it possible 
> (and correct) to turn on exception handling with LLVM?

You can certainly recompile LLVM with exceptions enabled, and I believe
people do.  That said, LLVM is not written to be exception-safe, and we're
not likely to accept any exception-safety patches unless they're pretty
minimal, so even if you compile LLVM with exceptions on, I would strongly
suggest never throwing through any LLVM frames.

John.



More information about the llvm-dev mailing list