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
-G Ninja: Uses the Ninja generator for fast incremental builds.lbi_cmake build-runtimes ...: Uses the book's CMake helper so install layout follows the environment policy (/binaries,/systembinaries,/libraries,/headers,/configuration,/variable, and documentation paths) instead of defaulting to/usr.-DCMAKE_C_COMPILER="$LBI_ROOT/system/tools/bin/$LBI_TARGET-clang": Uses the pass 1 target-prefixed Clang C compiler.-DCMAKE_CXX_COMPILER="$LBI_ROOT/system/tools/bin/$LBI_TARGET-clang++": Uses the pass 1 target-prefixed Clang C++ compiler.-DCMAKE_SYSROOT="$LBI_ROOT": Directs configure and compile checks at the target sysroot.-DCMAKE_FIND_ROOT_PATH="$LBI_ROOT;$LBI_ROOT/system": Restricts CMake's search roots to the target tree.-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER: Lets build-time tools (likecmake,ninja, and scripting runtimes) come from the host.-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY: Prevents linking target libraries from host paths such as/usr/lib.-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY: Prevents header discovery from host include paths.-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY: Forces package discovery into target roots instead of host package locations.-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY: Prevents CMake's compiler checks from requiring an executable link againstlibc++beforelibc++has been built.-DCMAKE_C_FLAGS="--target=$LBI_TARGET": Ensures C compilation targets the selected triple.-DCMAKE_CXX_FLAGS="--target=$LBI_TARGET": Ensures C++ compilation targets the selected triple.-DLLVM_ENABLE_RUNTIMES="libunwind;libcxxabi;libcxx": Builds exactly the unwinder, C++ ABI runtime, and C++ standard library runtimes.-DLIBUNWIND_INSTALL_LIBRARY_DIR=/system/libraries,-DLIBCXXABI_INSTALL_LIBRARY_DIR=/system/libraries,-DLIBCXX_INSTALL_LIBRARY_DIR=/system/libraries: Forces each runtime project to install its libraries into/system/libraries, because these projects can ignore genericCMAKE_INSTALL_LIBDIRdefaults.-DLLVM_ENABLE_ZLIB=OFF,-DLLVM_ENABLE_ZSTD=OFF,-DLLVM_ENABLE_LIBXML2=OFF: Disables optional compression/XML dependencies in this pass so hostfind_packagehits do not leak into the runtime bootstrap.-DLIBCXX_HAS_MUSL_LIBC=ON: Enables libcxx musl-specific behavior for the target libc environment.-DLIBCXX_HAS_ATOMIC_LIB=OFF: Prevents libcxx from linking-latomicas an external library in this pass.-DLIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL=OFF: Prevents libcxxabi from requiring glibc's__cxa_thread_atexit_implsymbol, which is not provided by musl.-DLIBCXXABI_USE_LLVM_UNWINDER=ON: Configures libcxxabi to use libunwind from this runtime set.-DLIBCXX_USE_COMPILER_RT=ON: Uses compiler-rt runtime libraries when building libcxx.-DLIBCXXABI_USE_COMPILER_RT=ON: Uses compiler-rt runtime libraries when building libcxxabi.-DLIBUNWIND_USE_COMPILER_RT=ON: Uses compiler-rt runtime libraries when building libunwind.-DCMAKE_BUILD_TYPE=Release: Uses release optimizations for runtime libraries.DESTDIR="$LBI_ROOT" ninja -C build-runtimes install: Installs into the target tree without writing to the host filesystem.
For additional runtime configuration details and accepted CMake options, see upstream documentation: