LLVM Project News and Details from the Trenches

Friday, October 11, 2013

New libunwind implementation in libc++abi

Today we are happy to announce that the LLVM family of C++ support libraries is more complete than ever. To enable clang++ to port to platforms that do not have a system unwinder, Apple has contributed their unwinder implementation to LLVM. It is now dual licensed under LLVM and MIT license which is the same license as the rest of LLVM’s runtime support libraries.

The new unwinder has been added to the libcxxabi.llvm.org project.  The unwinder has two levels of API.  The high level APIs are the _Unwind_* functions which the cxa_* exception functions in libcxxabi require.  The low level APIs are the unw_* functions which are an interface defined by the the old HP libunwind project (which shares no code with this libunwind).


Most architectures now use "zero cost" exceptions for C++.   The zero cost means there are no extra instructions executed if no exceptions are thrown.  But if an exception is thrown, the runtime must consult side tables and figure out how to restore registers and "unwind" from the current stack frame to the catch clause.  That ability to modify the stack frames and cause the thread to resume in a catch clause with all registers restored properly is the main purpose of libunwind.

The new unwinder sources are known to build on Darwin, but will need some #defines configured to build on other platforms (patches welcome!).   The low level libunwind API was designed to work either in-process (aka local) or to operate on another process (aka remote), but only the local path has been completed, as that is all that C++ exceptions require.


-Nick Kledzik