5.3. llvm/clang pass 1 22.1.3
The first llvm/clang pass establishes an initial toolchain in the tools prefix so later stages, including compiler-rt, can build against a controlled compiler and linker set.
llvm-project-22.1.3.src.tar.xz is already present from the chapter 4 manifest fetch step.
llvm/clang is a modular compiler and linker toolchain project. we need it to produce the pass 1 compiler components (clang, lld) used by later runtime work, including compiler-rt.
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
mkdir -p build-llvm
cd build-llvm
Configure llvm/clang Pass 1
cmake -G Ninja "../llvm" \
-DCMAKE_C_COMPILER=/usr/bin/clang \
-DCMAKE_CXX_COMPILER=/usr/bin/clang++ \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_INSTALL_PREFIX=$LBI_ROOT/system/tools \
-DLLVM_ENABLE_PROJECTS="lld;clang" \
-DLLVM_ENABLE_RUNTIMES="compiler-rt" \
-DCOMPILER_RT_BUILD_BUILTINS=ON \
-DCOMPILER_RT_BUILD_SANITIZERS=OFF \
-DCOMPILER_RT_BUILD_XRAY=OFF \
-DCOMPILER_RT_BUILD_LIBFUZZER=OFF \
-DCOMPILER_RT_BUILD_PROFILE=OFF \
-DLLVM_DEFAULT_TARGET_TRIPLE="$LBI_TARGET" \
-DLLVM_TARGETS_TO_BUILD="X86" \
-DCMAKE_BUILD_TYPE=Release \
-DCLANG_DEFAULT_CXX_STDLIB=libc++ \
-DCLANG_DEFAULT_LINKER=lld \
-DCLANG_DEFAULT_RTLIB=compiler-rt \
-DDEFAULT_SYSROOT=$LBI_ROOT
Build llvm/clang Pass 1
ninja $LWI_MAKE_FLAGS
Install llvm/clang Pass 1 to the temp tools directory
ninja install
Command Explanations
-G Ninja: Uses the Ninja generator for fast incremental builds.-DCMAKE_C*_COMPILER=/usr/bin/clang*: Forces Clang as the C and C++ compilers for pass 1. Remove these if you don't have clang installed, but clang is faster for the 4000+ source files in this pass.-DCMAKE_C_COMPILER_LAUNCHER=ccache: Enablesccachefor C compilations to speed rebuilds.-DCMAKE_CXX_COMPILER_LAUNCHER=ccache: Enablesccachefor C++ compilations to speed rebuilds.-DCMAKE_INSTALL_PREFIX=$LBI_ROOT/system/tools: Installs pass 1 outputs into the tools prefix used by later stages.-DLLVM_ENABLE_PROJECTS="lld;clang": Builds only theclangandlldprojects from the LLVM monorepo.-DLLVM_ENABLE_RUNTIMES="compiler-rt": Enablescompiler-rtin the runtimes build.-DCOMPILER_RT_BUILD_BUILTINS=ON: Builds compiler-rt builtins.-DCOMPILER_RT_BUILD_SANITIZERS=OFF: Skips sanitizer runtime libraries in this pass.-DCOMPILER_RT_BUILD_XRAY=OFF: Skips XRay runtime components in this pass.-DCOMPILER_RT_BUILD_LIBFUZZER=OFF: Skips libFuzzer runtime components in this pass.-DCOMPILER_RT_BUILD_PROFILE=OFF: Skips profile runtime components in this pass.-DLLVM_DEFAULT_TARGET_TRIPLE="$LBI_TARGET": Sets the default target triple for generated code.-DLLVM_TARGETS_TO_BUILD="X86": Restricts LLVM backend generation to the selected architecture.-DCMAKE_BUILD_TYPE=Release: Uses release optimizations for a stable bootstrap toolchain.-DCLANG_DEFAULT_CXX_STDLIB=libc++: Makes Clang default tolibc++as its C++ standard library.-DCLANG_DEFAULT_LINKER=lld: Makes Clang default tolldas its linker.-DCLANG_DEFAULT_RTLIB=compiler-rt: Makes Clang default tocompiler-rtruntime libraries.-DDEFAULT_SYSROOT=$LBI_ROOT: Sets the default sysroot for clang to the root prefix, so it can find headers and libraries from pass 1 and later stages, so it doesn't use host system headers and libraries by mistake.
This pass 1 configuration keeps compiler-rt limited to builtins-only output.
ccache is recommended, but not required. If ccache is not installed on your host, remove the two CMAKE_*_COMPILER_LAUNCHER lines and re-run configure.
For accepted LLVM_TARGETS_TO_BUILD values, choose the target that matches your architecture and verify against upstream documentation:
Create Target-Prefixed llvm Tool Symlinks
Some builds expect cross-style tool names like $LBI_TARGET-ld. Create symlinks for the installed LLVM tools so those names resolve in $LBI_ROOT/system/tools/bin.
cd "$LBI_ROOT/system/tools/bin"
ln -sf clang "$LBI_TARGET-clang"
ln -sf clang++ "$LBI_TARGET-clang++"
ln -sf clang "$LBI_TARGET-cc"
ln -sf clang++ "$LBI_TARGET-c++"
ln -sf llvm-ar "$LBI_TARGET-ar"
ln -sf llvm-ranlib "$LBI_TARGET-ranlib"
ln -sf llvm-as "$LBI_TARGET-as"
ln -sf llvm-nm "$LBI_TARGET-nm"
ln -sf llvm-objcopy "$LBI_TARGET-objcopy"
ln -sf llvm-objdump "$LBI_TARGET-objdump"
ln -sf llvm-readelf "$LBI_TARGET-readelf"
ln -sf llvm-strip "$LBI_TARGET-strip"
ln -sf ld.lld "$LBI_TARGET-ld"