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:
11 * clang >= version 3.4.0
12 * llvm >= version 3.7.1
14 Note that LLVM's tool 'llc' must support target 'bpf', list version
15 and supported targets with command: ``llc --version``
20 There are usually dependencies to header files of the current kernel.
21 To avoid installing devel kernel headers system wide, as a normal
26 This will creates a local "usr/include" directory in the git/build top
27 level directory, that the make system automatically pickup first.
32 For building the BPF samples, issue the below command from the kernel
37 Do notice the "/" slash after the directory name.
39 It is also possible to call make from this directory. This will just
40 hide the the invocation of make as above with the appended "/".
42 Manually compiling LLVM with 'bpf' support
43 ------------------------------------------
45 Since version 3.7.0, LLVM adds a proper LLVM backend target for the
46 BPF bytecode architecture.
48 By default llvm will build all non-experimental backends including bpf.
49 To generate a smaller llc binary one can use::
51 -DLLVM_TARGETS_TO_BUILD="BPF"
53 Quick sniplet for manually compiling LLVM and clang
54 (build dependencies are cmake and gcc-c++)::
56 $ git clone http://llvm.org/git/llvm.git
58 $ git clone --depth 1 http://llvm.org/git/clang.git
59 $ cd ..; mkdir build; cd build
60 $ cmake .. -DLLVM_TARGETS_TO_BUILD="BPF;X86"
61 $ make -j $(getconf _NPROCESSORS_ONLN)
63 It is also possible to point make to the newly compiled 'llc' or
64 'clang' command via redefining LLC or CLANG on the make command line::
66 make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
68 Cross compiling samples
69 -----------------------
70 In order to cross-compile, say for arm64 targets, export CROSS_COMPILE and ARCH
71 environment variables before calling make. This will direct make to build
72 samples for the cross target.
75 export CROSS_COMPILE="aarch64-linux-gnu-"
76 make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang