%general-entities; ]> LLVM-&llvm-version; LLVM 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. &lfs121_checked; Package Information Download (HTTP): Download (FTP): Download MD5 sum: &llvm-md5sum; Download size: &llvm-size; Estimated disk space required: &llvm-buildsize; Estimated build time: &llvm-time; Additional Downloads Cmake modules for LLVM Download: Download MD5 sum: &cmake-llvm-md5sum; Download size: &cmake-llvm-size; Third-party dependencies for LLVM build system Download: Download MD5 sum: &llvm-3rdparty-md5sum; Download size: &llvm-3rdparty-size; Recommended Download Clang Download: Download MD5 sum: &clang-md5sum; Download size: &clang-size; Optional Download Compiler RT Download: Download MD5 sum: &compiler-rt-md5sum; Download size: &compiler-rt-size; LLVM Dependencies Required Optional , , , , , (for tests), (for building documentation), (or ), , , , OCaml, psutil (for tests), and Z3 Installation of LLVM Two additional tarballs llvm-cmake-&llvm-maj-version;.src.tar.xz and llvm-third-party-&llvm-maj-version;.src.tar.xz are needed by LLVM building system. The upstream expects them extracted at the same level as the llvm-&llvm-version;.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-&llvm-version;.src hierarchy: tar -xf ../llvm-cmake-&llvm-maj-version;.src.tar.xz && tar -xf ../llvm-third-party-&llvm-maj-version;.src.tar.xz && sed '/LLVM_COMMON_CMAKE_UTILS/s@../cmake@llvm-cmake-&llvm-maj-version;.src@' \ -i CMakeLists.txt && sed '/LLVM_THIRD_PARTY_DIR/s@../third-party@llvm-third-party-&llvm-maj-version;.src@' \ -i cmake/modules/HandleLLVMOptions.cmake Install clang into the source tree by running the following commands: tar -xf ../clang-&llvm-version;.src.tar.xz -C tools && mv tools/clang-&llvm-version;.src tools/clang If you have downloaded compiler-rt, install it into the source tree by running the following commands: tar -xf ../compiler-rt-&llvm-version;.src.tar.xz -C projects && mv projects/compiler-rt-&llvm-version;.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 . Use the following command to fix these scripts: grep -rl '#!.*python' | xargs sed -i '1s/python$/python3/' 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_TARGETS_TO_BUILD="host;AMDGPU" \ -DLLVM_BINUTILS_INCDIR=/usr/include \ -DLLVM_INCLUDE_BENCHMARKS=OFF \ -DLLVM_VERSION_SUFFIX= \ -DCLANG_DEFAULT_PIE_ON_LINUX=ON \ -DCLANG_CONFIG_FILE_SYSTEM_DIR=/etc/clang \ -Wno-dev -G Ninja .. && ninja If you have installed 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 \ -DSPHINX_WARNINGS_AS_ERRORS=OFF \ -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 If you wish to run the tests, remove a test case known to hang indefinitely on some systems: rm -f ../projects/compiler-rt/test/tsan/getline_nohang.cpp 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, ensure and have been rebuilt with support (if you are interacting via a SSH or graphical session, also ensure the server or the desktop manager has been built with ) and the current login session is started after updating the /etc/pam.d/system-session file to include pam_systemd.so, then issue: sh -c 'ulimit -c 0 && ninja check-all' systemctl --user start dbus && systemd-run --user --pty -d -G -p LimitCORE=0 ninja check-all If (N replaced with a number) is passed to ninja, the tests will be built with N logical cores, but run using all available logical cores. Run the test command in a cgroup (pass the option to the systemd-run command, read for details) to limit the number of logical cores for running the tests. Two tests named sanitizer_coverage_inline8bit_counter_default_impl.cpp and sanitizer_coverage_symbolize.cpp are known to fail. One test named Linux/clone_setns.cpp will fail if is not enabled in kernel configuration. 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-&llvm-version; && mv -v /usr/share/doc/LLVM/llvm /usr/share/doc/llvm-&llvm-version; && 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-&llvm-version; && mv -v /usr/share/doc/LLVM/clang /usr/share/doc/llvm-&llvm-version; && 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": 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 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. -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-&llvm-maj-version;.so. -DLLVM_ENABLE_RTTI=ON: This switch is used to build LLVM with run-time type information. This is required for building . -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. -DLLVM_VERSION_SUFFIX=: works around an oversight in the upstream releasing process causing the 18.1.0 release branded 18.1rc. -DCLANG_DEFAULT_PIE_ON_LINUX=ON: makes option the default when compiling programs. Together with the feature enabled in the kernel, this defeats some kind of attacks based on known memory layouts. -DCLANG_CONFIG_FILE_SYSTEM_DIR=/etc/clang: makes clang and clang++ search /etc/clang for configuration files. : 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. : Enables the generation of browsable HTML documentation if you have installed . You should run make doxygen-html afterwards, and install the generated documentation manually. Configuring LLVM Configuration Information If you've built Clang, as the &root; user create two configuration files to make enabled by default for for clang and clang++, so the default configuration of their SSP feature will be consistent with : mkdir -pv /etc/clang && for i in clang clang++; do echo -fstack-protector-strong > /etc/clang/$i.cfg done Contents Installed Programs Installed Libraries Installed Directories amdgpu-arch, analyze-build, bugpoint, c-index-test, clang, clang++ (symlinks to clang-&llvm-maj-version;), clang-&llvm-maj-version;, 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, 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-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-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 libLLVM.so, libLLVM*.a (100 libraries), libLTO.so, libRemarks.so, libclang.so, libclang-cpp.so, libclang*.a (42 libraries), and LLVMgold.so /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}, /usr/share/doc/llvm-&llvm-version;, and /etc/clang Short Descriptions amdgpu-arch lists AMD GPUs installed; at runtime it needs libhsa-runtime64.so which is not a part of BLFS amdgpu-arch analyze-build is a static analysis tool analyze-build bugpoint is the automatic test case reduction tool bugpoint c-index-test is used to test the libclang API and demonstrate its usage c-index-test clang is the Clang C, C++, and Objective-C compiler clang clang-check is a tool to perform static code analysis and display Abstract Syntax Trees (AST) clang-check clang-extdef-mapping is a tool to collect the USR name and location of external definitions in a source file clang-extdef-mapping clang-format is a tool to format C/C++/Java/JavaScript/Objective-C/Protobuf code clang-format clang-linker-wrapper is a wrapper utility over the host linker clang-linker-wrapper clang-offload-bundler is a tool to bundle/unbundle OpenMP offloaded files associated with a common source file clang-offload-bundler 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-offload-packager clang-refactor is a Clang-based refactoring tool for C, C++ and Objective-C clang-refactor clang-rename is a tool to rename symbols in C/C++ programs clang-rename clang-scan-deps is a tool to scan for dependencies in a source file clang-scan-deps clang-tblgen is a program that translates compiler-related target description (.td) files into C++ code and other output formats clang-tblgen diagtool is a combination of tools for dealing with diagnostics in clang diagtool 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. FileCheck dsymutil is a tool used to manipulate archived DWARF debug symbol files, compatible with the Darwin command dsymutil dsymutil git-clang-format runs clang-format on git generated patches (requires ) git-clang-format hmaptool is a Python tool to dump and construct header maps hmaptool intercept-build generates a database of build commands for a project intercept-build llc is the LLVM static compiler llc lli is used to directly execute programs from LLVM bitcode lli llvm-addr2line is a tool used to convert addresses into file names and line numbers llvm-addr2line llvm-ar is the LLVM archiver llvm-ar llvm-as is the LLVM assembler llvm-as llvm-bcanalyzer is the LLVM bitcode analyzer llvm-bcanalyzer llvm-bitcode-strip strips LLVM bitcode from an object llvm-bitcode-strip llvm-cat is a tool to concatenate llvm modules llvm-cat llvm-cfi-verify identifies whether Control Flow Integrity protects all indirect control flow instructions in the provided object file, DSO, or binary llvm-cfi-verify llvm-config Prints LLVM compilation options llvm-config llvm-cov is used to emit coverage information llvm-cov llvm-c-test is a bytecode disassembler llvm-c-test llvm-cvtres is a tool to convert Microsoft resource files to COFF llvm-cvtres llvm-cxxdump is used as a C++ ABI Data Dumper llvm-cxxdump llvm-cxxfilt is used to demangle C++ symbols in llvm code llvm-cxxfilt llvm-cxxmap is used to remap C++ mangled symbols llvm-cxxmap llvm-debuginfo-analyzer prints a logical representation of low-level debug information llvm-debuginfo-analyzer llvm-debuginfod is a service providing debug information over an HTTP API for analyzing stripped binaries llvm-debuginfod llvm-debuginfod-find is an interface to the llvm-debuginfod daemon for finding debuginfod artifacts llvm-debuginfod-find llvm-diff is the LLVM structural 'diff' llvm-diff llvm-dis is the LLVM disassembler llvm-dis llvm-dwarfdump prints the content of DWARF sections in object files llvm-dwarfdump llvm-dwarfutil is a tool to copy and manipulate debug info llvm-dwarfutil llvm-dwp merges split DWARF files llvm-dwp llvm-elfabi is used to read information about an ELF binary's ABI llvm-elfabi llvm-exegesis is a benchmarking tool that uses information available in LLVM to measure host machine instruction characteristics like latency or port decomposition llvm-exegesis llvm-extract is used to extract a function from an LLVM module llvm-extract 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-gsymutil llvm-ifs is used to merge interface stubs with object files llvm-ifs llvm-install-name-tool is used to rewrite load commands into MachO binary format llvm-install-name-tool llvm-jitlink is used to parse relocatable object files to make their contents executable in a target process llvm-jitlink llvm-libtool-darwin provides basic libtool functionality on Darwin-based systems. This is mostly useful if you are generating binaries for macOS systems llvm-libtool-darwin llvm-link is the LLVM linker llvm-link llvm-lipo is used to create universal binaries from MachO files llvm-lipo llvm-lto is the LLVM LTO (link time optimization) linker llvm-lto llvm-lto2 is a test harness for the resolution based LTO interface llvm-lto2 llvm-mc is a standalone machine code assembler/disassembler llvm-mc llvm-mca is a performance analysis tool to statically measure the performance of machine code llvm-mca llvm-ml is a playground for machine code provided by LLVM llvm-ml llvm-modextract is a tool to extract one module from multimodule bitcode files llvm-modextract llvm-mt is a tool to generate signed files and catalogs from a side-by-side assembly manifest (used for Microsoft SDK) llvm-mt llvm-nm is used to list LLVM bitcode and object file's symbol table llvm-nm llvm-objcopy is LLVM's version of an objcopy tool llvm-objcopy llvm-objdump is an LLVM object file dumper llvm-objdump llvm-opt-report is a tool to generate an optimization report from YAML optimization record files llvm-opt-report llvm-pdbutil is a PDB (Program Database) dumper. PDB is a Microsoft format llvm-pdbutil llvm-profdata is a small tool to manipulate and print profile data files llvm-profdata llvm-profgen generates LLVM SPGO profiling information llvm-profgen llvm-ranlib is used to generate an index for a LLVM archive llvm-ranlib llvm-rc is a platform-independent tool to compile resource scripts into binary resource files llvm-rc llvm-readobj displays low-level format-specific information about object files llvm-readobj llvm-readtapi is the LLVM TAPI file reader and transformer llvm-readtapi llvm-reduce is used to automatically reduce testcases when running a test suite llvm-reduce llvm-remarkutil converts remark files between bitstream and YAML; or prints function instruction count information in remark files llvm-remarkutil llvm-rtdyld is the LLVM MC-JIT tool llvm-rtdyld llvm-size is the LLVM object size dumper llvm-size llvm-split is the LLVM module splitter llvm-split llvm-stress is used to generate random .ll files llvm-stress llvm-strings print strings found in a binary (object file, executable, or archive library) llvm-strings llvm-symbolizer converts addresses into source code locations llvm-symbolizer llvm-tblgen is the LLVM Target Description To C++ Code Generator llvm-tblgen llvm-tli-checker is the LLVM TargetLibraryInfo versus SDK checker llvm-tli-checker llvm-undname is a tool to demangle names llvm-undname llvm-xray is an implementation of Google's XRay function call tracing system llvm-xray nvptx-arch lists NVIDIA GPUs installed; at runtime it needs libcuda.so which is not a part of BLFS nvptx-arch opt is the LLVM optimizer opt sancov is the sanitizer coverage processing tool sancov sanstats is the sanitizer statistics processing tool sanstats scan-build is a Perl script that invokes the Clang static analyzer scan-build scan-build-py is a Python script that invokes the Clang static analyzer scan-build-py scan-view is a viewer for Clang static analyzer results scan-view verify-uselistorder is the LLVM tool to verify use-list order verify-uselistorder