Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

60.11. libunwind-23.1.2

LLVM libunwind, installed under /usr/lib/llvm-libunwind beside the system libunwind

Version 23.1.2, release 2
Shelf toolchain — The native compilers, the linker, the C library, and the LLVM family
Phase 31_compilers (Compilers), 12 of 22 in build order
Licence Apache-2.0 WITH LLVM-exception
Homepage https://libcxx.llvm.org/
Build time 1.3 SBU
Installed size 268.9 KiB in 12 files
Recipe ports/core/toolchain/libunwind/kpkgbuild

About

LLVM’s libunwind is a small C and C++ library that walks the call stack of the running process: the unwinder that C++ exceptions and _Unwind_Backtrace use in a program built against LLVM’s runtimes rather than gcc’s. It is built from the same llvm-project tarball as llvm, clang and the other runtimes of the current series.

KDOS installs it under a private prefix, /usr/lib/llvm-libunwind, with its headers in /usr/lib/llvm-libunwind/include and libunwind.so and libunwind.a in /usr/lib/llvm-libunwind/lib. The names /usr/include/libunwind.h, /usr/lib/libunwind.so and the libunwind*.pc files belong to libunwind-nongnu, the other library called libunwind, which unwinds another process through libunwind-ptrace and which programs such as htop, GStreamer, libcamera and samba link. Both projects use the same file names, so this one stays off every default search path, and no port names it in depends. Why the prefix, and how the LLVM ports share one source, is in A second version beside the first.

Why it is in KDOS

The comment above it in script/phases/31_compilers/packages.txt:

LLVM's libunwind, under /usr/lib/llvm-libunwind and nowhere directly in /usr: /usr/include/libunwind.h and libunwind.so belong to 40_lang's libunwind-nongnu, and a libunwind that held them would make that install a file conflict.

Sources

Dependencies

Depends on: llvm, python3.

Required by: no port names it.

Installation

From the repository root, inside the build container, this is the line kdosbuild runs for the port:

script/chroot/exec.sh bash -c 'source script/phases/31_compilers/phase.env && kpkg install libunwind'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/toolchain/libunwind.

1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.

cd /ports/core/toolchain/libunwind
echo 'c98bbef08a2b4c2613cd50e9aa9ae7b69b1fe6c16b2c40373bc0ab6116fdf78a  libunwind-23.1.2.tar.xz' | sha256sum -c -

2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.

SRC_ROOT=/var/cache/kpkg/work/libunwind
SRC=$SRC_ROOT/libunwind-23.1.2
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf libunwind-23.1.2.tar.xz -C "$SRC" --strip-components=1

Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.

3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the recipe’s helpers _prefix and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:

cmake -S runtimes -B build -G Ninja \
	-D CMAKE_INSTALL_PREFIX=$_prefix \
	-D CMAKE_BUILD_TYPE=Release \
	-D CMAKE_C_FLAGS_RELEASE="$CFLAGS -DNDEBUG" \
	-D CMAKE_CXX_FLAGS_RELEASE="$CXXFLAGS -DNDEBUG" \
	-D LLVM_ENABLE_RUNTIMES="libunwind" \
	-D LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF \
	-D LLVM_INCLUDE_TESTS=OFF \
	-D LIBUNWIND_INCLUDE_TESTS=OFF \
	-D LIBUNWIND_INSTALL_HEADERS=ON \
	-D LIBUNWIND_ENABLE_ASSERTIONS=OFF \
	-Wno-dev

cmake --build build
DESTDIR=$PKG cmake --install build

The switches, and why each is set:

The common switches of each build system are explained in the Flag glossary.

4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/libunwind, prunes what the image does not ship, lints the tree and rolls it reproducibly:

tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
    --mtime=@$SOURCE_DATE_EPOCH \
    --use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
    -cf libunwind-23.1.2-2.tar.xz -C "$PKG" .

5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/libunwind, and runs the triggers its paths call for.

Contents

Installed directories: /usr/lib/llvm-libunwind, /usr/share/licenses/libunwind.

Notes

The port is in 31_compilers, before 40_lang, where libunwind-nongnu installs. kpkgadd refuses a file another package owns, so a libunwind package that held /usr/include/libunwind.h or /usr/lib/libunwind.so would stop libunwind-nongnu from installing; building this port first puts its files in their prefix before that install.

lld21, the linker of the LLVM 21 slot, needs mach-o/compact_unwind_encoding.h from its own release. It carries LLVM 21’s libunwind source for that header rather than reading this port’s copy, which is the current series and is not on a default include path.