5.5. LLVM runtimes (libunwind, libcxxabi, libcxx) 22.1.3

This pass builds and installs the LLVM C++ runtime stack against musl, so later C++ builds have unwinding, ABI support, and the C++ standard library available in the target tree.

Input assumption: llvm-project-22.1.3.src.tar.xz is already present from the chapter 4 manifest fetch step, and section 5.4 completed successfully so musl is available in the target tree.

libunwind is a platform-independent stack unwinding library. we need it to provide the unwinder used by C++ exception handling in this book.

libcxxabi is the LLVM C++ ABI support library. we need it to provide C++ ABI and exception runtime support required by libcxx.

libcxx is the LLVM C++ standard library implementation. we need it to provide the C++ standard library used by Clang in later stages of this book.

Extract Sources and Create a Build Directory

cd "$LBI_SOURCES"
tar -xf llvm-project-22.1.3.src.tar.xz
cd llvm-project-22.1.3.src/runtimes

Configure LLVM Runtimes for musl

lbi_cmake build-runtimes \
    -G Ninja \
    -DCMAKE_C_COMPILER="$LBI_ROOT/system/tools/bin/$LBI_TARGET-clang" \
    -DCMAKE_CXX_COMPILER="$LBI_ROOT/system/tools/bin/$LBI_TARGET-clang++" \
    -DCMAKE_SYSROOT="$LBI_ROOT" \
    -DCMAKE_FIND_ROOT_PATH="$LBI_ROOT;$LBI_ROOT/system" \
    -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
    -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
    -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
    -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY \
    -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY \
    -DCMAKE_C_FLAGS="--target=$LBI_TARGET" \
    -DCMAKE_CXX_FLAGS="--target=$LBI_TARGET" \
    -DLLVM_ENABLE_RUNTIMES="libunwind;libcxxabi;libcxx" \
    -DLIBUNWIND_INSTALL_LIBRARY_DIR=/system/libraries \
    -DLIBCXXABI_INSTALL_LIBRARY_DIR=/system/libraries \
    -DLIBCXX_INSTALL_LIBRARY_DIR=/system/libraries \
    -DLLVM_ENABLE_ZLIB=OFF \
    -DLLVM_ENABLE_ZSTD=OFF \
    -DLLVM_ENABLE_LIBXML2=OFF \
    -DLIBCXX_HAS_MUSL_LIBC=ON \
    -DLIBCXX_HAS_ATOMIC_LIB=OFF \
    -DLIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL=OFF \
    -DLIBCXXABI_USE_LLVM_UNWINDER=ON \
    -DLIBCXX_USE_COMPILER_RT=ON \
    -DLIBCXXABI_USE_COMPILER_RT=ON \
    -DLIBUNWIND_USE_COMPILER_RT=ON \
    -DCMAKE_BUILD_TYPE=Release

Build LLVM Runtimes

ninja -C build-runtimes $LWI_MAKE_FLAGS

Install LLVM Runtimes into the Target Tree

DESTDIR="$LBI_ROOT" ninja -C build-runtimes install

Command Explanations

For additional runtime configuration details and accepted CMake options, see upstream documentation: