LLVM-21.1.8

#### Gaming Linux® From Scratch - Version 13.0

### Chapter 6. Tooling

- Prev

  CMake-4.2.3

- Next

  Rustc-1.93.1

- Up
- Home

# LLVM-21.1.8

## Introduction to LLVM

The LLVM package contains a collection of modular and reusable compiler and toolchain technologies. The Low Level Virtual Machine (LLVM) Core libraries provide a modern source and target-independent optimizer, along with code generation support for many popular CPUs, as well as some less common ones. These libraries are built around a well specified code representation known as the LLVM intermediate representation ("LLVM IR").

Clang provides new C, C++, Objective C and Objective C++ front-ends for LLVM and is required by some desktop packages such as Firefox and for Rustc-1.93.1 if that is built using the system LLVM.

The Compiler RT package provides runtime sanitizer and profiling libraries for developers who use Clang and LLVM.

The below instructions will install all of these projects, though you may wish to skip installing some of the optional packages.

### Note

This may take a while to build. Feel free to do something else while this is building.

- Download: https://github.com/llvm/llvm-project/releases/download/llvmorg-21.1.8/

### LLVM Dependencies

Required
CMake-4.2.3

## Downloading LLVM tarballs

The tarballs that are to be downloaded are poorly named and may conflict with other present tarballs that may be in the current directory. The instructions below work around this by putting the tarballs in a new directory so they are isolated.

First, create a list of files to be downloaded:

    cat > llvm-21.1.8-list << "EOF"
    # The three tarballs below are required
    llvm-21.1.8.src.tar.xz
    cmake-21.1.8.src.tar.xz
    third-party-21.1.8.src.tar.xz

    # The following clang tarball is for Clang (Recommended)
    clang-21.1.8.src.tar.xz

    # The following compiler-rt tarball is for Compiler RT (Recommended)
    compiler-rt-21.1.8.src.tar.xz
    EOF

To download the needed files using Wget-1.25.0, use the following commands:

    mkdir llvm &&
    cd llvm &&
    grep -v '^#' ../llvm-21.1.8-list | wget -i- -c \
        -B https://github.com/llvm/llvm-project/releases/download/llvmorg-21.1.8/

## Installation of LLVM

Extract the `llvm-21.1.8.src.tar.xz` tarball and navigate to the extracted `llvm-21.1.8.src` directory:

    tar -xf llvm-21.1.8.src.tar.xz &&
    cd llvm-21.1.8.src

The `cmake-21.1.8.src.tar.xz` and `third-party-21.1.8.src.tar.xz` tarballs are necessary for the LLVM building process. The `cmake-21.1.8.src.tar.xz` tarball includes CMake modules that LLVM uses, such as properly setting the version number. The `third-party-21.1.8.src.tar.xz` tarball includes dependencies, such as benchmark and unittest. Upstream expects both tarballs to be extracted at the same level as the `llvm-21.1.8.src.tar.xz` tarball. Additionally, the extracted directories must be renamed to `cmake` and `third-party` respectively. Extract them and modify the build system to avoid creating ambiguously-named directories outside the `llvm-21.1.8.src` hierarchy:

    tar -xf ../cmake-21.1.8.src.tar.xz &&
    tar -xf ../third-party-21.1.8.src.tar.xz &&
    sed '/LLVM_COMMON_CMAKE_UTILS/s@../cmake@cmake-21.1.8.src@' \
        -i CMakeLists.txt &&
    sed '/LLVM_THIRD_PARTY_DIR/s@../third-party@third-party-21.1.8.src@' \
        -i cmake/modules/HandleLLVMOptions.cmake

Extract clang into the source tree by running the following commands:

    tar -xf ../clang-21.1.8.src.tar.xz -C tools &&
    mv tools/clang-21.1.8.src tools/clang

Extract compiler-rt into the source tree by running the following commands:

    tar -xf ../compiler-rt-21.1.8.src.tar.xz -C projects    &&
    mv projects/compiler-rt-21.1.8.src projects/compiler-rt

