libunwind LLVM Unwinder

Overview

libunwind is an implementation of the interface defined by the HP libunwind project. It was contributed by Apple as a way to enable clang++ to port to platforms that do not have a system unwinder. It is intended to be a small and fast implementation of the ABI, leaving off some features of HP’s libunwind that never materialized (e.g. remote unwinding).

The unwinder has two levels of API. The high level APIs are the _Unwind_* functions which implement functionality required by __cxa_* exception functions. The low level APIs are the unw_* functions which are an interface defined by the old HP libunwind project.

Getting Started with libunwind

Building libunwind

Getting Started

On Mac OS, the easiest way to get this library is to link with -lSystem. However if you want to build tip-of-trunk from here (getting the bleeding edge), read on.

The basic steps needed to build libc++ are:

  1. Checkout LLVM:

    • cd where-you-want-llvm-to-live
    • svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
  2. Checkout libunwind:

    • cd where-you-want-llvm-to-live
    • cd llvm/runtimes
    • svn co http://llvm.org/svn/llvm-project/libunwind/trunk libunwind
  3. Configure and build libunwind:

    CMake is the only supported configuration system.

    Clang is the preferred compiler when building and using libunwind.

    • cd where you want to build llvm
    • mkdir build
    • cd build
    • cmake -G <generator> [options] <path to llvm sources>

    For more information about configuring libunwind see CMake Options.

    • make unwind — will build libunwind.
    • make check-unwind — will run the test suite.

    Shared and static libraries for libunwind should now be present in llvm/build/lib.

  4. Optional: Install libunwind

    If your system already provides an unwinder, it is important to be careful not to replace it. Remember Use the CMake option CMAKE_INSTALL_PREFIX to select a safe place to install libunwind.

    • make install-unwind — Will install the libraries and the headers

It is sometimes beneficial to build outside of the LLVM tree. An out-of-tree build would look like this:

$ cd where-you-want-libunwind-to-live
$ # Check out llvm, and libunwind
$ ``svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm``
$ ``svn co http://llvm.org/svn/llvm-project/libunwind/trunk libunwind``
$ cd where-you-want-to-build
$ mkdir build && cd build
$ export CC=clang CXX=clang++
$ cmake -DLLVM_PATH=path/to/llvm \
        path/to/libunwind
$ make
CMake Options

Here are some of the CMake variables that are used often, along with a brief explanation and LLVM-specific notes. For full documentation, check the CMake docs or execute cmake --help-variable VARIABLE_NAME.

CMAKE_BUILD_TYPE:STRING
Sets the build type for make based generators. Possible values are Release, Debug, RelWithDebInfo and MinSizeRel. On systems like Visual Studio the user sets the build type with the IDE settings.
CMAKE_INSTALL_PREFIX:PATH
Path where LLVM will be installed if “make install” is invoked or the “INSTALL” target is built.
CMAKE_CXX_COMPILER:STRING
The C++ compiler to use when building and testing libunwind.
libunwind specific options
LIBUNWIND_BUILD_32_BITS:BOOL

Default: Same as LLVM_BUILD_32_BITS

Toggle whether libunwind should be built with -m32.

LIBUNWIND_ENABLE_ASSERTIONS:BOOL

Default: ON

Toggle assertions independent of the build mode.

LIBUNWIND_ENABLE_PEDANTIC:BOOL

Default: ON

Compile with -Wpedantic.

LIBUNWIND_ENABLE_WERROR:BOOL

Default: ON

Compile with -Werror

LIBUNWIND_ENABLE_SHARED:BOOL

Default: ON

Build libunwind as a shared library.

LIBUNWIND_ENABLE_STATIC:BOOL

Default: ON

Build libunwind as a static archive.

LIBUNWIND_ENABLE_CROSS_UNWINDING:BOOL

Default: OFF

Enable cross-platform unwinding support.

LIBUNWIND_ENABLE_ARM_WMMX:BOOL

Default: OFF

Enable unwinding support for ARM WMMX registers.

LIBUNWIND_ENABLE_THREADS:BOOL

Default: ON

Build libunwind with threading support.

LIBUNWIND_TARGET_TRIPLE:STRING

Target triple for cross compiling

LIBUNWIND_GCC_TOOLCHAIN:PATH

GCC toolchain for cross compiling

LIBUNWIND_SYSROOT

Sysroot for cross compiling

Current Status

libunwind is a production-quality unwinder, with platform support for DWARF unwind info, SjLj, and ARM EHABI.

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 implemented. Remote unwinding remains as future work.

Platform and Compiler Support

libunwind is known to work on the following platforms:

OS Arch Compilers Unwind Info
Any i386, x86_64, ARM Clang SjLj
Bare Metal ARM Clang, GCC EHABI
FreeBSD i386, x86_64, ARM64 Clang DWARF CFI
iOS ARM Clang SjLj
Linux ARM Clang, GCC EHABI
Linux i386, x86_64, ARM64 Clang, GCC DWARF CFI
Mac OS X i386, x86_64 Clang, GCC DWARF CFI
NetBSD x86_64 Clang, GCC DWARF CFI
Windows i386, x86_64, ARM, ARM64 Clang DWARF CFI

The following minimum compiler versions are strongly recommended.

  • Clang 3.5 and above
  • GCC 4.7 and above.

Anything older may work.

Notes and Known Issues

  • TODO

Getting Involved

First please review our Developer’s Policy and Getting started with LLVM.

Bug Reports

If you think you’ve found a bug in libunwind, please report it using the LLVM Bugzilla. If you’re not sure, you can post a message to the cfe-dev mailing list or on IRC. Please include “libunwind” in your subject.

Patches

If you want to contribute a patch to libunwind, the best place for that is Phabricator. Please include [libunwind] in the subject and add cfe-commits as a subscriber. Also make sure you are subscribed to the cfe-commits mailing list.

Discussion and Questions

Send discussions and questions to the cfe-dev mailing list. Please include [libunwind] in the subject.