4 This directory contains a test stubs, verifier test-suite and examples
5 for using eBPF. The examples use libbpf from tools/lib/bpf.
10 Compiling requires having installed:
15 Consult :ref:`Documentation/process/changes.rst <changes>` for the minimum
16 version numbers required and how to update them. Note that LLVM's tool
17 'llc' must support target 'bpf', list version and supported targets with
18 command: ``llc --version``
20 Clean and configuration
21 -----------------------
23 It can be needed to clean tools, samples or kernel before trying new arch or
24 after some changes (on demand)::
27 make -C samples/bpf clean
30 Configure kernel, defconfig for instance
31 (see "tools/testing/selftests/bpf/config" for a reference config)::
38 There are usually dependencies to header files of the current kernel.
39 To avoid installing devel kernel headers system wide, as a normal
44 This will create a local "usr/include" directory in the git/build top
45 level directory, that the make system will automatically pick up first.
50 For building the BPF samples, issue the below command from the kernel
55 It is also possible to call make from this directory. This will just
56 hide the invocation of make as above.
58 Manually compiling LLVM with 'bpf' support
59 ------------------------------------------
61 Since version 3.7.0, LLVM adds a proper LLVM backend target for the
62 BPF bytecode architecture.
64 By default llvm will build all non-experimental backends including bpf.
65 To generate a smaller llc binary one can use::
67 -DLLVM_TARGETS_TO_BUILD="BPF"
69 We recommend that developers who want the fastest incremental builds
70 use the Ninja build system, you can find it in your system's package
71 manager, usually the package is ninja or ninja-build.
73 Quick sniplet for manually compiling LLVM and clang
74 (build dependencies are ninja, cmake and gcc-c++)::
76 $ git clone https://github.com/llvm/llvm-project.git
77 $ mkdir -p llvm-project/llvm/build
78 $ cd llvm-project/llvm/build
79 $ cmake .. -G "Ninja" -DLLVM_TARGETS_TO_BUILD="BPF;X86" \
80 -DLLVM_ENABLE_PROJECTS="clang" \
81 -DCMAKE_BUILD_TYPE=Release \
82 -DLLVM_BUILD_RUNTIME=OFF
85 It is also possible to point make to the newly compiled 'llc' or
86 'clang' command via redefining LLC or CLANG on the make command line::
88 make M=samples/bpf LLC=~/git/llvm-project/llvm/build/bin/llc CLANG=~/git/llvm-project/llvm/build/bin/clang
90 Cross compiling samples
91 -----------------------
92 In order to cross-compile, say for arm64 targets, export CROSS_COMPILE and ARCH
93 environment variables before calling make. But do this before clean,
94 configuration and header install steps described above. This will direct make to
95 build samples for the cross target::
98 export CROSS_COMPILE="aarch64-linux-gnu-"
100 Headers can be also installed on RFS of target board if need to keep them in
101 sync (not necessarily and it creates a local "usr/include" directory also)::
103 make INSTALL_HDR_PATH=~/some_sysroot/usr headers_install
105 Pointing LLC and CLANG is not necessarily if it's installed on HOST and have
106 in its targets appropriate arm64 arch (usually it has several arches).
111 Or build samples with SYSROOT if some header or library is absent in toolchain,
112 say libelf, providing address to file system containing headers and libs,
113 can be RFS of target board::
115 make M=samples/bpf SYSROOT=~/some_sysroot