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
compiler-rt-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
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:
CMAKE_C_COMPILER=clang— Compiles the runtimes with clang, the compiler that links them, rather than the system’s GCC. The recipe depends on clang for this.CMAKE_CXX_COMPILER=clang++— The same for C++.CMAKE_C_COMPILER_TARGET="$_triple"— The target the runtimes are compiled for, gcc’s own triple fromcc -dumpmachine, which is also the default target of the llvm port. The C++ and assembler forms (CMAKE_CXX_COMPILER_TARGET,CMAKE_ASM_COMPILER_TARGET) are set to the same.LLVM_DEFAULT_TARGET_TRIPLE="$_triple"— The triple the runtimes build is configured for, the same one.CMAKE_C_FLAGS_RELEASE— Replaces CMake’s Release flags,-O3 -DNDEBUG, with the tree’sCFLAGSand-DNDEBUG.CMAKE_CXX_FLAGS_RELEASE— The same for C++.LLVM_ENABLE_RUNTIMES="compiler-rt"— Configures LLVM’sruntimesdirectory for this one runtime, the build upstream supports for it.LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF— Installs the libraries aslib/linux/libclang_rt.<name>-x86_64.a, with the architecture in the file name, rather than in a directory per target triple. clang’s driver looks in both places.COMPILER_RT_INSTALL_PATH="$_resdir"— Installs everything under clang’s resource directory,/usr/lib/clang/<major>, which the recipe’s_resdirhelper derives from the version, so it moves with a major-version bump of the LLVM ports.COMPILER_RT_DEFAULT_TARGET_ONLY=ON— Builds for this machine’s triple alone, rather than for every target the build could compile for.COMPILER_RT_BUILD_BUILTINS=ON— Buildslibclang_rt.builtins, the low-level arithmetic and support routines--rtlib=compiler-rtlinks.COMPILER_RT_BUILD_CRT=ON— Buildsclang_rt.crtbeginandclang_rt.crtend, the start-up and shutdown objects that go with the builtins.COMPILER_RT_BUILD_PROFILE=ON— Builds the profile runtime, which clang’s instrumentation-based profiling and source-based coverage link (llvm-profdataandllvm-covread what it writes).COMPILER_RT_BUILD_SANITIZERS=ON— Builds the sanitizer runtimes, limited by the next switch.COMPILER_RT_SANITIZERS_TO_BUILD="ubsan_minimal"— Of the sanitizers listed by name, builds only the minimal UBSan runtime, which-fsanitize-minimal-runtimelinks. The full UBSan runtime,ubsan_standalone, is not in that list and is built with the sanitizer support whatever it says.COMPILER_RT_BUILD_XRAY=OFF— No XRay function-call tracing runtime.COMPILER_RT_BUILD_LIBFUZZER=OFF— No libFuzzer, the in-process fuzzing engine-fsanitize=fuzzerlinks.COMPILER_RT_BUILD_MEMPROF=OFF— No heap profiling runtime.COMPILER_RT_BUILD_ORC=OFF— No ORC runtime, the support library of LLVM’s ORC JIT.COMPILER_RT_BUILD_CTX_PROFILE=OFF— No contextual profiling runtime.COMPILER_RT_BUILD_GWP_ASAN=OFF— No GWP-ASan, the sampling allocator that is linked into Scudo.
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.