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

60.10. compiler-rt-23.1.2

clang's runtime libraries — builtins, the profile runtime and UndefinedBehaviorSanitizer

Version 23.1.2, release 1
Shelf toolchain — The native compilers, the linker, the C library, and the LLVM family
Phase 31_compilers (Compilers), 11 of 22 in build order
Licence Apache-2.0 WITH LLVM-exception
Homepage https://compiler-rt.llvm.org/
Build time 2.1 SBU
Installed size 8.3 MiB in 39 files
Recipe ports/core/toolchain/compiler-rt/kpkgbuild

About

compiler-rt is clang’s runtime library set. This port builds three parts of it: the builtins with crtbegin and crtend, which --rtlib=compiler-rt links in place of GCC’s libgcc; the profile runtime, which -fprofile-instr-generate links for source-based code coverage; and UndefinedBehaviorSanitizer, which -fsanitize=undefined links. Every file goes into clang’s resource directory, /usr/lib/clang/<major>, where the driver looks for libclang_rt.*. chromium depends on it.

Of the sanitizers only UBSan is built. AddressSanitizer, ThreadSanitizer, MemorySanitizer and the others intercept glibc internals and do not support musl.

Why it is in KDOS

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

clang's own runtimes: builtins, profile (source-based coverage) and UBSan.

Sources

Dependencies

Depends on: llvm, clang, python3, cmake, ninja.

Required by (1): chromium.

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 compiler-rt'

What kpkg does

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

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/compiler-rt
echo 'c98bbef08a2b4c2613cd50e9aa9ae7b69b1fe6c16b2c40373bc0ab6116fdf78a  compiler-rt-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/compiler-rt
SRC=$SRC_ROOT/compiler-rt-23.1.2
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf compiler-rt-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 _resdir and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:

_triple=$(cc -dumpmachine)
cmake -S runtimes -B build -G Ninja \
	-D CMAKE_C_COMPILER=clang \
	-D CMAKE_CXX_COMPILER=clang++ \
	-D CMAKE_C_COMPILER_TARGET="$_triple" \
	-D CMAKE_CXX_COMPILER_TARGET="$_triple" \
	-D CMAKE_ASM_COMPILER_TARGET="$_triple" \
	-D LLVM_DEFAULT_TARGET_TRIPLE="$_triple" \
	-D CMAKE_INSTALL_PREFIX=/usr \
	-D CMAKE_BUILD_TYPE=Release \
	-D CMAKE_C_FLAGS_RELEASE="$CFLAGS -DNDEBUG" \
	-D CMAKE_CXX_FLAGS_RELEASE="$CXXFLAGS -DNDEBUG" \
	-D LLVM_ENABLE_RUNTIMES="compiler-rt" \
	-D LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF \
	-D LLVM_INCLUDE_TESTS=OFF \
	-D COMPILER_RT_INSTALL_PATH="$_resdir" \
	-D COMPILER_RT_DEFAULT_TARGET_ONLY=ON \
	-D COMPILER_RT_INCLUDE_TESTS=OFF \
	-D COMPILER_RT_BUILD_BUILTINS=ON \
	-D COMPILER_RT_BUILD_CRT=ON \
	-D COMPILER_RT_BUILD_PROFILE=ON \
	-D COMPILER_RT_BUILD_SANITIZERS=ON \
	-D COMPILER_RT_SANITIZERS_TO_BUILD="ubsan_minimal" \
	-D COMPILER_RT_BUILD_XRAY=OFF \
	-D COMPILER_RT_BUILD_LIBFUZZER=OFF \
	-D COMPILER_RT_BUILD_MEMPROF=OFF \
	-D COMPILER_RT_BUILD_ORC=OFF \
	-D COMPILER_RT_BUILD_CTX_PROFILE=OFF \
	-D COMPILER_RT_BUILD_GWP_ASAN=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/compiler-rt, 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 compiler-rt-23.1.2-1.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/compiler-rt, and runs the triggers its paths call for.

Contents

Installed directories: /usr/lib/clang/23/include/fuzzer, /usr/lib/clang/23/include/profile, /usr/lib/clang/23/include/sanitizer, /usr/lib/clang/23/lib, /usr/share/licenses/compiler-rt.

Notes

What the sanitizer switches leave installed, measured on the built tree: ubsan_standalone and ubsan_standalone_cxx (-fsanitize=undefined), ubsan_minimal, ubsan_loop_detect, lsan, stats and stats_client, all under /usr/lib/clang/<major>/lib/linux. The headers of every sanitizer are installed whatever was built, so <sanitizer/asan_interface.h> exists although no AddressSanitizer runtime does, and a -fsanitize=address link fails for want of libclang_rt.asan.

The resource directory belongs to clang’s major version. A clang and a compiler-rt of different major versions do not see each other: clang looks under its own number only.