|
| 1 | +.. _libc_uefi_building: |
| 2 | + |
| 3 | +====================== |
| 4 | +Building libc for UEFI |
| 5 | +====================== |
| 6 | + |
| 7 | +.. contents:: Table of Contents |
| 8 | + :depth: 4 |
| 9 | + :local: |
| 10 | + |
| 11 | +Building LLVM libc for UEFI |
| 12 | +=========================== |
| 13 | + |
| 14 | +This document will present recipes to build the LLVM C library for UEFI. |
| 15 | +UEFI builds use the same :ref:`cross build<full_cross_build>` support as |
| 16 | +the other targets. However, the UEFI target has the restriction that it *must* |
| 17 | +be built with an up-to-date ``clang`` compiler. This is because UEFI support |
| 18 | +in ``clang`` is still an experimental feature. |
| 19 | + |
| 20 | +Currently, it is only possible to build LLVM libc for UEFI for ``x86_64`` |
| 21 | +CPUs. This is due to the target not being enabled for ``aarch64`` and |
| 22 | +``riscv64``. |
| 23 | + |
| 24 | +Once you have finished building, refer to :ref:`libc_uefi_usage` to get started |
| 25 | +with the newly built C library. |
| 26 | + |
| 27 | +Standard runtimes build |
| 28 | +----------------------- |
| 29 | + |
| 30 | +The simplest way to build for UEFI is to use the existing LLVM runtimes |
| 31 | +support. This will automatically handle bootstrapping an up-to-date ``clang`` |
| 32 | +compiler and use it to build the C library. The following CMake invocation |
| 33 | +will instruct it to build the ``libc`` runtime targeting ``x86_64`` CPUs. |
| 34 | + |
| 35 | +.. code-block:: sh |
| 36 | +
|
| 37 | + $> cd llvm-project # The llvm-project checkout |
| 38 | + $> mkdir build |
| 39 | + $> cd build |
| 40 | + $> cmake ../llvm -G Ninja \ |
| 41 | + -DLLVM_ENABLE_PROJECTS="clang;lld" \ |
| 42 | + -DCMAKE_BUILD_TYPE=<Debug|Release> \ # Select build type |
| 43 | + -DCMAKE_INSTALL_PREFIX=<PATH> \ # Where the libraries will live |
| 44 | + -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-uefi-llvm \ |
| 45 | + -DLLVM_RUNTIME_TARGETS=x86_64-unknown-uefi-llvm \ |
| 46 | + -DRUNTIMES_x86_64-unknown-uefi-llvm_LLVM_ENABLE_RUNTIMES=libc \ |
| 47 | + -DRUNTIMES_x86_64-unknown-uefi-llvm_LLVM_LIBC_FULL_BUILD=true \ |
| 48 | + $> ninja install |
| 49 | +
|
| 50 | +We need ``clang`` to build the UEFI C library and ``lld`` to link UEFI PE |
| 51 | +executables, so we enable them in ``LLVM_ENABLE_PROJECTS``. We then set |
| 52 | +``RUNTIMES_<triple>_LLVM_ENABLE_RUNTIMES`` to enable ``libc`` for the UEFI |
| 53 | +targets. |
0 commit comments