blob: 79f9a58f1872714ce6dd1047cb9d1dbd8842ad60 [file] [log] [blame]
Jesper Dangaard Brouer1c975662016-04-28 14:21:04 +02001eBPF sample programs
2====================
3
Joe Stringer43371c82016-12-14 14:43:39 -08004This directory contains a test stubs, verifier test-suite and examples
5for using eBPF. The examples use libbpf from tools/lib/bpf.
Jesper Dangaard Brouer1c975662016-04-28 14:21:04 +02006
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
Jesper Dangaard Brouerb62a7962016-04-28 14:21:09 +020039It is also possible to call make from this directory. This will just
40hide the the invocation of make as above with the appended "/".
41
Jesper Dangaard Brouer1c975662016-04-28 14:21:04 +020042Manually 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
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +020063It 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::
Jesper Dangaard Brouer1c975662016-04-28 14:21:04 +020065
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +020066 make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang