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
libunwind-23.1.2.tar.xz(170.9 MiB)
sha256c98bbef08a2b4c2613cd50e9aa9ae7b69b1fe6c16b2c40373bc0ab6116fdf78a
upstream: https://github.com/llvm/llvm-project/releases/download/llvmorg-23.1.2/llvm-project-23.1.2.src.tar.xz
archive copy: sources-4/toolchain--clang-23.1.2.tar.xz
Dependencies
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:
-S runtimes— Configures LLVM’sruntimes/directory, notlibunwind/. The standalonelibunwind/directory has noproject()of its own, so CMake gives it an implicit one for C and C++ only and silently drops the assembly sources; the library then lacks the routines written in assembly, and every static link against it fails on unwinder symbols.runtimes/declaresproject(Runtimes C CXX ASM). See A CMake file with no project declaration.CMAKE_INSTALL_PREFIX=$_prefix— Installs into/usr/lib/llvm-libunwind, the_prefixhelper thekpkgbuildsets, instead of/usr, for the file-name clash described above.CMAKE_C_FLAGS_RELEASE,CMAKE_CXX_FLAGS_RELEASE— Replace CMake’s Release flags,-O3 -DNDEBUG, with the tree’s$CFLAGSand$CXXFLAGSfollowed by-DNDEBUG. The optimisation level is then the tree’s-O2, and-DNDEBUGstays, as the CMake conventions ask of a recipe that sets these variables itself (see cmake).LLVM_ENABLE_RUNTIMES="libunwind"— Selects which runtimes theruntimes/build configures; naming only libunwind builds nothing else from the tarball.LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF— With it on, the library would go into a subdirectory named after the target triple,lib/x86_64-…/; off, it goes straight into/usr/lib/llvm-libunwind/lib. The on-by-default for Linux is set inllvm/CMakeLists.txt, which a configure ofruntimes/alone never reads, so here the switch names the value the build would take anyway and keeps it from depending on that. The compiler-rt and openmp ports set the same switch.LLVM_INCLUDE_TESTS=OFF,LIBUNWIND_INCLUDE_TESTS=OFF— Generate no test targets for the runtimes build or for libunwind.LIBUNWIND_INCLUDE_TESTSdefaults to the value ofLLVM_INCLUDE_TESTS, which defaults to on inruntimes/.LIBUNWIND_INSTALL_HEADERS=ON— Installs the library’s headers,libunwind.h,unwind.handmach-o/compact_unwind_encoding.hamong them, into the prefix’sinclude/. It is upstream’s default, named here.LIBUNWIND_ENABLE_ASSERTIONS=OFF— libunwind’s own switch forassert(), independent of the build type, and on by default; Release alone would leave the assertions compiled in.
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.