Jesper Dangaard Brouer | 1c97566 | 2016-04-28 14:21:04 +0200 | [diff] [blame] | 1 | eBPF sample programs |
| 2 | ==================== |
| 3 | |
| 4 | This directory contains a mini eBPF library, test stubs, verifier |
| 5 | test-suite and examples for using eBPF. |
| 6 | |
| 7 | Build dependencies |
| 8 | ================== |
| 9 | |
| 10 | Compiling requires having installed: |
| 11 | * clang >= version 3.4.0 |
| 12 | * llvm >= version 3.7.1 |
| 13 | |
| 14 | Note that LLVM's tool 'llc' must support target 'bpf', list version |
| 15 | and supported targets with command: ``llc --version`` |
| 16 | |
| 17 | Kernel headers |
| 18 | -------------- |
| 19 | |
| 20 | There are usually dependencies to header files of the current kernel. |
| 21 | To avoid installing devel kernel headers system wide, as a normal |
| 22 | user, simply call:: |
| 23 | |
| 24 | make headers_install |
| 25 | |
| 26 | This will creates a local "usr/include" directory in the git/build top |
| 27 | level directory, that the make system automatically pickup first. |
| 28 | |
| 29 | Compiling |
| 30 | ========= |
| 31 | |
| 32 | For building the BPF samples, issue the below command from the kernel |
| 33 | top level directory:: |
| 34 | |
| 35 | make samples/bpf/ |
| 36 | |
| 37 | Do notice the "/" slash after the directory name. |
| 38 | |
Jesper Dangaard Brouer | b62a796 | 2016-04-28 14:21:09 +0200 | [diff] [blame] | 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 "/". |
| 41 | |
Jesper Dangaard Brouer | 1c97566 | 2016-04-28 14:21:04 +0200 | [diff] [blame] | 42 | Manually compiling LLVM with 'bpf' support |
| 43 | ------------------------------------------ |
| 44 | |
| 45 | Since version 3.7.0, LLVM adds a proper LLVM backend target for the |
| 46 | BPF bytecode architecture. |
| 47 | |
| 48 | By default llvm will build all non-experimental backends including bpf. |
| 49 | To generate a smaller llc binary one can use:: |
| 50 | |
| 51 | -DLLVM_TARGETS_TO_BUILD="BPF" |
| 52 | |
| 53 | Quick 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 Brouer | bdefbbf | 2016-04-28 14:21:14 +0200 | [diff] [blame] | 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:: |
Jesper Dangaard Brouer | 1c97566 | 2016-04-28 14:21:04 +0200 | [diff] [blame] | 65 | |
Jesper Dangaard Brouer | bdefbbf | 2016-04-28 14:21:14 +0200 | [diff] [blame] | 66 | make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang |