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 rust 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.

This package is known to build and work properly using an LFS 12.0 platform.

Package Information

Additional Downloads

Cmake modules for LLVM

Third-party dependencies for LLVM build system

Recommended Download


Optional Download

Compiler RT

LLVM Dependencies




Doxygen-1.9.7, git-2.41.0, Graphviz-8.1.0, libxml2-2.10.4, Pygments-2.16.1, rsync-3.2.7 (for tests), recommonmark-0.7.1 (for building documentation), texlive-20230313 (or install-tl-unx), Valgrind-3.21.0, PyYAML-6.0.1, Zip-3.0, OCaml, psutil (for tests), and Z3

Installation of LLVM

Two additional tarballs llvm-cmake.src.tar.xz and llvm-third-party.src.tar.xz are needed by LLVM building system. The upstream expects them extracted at the same level as the llvm-16.0.5.src.tar.xz tarball, and the extracted directories renamed to cmake and third-party. Extract them and modify the build system to avoid creating ambiguously-named directories outside the llvm-16.0.5.src hierarchy:

tar -xf ../llvm-cmake.src.tar.xz                                   &&
tar -xf ../llvm-third-party.src.tar.xz                             &&
sed '/LLVM_COMMON_CMAKE_UTILS/s@../[email protected]@'          \
    -i CMakeLists.txt                                              &&
sed '/LLVM_THIRD_PARTY_DIR/s@../[email protected]@' \
    -i cmake/modules/HandleLLVMOptions.cmake

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

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

If you have downloaded compiler-rt, install it into the source tree by running the following commands:

tar -xf ../compiler-rt-16.0.5.src.tar.xz -C projects &&
mv projects/compiler-rt-16.0.5.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 Python-3.11.4. Use the following command to fix these scripts:

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

If you have downloaded clang, apply the following patch to enable SSP by default in compiled programs.

patch -Np2 -d tools/clang <../clang-16.0.5-enable_default_ssp-1.patch

If you have downloaded compiler-rt, fix a test case broken by default SSP in clang:

sed 's/clang_dfsan/& -fno-stack-protector/' \
    -i projects/compiler-rt/test/dfsan/origin_unaligned_memtrans.c

Install LLVM by running the following commands:

mkdir -v build &&
cd       build &&

CC=gcc CXX=g++                                  \
cmake -DCMAKE_INSTALL_PREFIX=/usr               \
      -DLLVM_ENABLE_FFI=ON                      \
      -DCMAKE_BUILD_TYPE=Release                \
      -DLLVM_BUILD_LLVM_DYLIB=ON                \
      -DLLVM_LINK_LLVM_DYLIB=ON                 \
      -DLLVM_ENABLE_RTTI=ON                     \
      -DLLVM_BINUTILS_INCDIR=/usr/include       \
      -Wno-dev -G Ninja ..                      &&

If you have installed recommonmark-0.7.1 and its dependencies, you can generate the html documentation and manual pages with the following commands:

cmake -DLLVM_BUILD_DOCS=ON            \
      -DLLVM_ENABLE_SPHINX=ON         \
      -Wno-dev -G Ninja ..            &&
ninja docs-llvm-html  docs-llvm-man

The clang documentation can be built too:

ninja docs-clang-html docs-clang-man

LLVM test suite can produce many core dump files. They will occupy a large amount of disk space, and the core dump process can significantly slow down the testing. To test the results with core dump disabled, issue:

sh -c 'ulimit -c 0 && ninja check-all'

Tests are built with all available cores, but run using the number of online processors. (The difference is that available cores can be limited using taskset, but taking them offline requires echoing 0 to /sys/devices/system/cpu/cpu<N>/online by the root user and makes them temporarily unusable by all jobs on the machine.) One test named Linux/clone_setns.cpp will fail if CONFIG_USER_NS is not enabled in kernel configuration. The tests named AtoiAndFriendsOOBTest, StrtolOOBTest, StrtollOOBTest, interception_malloc_test.cpp, and scanf-allocate.cpp are known to fail with Glibc-2.38.

Now, as the root user:

ninja install &&
cp bin/FileCheck /usr/bin

If you have built the llvm documentation, it has been installed by the above command, but it needs to be moved. As the root user:

install -v -d -m755 /usr/share/doc/llvm-16.0.5            &&
mv -v /usr/share/doc/LLVM/llvm /usr/share/doc/llvm-16.0.5 &&
rmdir -v --ignore-fail-on-non-empty /usr/share/doc/LLVM

If you have built the clang documentation, it has been installed, but needs to be moved too. Again as the root user:

install -v -d -m755 /usr/share/doc/llvm-16.0.5             &&
mv -v /usr/share/doc/LLVM/clang /usr/share/doc/llvm-16.0.5 &&
rmdir -v --ignore-fail-on-non-empty /usr/share/doc/LLVM

Command Explanations

-DLLVM_ENABLE_FFI=ON: This switch allows LLVM to use libffi.

-DLLVM_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.

-DCMAKE_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.

-DLLVM_TARGETS_TO_BUILD="host;AMDGPU;BPF": This switch enables building for the same target as the host, and also for the r600 AMD GPU used by the Mesa r600 and radeonsi drivers. The BPF target is required to build v4l-utils-1.24.1. The Default is all of the targets. You can use a semicolon separated list. Valid targets are: host, X86, Sparc, PowerPC, ARM, AArch64, Mips, Hexagon, Xcore, M68K, MSP430, NVPTX, SystemZ, AMDGPU, BPF, CppBackend, or all.

-DLLVM_LINK_LLVM_DYLIB=ON: Used in conjunction with -DLLVM_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-16.so.

-DLLVM_ENABLE_RTTI=ON: This switch is used to build LLVM with run-time type information. This is required for building Mesa-23.1.6.

-DLLVM_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.so, which is needed for building programs with clang and Link Time Optimization (LTO).

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

-DCLANG_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.

-DBUILD_SHARED_LIBS=ON: if used instead of -DLLVM_BUILD_LLVM_DYLIB=ON and -DLLVM_LINK_LLVM_DYLIB=ON, builds all the LLVM libraries (about 60) as shared libraries instead of static.

-DLLVM_ENABLE_DOXYGEN: Enables the generation of browsable HTML documentation if you have installed Doxygen-1.9.7. You should run make doxygen-html afterwards, and install the generated documentation manually.


Installed Programs: amdgpu-arch, analyze-build, bugpoint, c-index-test, clang, clang++ (symlinks to clang-16), clang-16, clang-check, clang-cl, clang-cpp (last two symlinks to clang), clang-extdef-mapping, clang-format, clang-linker-wrapper, clang-offload-bundler, clang-offload-packager, clang-refactor, clang-rename, clang-repl, clang-scan-deps, 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-config, llvm-cov, llvm-c-test, 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-reduce, llvm-remark-size-diff, llvm-remarkutil, llvm-rtdyld, llvm-sim, llvm-size, llvm-split, llvm-stress, llvm-strings, llvm-strip (symlink to llvm-objcopy), llvm-symbolizer, llvm-tapi-diff, 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, split-file, and verify-uselistorder
Installed Libraries: libLLVM.so, libLLVM*.a (100 libraries), libLTO.so, libRemarks.so, libclang.so, libclang-cpp.so, libclang*.a (42 libraries), and LLVMgold.so
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 /usr/share/doc/llvm-16.0.5

Short Descriptions


lists AMD GPUs installed; at runtime it needs libhsa-runtime64.so which is not a part of BLFS


is a static analysis tool


is the automatic test case reduction tool


is used to test the libclang API and demonstrate its usage


is the Clang C, C++, and Objective-C compiler


is a tool to perform static code analysis and display Abstract Syntax Trees (AST)


is a tool to collect the USR name and location of external definitions in a source file


is a tool to format C/C++/Java/JavaScript/Objective-C/Protobuf code