There are many Python scripts in this package which use /usr/bin/env python to access the system Python which on LFS is Python3. Use the following command to fix these scripts:

    grep -rl '#!.*python' | xargs sed -i '1s/python$/python3/'

Ensure installing the FileCheck program:

    sed 's/utility/tool/' -i utils/FileCheck/CMakeLists.txt

Install LLVM by running the following commands:

    mkdir build &&
    cd    build &&

    CC=gcc CXX=g++                                         \
    cmake -D CMAKE_INSTALL_PREFIX=/usr                     \
          -D CMAKE_SKIP_INSTALL_RPATH=ON                   \
          -D LLVM_ENABLE_FFI=ON                            \
          -D CMAKE_BUILD_TYPE=Release                      \
          -D LLVM_BUILD_LLVM_DYLIB=ON                      \
          -D LLVM_LINK_LLVM_DYLIB=ON                       \
          -D LLVM_ENABLE_RTTI=ON                           \
          -D LLVM_TARGETS_TO_BUILD="X86;host;AMDGPU;NVPTX" \
          -D LLVM_BINUTILS_INCDIR=/usr/include             \
          -D LLVM_INCLUDE_BENCHMARKS=OFF                   \
          -D CLANG_DEFAULT_PIE_ON_LINUX=ON                 \
          -D CLANG_CONFIG_FILE_SYSTEM_DIR=/etc/clang       \
          -W no-dev -G Ninja .. &&

    ninja

Now, as the `root` user:

    ninja install

## lib32 Installation of LLVM

If you are doing multilib, you will also need to install the 32-bit runtime libraries. Install them by doing the following:

    rm -rf * &&

    CC=gcc CXX=g++                                          \
    cmake -D CMAKE_INSTALL_PREFIX=/usr                      \
          -D CMAKE_C_FLAGS:STRING=-m32                      \
          -D CMAKE_SKIP_INSTALL_RPATH=ON                    \
          -D CMAKE_CXX_FLAGS:STRING=-m32                    \
          -D LLVM_TARGET_ARCH:STRING=i686                   \
          -D LLVM_LIBDIR_SUFFIX=32                          \
          -D LLVM_ENABLE_FFI=ON                             \
          -D CMAKE_BUILD_TYPE=Release                       \
          -D LLVM_BUILD_LLVM_DYLIB=ON                       \
          -D LLVM_LINK_LLVM_DYLIB=ON                        \
          -D LLVM_ENABLE_RTTI=ON                            \
          -D LLVM_DEFAULT_TARGET_TRIPLE="i686-pc-linux-gnu" \
          -D LLVM_TARGETS_TO_BUILD="X86;host;AMDGPU;NVPTX"  \
          -D LLVM_HOST_TRIPLE="x86_64-pc-linux-gnu"         \
          -D LLVM_BINUTILS_INCDIR=/usr/include              \
          -D LLVM_INCLUDE_BENCHMARKS=OFF                    \
          -D CLANG_DEFAULT_PIE_ON_LINUX=ON                  \
          -D CLANG_CONFIG_FILE_SYSTEM_DIR=/etc/clang        \
          -W no-dev -G Ninja .. &&

    ninja

