xref: /openbmc/linux/samples/bpf/README.rst (revision 78700c0a)
1eBPF sample programs
2====================
3
4This directory contains a mini eBPF library, test stubs, verifier
5test-suite and examples for using eBPF.
6
7Build dependencies
8==================
9
10Compiling requires having installed:
11 * clang >= version 3.4.0
12 * llvm >= version 3.7.1
13
14Note that LLVM's tool 'llc' must support target 'bpf', list version
15and supported targets with command: ``llc --version``
16
17Kernel headers
18--------------
19
20There are usually dependencies to header files of the current kernel.
21To avoid installing devel kernel headers system wide, as a normal
22user, simply call::
23
24 make headers_install
25
26This will creates a local "usr/include" directory in the git/build top
27level directory, that the make system automatically pickup first.
28
29Compiling
30=========
31
32For building the BPF samples, issue the below command from the kernel
33top level directory::
34
35 make samples/bpf/
36
37Do notice the "/" slash after the directory name.
38
39It is also possible to call make from this directory.  This will just
40hide the the invocation of make as above with the appended "/".
41
42Manually compiling LLVM with 'bpf' support
43------------------------------------------
44
45Since version 3.7.0, LLVM adds a proper LLVM backend target for the
46BPF bytecode architecture.
47
48By default llvm will build all non-experimental backends including bpf.
49To generate a smaller llc binary one can use::
50
51 -DLLVM_TARGETS_TO_BUILD="BPF"
52
53Quick sniplet for manually compiling LLVM and clang
54(build dependencies are cmake and gcc-c++)::
55
56 $ git clone http://llvm.org/git/llvm.git
57 $ cd llvm/tools
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)
62
63It 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::
65
66 make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
67