is a wrapper utility over the host linker


is a tool to bundle/unbundle OpenMP offloaded files associated with a common source file


is a tool to bundle several object files into a single binary, which can then be used to create a fatbinary containing offloading code


is a Clang-based refactoring tool for C, C++ and Objective-C


is a tool to rename symbols in C/C++ programs


is a tool to scan for dependencies in a source file


is a combination of tools for dealing with diagnostics in clang


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.


is a tool used to manipulate archived DWARF debug symbol files, compatible with the Darwin command dsymutil


runs clang-format on git generated patches (requires git-2.41.0)


is a Python tool to dump and construct header maps


generates a database of build commands for a project


is the LLVM static compiler


is used to directly execute programs from LLVM bitcode


is a tool used to convert addresses into file names and line numbers


is the LLVM archiver


is the LLVM assembler


is the LLVM bitcode analyzer


strips LLVM bitcode from an object


is a tool to concatenate llvm modules


identifies whether Control Flow Integrity protects all indirect control flow instructions in the provided object file, DSO, or binary


Prints LLVM compilation options


is used to emit coverage information


is a bytecode disassembler


is a tool to convert Microsoft resource files to COFF


is used as a C++ ABI Data Dumper


is used to demangle C++ symbols in llvm code


is used to remap C++ mangled symbols


prints a logical representation of low-level debug information


is a service providing debug information over an HTTP API for analyzing stripped binaries


is an interface to the llvm-debuginfod daemon for finding debuginfod artifacts


is the LLVM structural 'diff'


is the LLVM disassembler


prints the content of DWARF sections in object files


is a tool to copy and manipulate debug info


merges split DWARF files


is used to read information about an ELF binary's ABI


is a benchmarking tool that uses information available in LLVM to measure host machine instruction characteristics like latency or port decomposition


is used to extract a function from an LLVM module


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


is used to merge interface stubs with object files


is used to rewrite load commands into MachO binary format


is used to parse relocatable object files to make their contents executable in a target process


provides basic libtool functionality on Darwin-based systems. This is mostly useful if you are generating binaries for macOS systems


is the LLVM linker


is used to create universal binaries from MachO files


is the LLVM LTO (link time optimization) linker


is a test harness for the resolution based LTO interface


is a standalone machine code assembler/disassembler


is a performance analysis tool to statically measure the performance of machine code


is a playground for machine code provided by LLVM


is a tool to extract one module from multimodule bitcode files


is a tool to generate signed files and catalogs from a side-by-side assembly manifest (used for Microsoft SDK)


is used to list LLVM bitcode and object file's symbol table


is LLVM's version of an objcopy tool


is an LLVM object file dumper


is a tool to generate an optimization report from YAML optimization record files


is a PDB (Program Database) dumper. PDB is a Microsoft format


is a small tool to manipulate and print profile data files


generates LLVM SPGO profiling information


is used to generate an index for a LLVM archive


is a platform-independent tool to compile resource scripts into binary resource files


displays low-level format-specific information about object files


is used to automatically reduce testcases when running a test suite


reports the difference in instruction count and stack size remarks between two remark files


converts remark files between bitstream and YAML; or prints function instruction count information in remark files


is the LLVM MC-JIT tool


is the LLVM object size dumper


is the LLVM module splitter


is used to generate random .ll files


print strings found in a binary (object file, executable, or archive library)


converts addresses into source code locations


is the LLVM Target Description To C++ Code Generator


is the LLVM TargetLibraryInfo versus SDK checker


is a tool to demangle names


is an implementation of Google's XRay function call tracing system


lists NVIDIA GPUs installed; at runtime it needs libcuda.so which is not a part of BLFS


is the LLVM optimizer


is the sanitizer coverage processing tool


is the sanitizer statistics processing tool


is a Perl script that invokes the Clang static analyzer


is a Python script that invokes the Clang static analyzer


is a viewer for Clang static analyzer results


splits an input file into multiple parts separated by regex


is the LLVM tool to verify use-list order