7 .. contents:: Table of Contents
11 In this document, we will present a recipe to build the full libc for the host.
12 When we say *build the libc for the host*, the goal is to build the libc for
13 the same system on which the libc is being built. Also, we will take this
14 opportunity to demonstrate how one can set up a *sysroot* (see the documentation
15 of the ``--sysroot`` option here:
16 `<https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html>`_) which includes
17 not only the components of LLVM's libc, but also a full LLVM only toolchain
18 consisting of the `clang <https://clang.llvm.org/>`_ compiler, the
19 `lld <https://lld.llvm.org/>`_ linker and the
20 `compiler-rt <https://compiler-rt.llvm.org/>`_ runtime libraries. LLVM's libc is
21 not yet complete enough to allow using and linking a C++ application against
22 a C++ standard library (like libc++). Hence, we do not include
23 `libc++ <https://libcxx.llvm.org/>`_ in the sysroot.
25 .. note:: When the libc is complete enough, we should be able to include
26 `libc++ <https://libcxx.llvm.org/>`_, libcxx-abi and libunwind in the
27 LLVM only toolchain and use them to build and link C++ applications.
29 Configure the full libc build
30 ===============================
32 Below is the list of commands for a simple recipe to build and install the
33 libc components along with other components of an LLVM only toolchain.
37 $> cd llvm-project # The llvm-project checkout
41 -G Ninja \ # Generator
42 -DLLVM_ENABLE_PROJECTS="clang;libc;lld;compiler-rt" \ # Enabled projects
43 -DCMAKE_BUILD_TYPE=<Debug|Release> \ # Select build type
44 -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
45 -DLLVM_LIBC_FULL_BUILD=ON \ # We want the full libc
46 -DLLVM_LIBC_INCLUDE_SCUDO=ON \ # Include Scudo in the libc
47 -DCOMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC=ON \
48 -DCOMPILER_RT_BUILD_GWP_ASAN=OFF \
49 -DCOMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED=OFF \
50 -DCMAKE_INSTALL_PREFIX=<SYSROOT> # Specify a sysroot directory
52 We will go over some of the special options passed to the ``cmake`` command
55 * **Enabled Projects** - Since we want to build and install clang, lld
56 and compiler-rt along with the libc, we specify
57 ``clang;libc;lld;compiler-rt`` as the list of enabled projects.
58 * **The full build option** - Since we want to do build the full libc, we pass
59 ``-DLLVM_LIBC_FULL_BUILD=ON``.
60 * **Scudo related options** - LLVM's libc uses
61 `Scudo <https://llvm.org/docs/ScudoHardenedAllocator.html>`_ as its allocator.
62 So, when building the full libc, we should specify that we want to include
63 Scudo in the libc. Since the libc currently only supports static linking, we
64 also specify that we do not want to build the Scudo shared library.
65 * **The install prefix** - This is the path to the tool chain install directory.
66 This is the directory where you intend to set up the sysroot.
71 After configuring the build with the above ``cmake`` command, one can build and
72 install the libc, clang (and its support libraries and builtins), lld and
73 compiler-rt, with the following command:
77 $> ninja install-clang install-builtins install-compiler-rt \
78 install-core-resource-headers install-libc install-lld
80 Once the above command completes successfully, the ``<SYSROOT>`` directory you
81 have specified with the CMake configure step above will contain a full LLVM-only
82 toolchain with which you can build practical/real-world C applications. See
83 `<https://github.com/llvm/llvm-project/tree/main/libc/examples>`_ for examples
84 of how to start using this new toolchain.
89 If you are using the full libc on Linux, then you will also need to install
90 Linux headers in your sysroot. It is left to the reader to figure out the best
91 way to install Linux headers on the system they want to use the full libc on.