[libcxxabi][PATCH] unwinder

Nick Kledzik kledzik at apple.com
Thu Oct 3 10:36:20 PDT 2013


libcxxabi contains the runtime support for C++.  But, as some folks have realized, it is not complete.  It relies on some _Unwind_* functions to be supplied by the OS.  That means it cannot be ported to platforms that don’t already have an unwinder.  

Years ago Apple wrote its own unwinder for MacOSX and iOS.  To make libcxxabi complete, Apple has decided the source code for its unwinder can be contributed to the open source LLVM libcxxabi project, with a dual licensed under LLVM and MIT license.

So, I’ve spent some time cleaning up the sources to make them conform with LLVM style and to conditionalize the sources in a way that should make it easier to port to other platforms.  The sources are in a separate “Unwind” directory under “src” in libcxxabi.  I am submitting this patch for review.

Background:
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 the unwinder.

This 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 unwinder).

Getting started:
I’ve verified this patch builds and runs on iOS and MacOSX.  To build on another platform, you’ll first need to update src/Unwind/config.h and add defines for the various _LIBUNWIND_* conditionals.  Then there are a few spots to implement platform specific code such as LocalAddressSpace::findUnwindSections() which will need to return the address of the dwarf unwind section (e.g. .eh_frame).  You’ll also need to modify the buildit script (or whatever additional make system you have for libcxxabi) to start building the new sources.

-Nick

-------------- next part --------------
A non-text attachment was scrubbed...
Name: libunwind.patch
Type: application/octet-stream
Size: 312186 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131003/44ab756d/attachment.obj>


More information about the cfe-commits mailing list