Now as the `root` user:

    DESTDIR=$PWD/DESTDIR ninja install    &&
    cp -vr DESTDIR/usr/lib32/* /usr/lib32 &&
    rm -rf DESTDIR                        &&
    ldconfig

## Command Explanations

### Note

For a full list of options and values, make sure you are in a build directory, then run cmake -LAH ...

`-D LLVM_ENABLE_FFI=ON`: This switch allows LLVM to use libffi.

`-D LLVM_BUILD_LLVM_DYLIB=ON`: This switch builds the libraries as static and links all of them into an unique shared one. This is the recommended way of building a shared library and is required by Rustc-1.93.1 in order to build against the system-installed LLVM.

`-D CMAKE_BUILD_TYPE=Release`: This switch enables compiler optimizations in order to speed up the code and reduce its size. It also disables some compile checks which are not necessary on a production system.

`-D CMAKE_SKIP_INSTALL_RPATH=ON`: This switch makes cmake remove hardcoded library search paths (rpath) when installing a binary executable file or a shared library. This package does not need rpath once it's installed into the standard location, and rpath may sometimes cause unwanted effects or even security issues.

`-D LLVM_TARGETS_TO_BUILD="X86;host;AMDGPU;NVPTX"`: This switch enables building for x86, the same target as the host, for the r600 AMD GPU used by the Mesa-25.3.5 r600 and radeonsi drivers, as well as NVIDIA GPUs used in tandem with CUDA. The default is all of the targets. You can use a semicolon separated list. Valid targets are: host, AArch64, AMDGPU, ARM, AVR, BPF, Hexagon, Lanai, LoongArch, Mips, MSP430, NVPTX, PowerPC, RISCV, Sparc, SystemZ, SystemZ, VE, WebAssembly, X86, XCore, or all.

`-D LLVM_LINK_LLVM_DYLIB=ON`: Used in conjunction with `-D LLVM_BUILD_LLVM_DYLIB=ON`, this switch enables linking the tools against the shared library instead of the static ones. It slightly reduces their size and also ensures that llvm-config will correctly use libLLVM-21.

`-D LLVM_ENABLE_RTTI=ON`: This switch is used to build LLVM with run-time type information. This is required for building Gallium3D LLVMpipe from Mesa-25.3.5.

`-D LLVM_BINUTILS_INCDIR=/usr/include`: This switch is used to tell the build system the location of binutils headers, which were installed in LFS. This allows the building of `LLVMgold`, which is needed for building programs with clang and Link Time Optimization (LTO).

`-D LLVM_INCLUDE_BENCHMARKS=OFF`: is used to disable generation build targets for the LLVM benchmarks. This option requires additional code that is not currently available.

`-D CLANG_DEFAULT_PIE_ON_LINUX=ON`: makes `-fpie` option the default when compiling programs. Together with the ASLR feature enabled in the kernel, this defeats some kind of attacks based on known memory layouts.

`-D CLANG_CONFIG_FILE_SYSTEM_DIR=/etc/clang`: makes clang and clang++ search `/etc/clang` for configuration files.

`-D BUILD_SHARED_LIBS=ON`: if used instead of `-D LLVM_BUILD_LLVM_DYLIB=ON` and `-D LLVM_LINK_LLVM_DYLIB=ON`, builds all the LLVM libraries (about 60) as shared libraries instead of static.

## Configuring LLVM

### Configuration Information

If you've built Clang, as the `root` user create two configuration files to make SSP enabled by default for clang and clang++, so the default configuration of their SSP feature will be consistent with GCC:

    mkdir -pv /etc/clang &&
    for i in clang clang++; do
      echo -fstack-protector-strong > /etc/clang/$i.cfg
    done

## Contents

Installed Programs: amdgpu-arch, analyze-build, bugpoint, c-index-test, clang, clang++ (symlinks to clang-21), clang-21, clang-check, clang-cl, clang-cpp (last two symlinks to clang), clang-extdef-mapping, clang-format, clang-installapi, clang-linker-wrapper, clang-nvlink-wrapper, clang-offload-bundler, clang-offload-packager, clang-refactor, clang-repl, clang-scan-deps, clang-sycl-linker, clang-tblgen, diagtool, dsymutil, FileCheck, git-clang-format, hmaptool, intercept-build, llc, lli, llvm-addr2line (symlink to llvm-symbolizer), llvm-ar, llvm-as, llvm-bcanalyzer, llvm-bitcode-strip (symlink to llvm-objcopy), llvm-cat, llvm-cfi-verify, llvm-cgdata, llvm-config, llvm-cov, llvm-c-test, llvm-ctxprog-util, llvm-cvtres, llvm-cxxdump, llvm-cxxfilt, llvm-cxxmap, llvm-debuginfo-analyzer, llvm-debuginfod, llvm-debuginfod-find, llvm-diff, llvm-dis, llvm-dlltool (symlink to llvm-ar), llvm-dwarfdump, llvm-dwarfutil, llvm-dwp, llvm-exegesis, llvm-extract, llvm-gsymutil, llvm-ifs, llvm-install-name-tool (symlink to llvm-objcopy), llvm-jitlink, llvm-lib (symlink to llvm-ar), llvm-libtool-darwin, llvm-link, llvm-lipo, llvm-lto, llvm-lto2, llvm-mc, llvm-mca, llvm-ml, llvm-modextract, llvm-mt, llvm-nm, llvm-objcopy, llvm-objdump, llvm-opt-report, llvm-otool (symlink to llv-objdump), llvm-pdbutil, llvm-profdata, llvm-profgen, llvm-ranlib (symlink to llvm-ar), llvm-rc, llvm-readelf (symlink to llvm-readobj), llvm-readobj, llvm-readtapi, llvm-reduce, llvm-remarkutil, llvm-rtdyld, llvm-sim, llvm-size, llvm-split, llvm-stress, llvm-strings, llvm-strip (symlink to llvm-objcopy), llvm-symbolizer, llvm-tblgen, llvm-tli-checker, llvm-undname, llvm-windres (symlink to llvm-rc), llvm-xray, nvptx-arch, opt, sancov, sanstats, scan-build, scan-build-py, scan-view, and verify-uselistorder
Installed Libraries: libLLVM, libLLVM* (107 static libraries), libLTO, libRemarks, libclang, libclang-cpp, libclang* (43 static libraries), and LLVMgold
Installed Directories: /usr/include/{clang,clang-c,llvm,llvm-c}, /usr/lib/{clang,cmake/{clang,llvm},libear,libscanbuild}, /usr/share/{clang,opt-viewer,scan-build,scan-view}, and /etc/clang

### Short Descriptions

amdgpu-arch | lists AMD GPUs installed; at runtime it needs `libhsa-runtime64` which is not a part of BLFS
analyze-build | is a static analysis tool
bugpoint | is the automatic test case reduction tool
c-index-test | is used to test the libclang API and demonstrate its usage
clang | is the Clang C, C++, and Objective-C compiler
clang-check | is a tool to perform static code analysis and display Abstract Syntax Trees (AST)
clang-extdef-mapping | is a tool to collect the USR name and location of external definitions in a source file
clang-format | is a tool to format C/C++/Java/JavaScript/Objective-C/Protobuf code
clang-linker-wrapper | is a wrapper utility over the host linker
clang-offload-bundler | is a tool to bundle/unbundle OpenMP offloaded files associated with a common source file
clang-offload-packager | is a tool to bundle several object files into a single binary, which can then be used to create a fatbinary containing offloading code
clang-refactor | is a Clang-based refactoring tool for C, C++ and Objective-C
clang-scan-deps | is a tool to scan for dependencies in a source file
clang-tblgen | is a program that translates compiler-related target description (`.td`) files into C++ code and other output formats
diagtool | is a combination of tools for dealing with diagnostics in clang
FileCheck | is a tool that reads two files (one from standard input, and one specified on the command line) and uses one to verify the other.
dsymutil | is a tool used to manipulate archived DWARF debug symbol files, compatible with the Darwin command dsymutil
git-clang-format | runs clang-format on git generated patches (requires Git)
hmaptool | is a Python tool to dump and construct header maps
intercept-build | generates a database of build commands for a project
llc | is the LLVM static compiler
lli | is used to directly execute programs from LLVM bitcode
llvm-addr2line | is a tool used to convert addresses into file names and line numbers
llvm-ar | is the LLVM archiver
llvm-as | is the LLVM assembler
llvm-bcanalyzer | is the LLVM bitcode analyzer
llvm-bitcode-strip | strips LLVM bitcode from an object
llvm-cat | is a tool to concatenate llvm modules
llvm-cfi-verify | identifies whether Control Flow Integrity protects all indirect control flow instructions in the provided object file, DSO, or binary
llvm-config | Prints LLVM compilation options
llvm-cov | is used to emit coverage information
llvm-c-test | is a bytecode disassembler
llvm-cvtres | is a tool to convert Microsoft resource files to COFF
llvm-cxxdump | is used as a C++ ABI Data Dumper
llvm-cxxfilt | is used to demangle C++ symbols in llvm code
llvm-cxxmap | is used to remap C++ mangled symbols
llvm-debuginfo-analyzer | prints a logical representation of low-level debug information
llvm-debuginfod | is a service providing debug information over an HTTP API for analyzing stripped binaries
llvm-debuginfod-find | is an interface to the llvm-debuginfod daemon for finding debuginfod artifacts
llvm-diff | is the LLVM structural 'diff'
llvm-dis | is the LLVM disassembler
llvm-dwarfdump | prints the content of DWARF sections in object files
llvm-dwarfutil | is a tool to copy and manipulate debug info
llvm-dwp | merges split DWARF files
llvm-elfabi | is used to read information about an ELF binary's ABI
llvm-exegesis | is a benchmarking tool that uses information available in LLVM to measure host machine instruction characteristics like latency or port decomposition
llvm-extract | is used to extract a function from an LLVM module
llvm-gsymutil | is used to process GSYM Symbolication Format files which convert memory addresses to function name and source file line. These files are smaller than DWARF or Breakpad files
llvm-ifs | is used to merge interface stubs with object files
llvm-install-name-tool | is used to rewrite load commands into MachO binary format
llvm-jitlink | is used to parse relocatable object files to make their contents executable in a target process
llvm-libtool-darwin | provides basic libtool functionality on Darwin-based systems. This is mostly useful if you are generating binaries for macOS systems
llvm-link | is the LLVM linker
llvm-lipo | is used to create universal binaries from MachO files
llvm-lto | is the LLVM LTO (link time optimization) linker
llvm-lto2 | is a test harness for the resolution based LTO interface
llvm-mc | is a standalone machine code assembler/disassembler
llvm-mca | is a performance analysis tool to statically measure the performance of machine code
llvm-ml | is a playground for machine code provided by LLVM
llvm-modextract | is a tool to extract one module from multimodule bitcode files
llvm-mt | is a tool to generate signed files and catalogs from a side-by-side assembly manifest (used for Microsoft SDK)
llvm-nm | is used to list LLVM bitcode and object file's symbol table
llvm-objcopy | is LLVM's version of an objcopy tool
llvm-objdump | is an LLVM object file dumper
llvm-opt-report | is a tool to generate an optimization report from YAML optimization record files
llvm-pdbutil | is a PDB (Program Database) dumper. PDB is a Microsoft format
llvm-profdata | is a small tool to manipulate and print profile data files
llvm-profgen | generates LLVM SPGO profiling information
llvm-ranlib | is used to generate an index for a LLVM archive
llvm-rc | is a platform-independent tool to compile resource scripts into binary resource files
llvm-readobj | displays low-level format-specific information about object files
llvm-readtapi | is the LLVM TAPI file reader and transformer
llvm-reduce | is used to automatically reduce testcases when running a test suite
llvm-remarkutil | converts remark files between bitstream and YAML; or prints function instruction count information in remark files
llvm-rtdyld | is the LLVM MC-JIT tool
llvm-size | is the LLVM object size dumper
llvm-split | is the LLVM module splitter
llvm-stress | is used to generate random `.ll` files
llvm-strings | print strings found in a binary (object file, executable, or archive library)
llvm-symbolizer | converts addresses into source code locations
llvm-tblgen | is the LLVM Target Description To C++ Code Generator
llvm-tli-checker | is the LLVM TargetLibraryInfo versus SDK checker
llvm-undname | is a tool to demangle names
llvm-xray | is an implementation of Google's XRay function call tracing system
nvptx-arch | lists NVIDIA GPUs installed; at runtime it needs `libcuda` from NVIDIA
opt | is the LLVM optimizer
sancov | is the sanitizer coverage processing tool
sanstats | is the sanitizer statistics processing tool
scan-build | is a Perl script that invokes the Clang static analyzer
scan-build-py | is a Python script that invokes the Clang static analyzer
scan-view | is a viewer for Clang static analyzer results
verify-uselistorder | is the LLVM tool to verify use-list order

- Prev

  CMake-4.2.3

- Next

  Rustc-1.93.1

- Up
- Home