Linux Audio

Check our new training course

Loading...
v6.8
  1eBPF sample programs
  2====================
  3
  4This directory contains a test stubs, verifier test-suite and examples
  5for using eBPF. The examples use libbpf from tools/lib/bpf.
  6
  7Note that the XDP-specific samples have been removed from this directory and
  8moved to the xdp-tools repository: https://github.com/xdp-project/xdp-tools
  9See the commit messages removing each tool from this directory for how to
 10convert specific command invocations between the old samples and the utilities
 11in xdp-tools.
 12
 13Build dependencies
 14==================
 15
 16Compiling requires having installed:
 17 * clang
 18 * llvm
 19 * pahole
 20
 21Consult :ref:`Documentation/process/changes.rst <changes>` for the minimum
 22version numbers required and how to update them. Note that LLVM's tool
 23'llc' must support target 'bpf', list version and supported targets with
 24command: ``llc --version``
 25
 26Clean and configuration
 27-----------------------
 28
 29It can be needed to clean tools, samples or kernel before trying new arch or
 30after some changes (on demand)::
 31
 32 make -C tools clean
 33 make -C samples/bpf clean
 34 make clean
 35
 36Configure kernel, defconfig for instance
 37(see "tools/testing/selftests/bpf/config" for a reference config)::
 38
 39 make defconfig
 40
 41Kernel headers
 42--------------
 43
 44There are usually dependencies to header files of the current kernel.
 45To avoid installing devel kernel headers system wide, as a normal
 46user, simply call::
 47
 48 make headers_install
 49
 50This will create a local "usr/include" directory in the git/build top
 51level directory, that the make system will automatically pick up first.
 52
 53Compiling
 54=========
 55
 56For building the BPF samples, issue the below command from the kernel
 57top level directory::
 58
 59 make M=samples/bpf
 
 
 60
 61It is also possible to call make from this directory.  This will just
 62hide the invocation of make as above.
 63
 64Manually compiling LLVM with 'bpf' support
 65------------------------------------------
 66
 67Since version 3.7.0, LLVM adds a proper LLVM backend target for the
 68BPF bytecode architecture.
 69
 70By default llvm will build all non-experimental backends including bpf.
 71To generate a smaller llc binary one can use::
 72
 73 -DLLVM_TARGETS_TO_BUILD="BPF"
 74
 75We recommend that developers who want the fastest incremental builds
 76use the Ninja build system, you can find it in your system's package
 77manager, usually the package is ninja or ninja-build.
 78
 79Quick sniplet for manually compiling LLVM and clang
 80(build dependencies are ninja, cmake and gcc-c++)::
 81
 82 $ git clone https://github.com/llvm/llvm-project.git
 83 $ mkdir -p llvm-project/llvm/build
 84 $ cd llvm-project/llvm/build
 85 $ cmake .. -G "Ninja" -DLLVM_TARGETS_TO_BUILD="BPF;X86" \
 86            -DLLVM_ENABLE_PROJECTS="clang"    \
 87            -DCMAKE_BUILD_TYPE=Release        \
 88            -DLLVM_BUILD_RUNTIME=OFF
 89 $ ninja
 90
 91It is also possible to point make to the newly compiled 'llc' or
 92'clang' command via redefining LLC or CLANG on the make command line::
 93
 94 make M=samples/bpf LLC=~/git/llvm-project/llvm/build/bin/llc CLANG=~/git/llvm-project/llvm/build/bin/clang
 95
 96Cross compiling samples
 97-----------------------
 98In order to cross-compile, say for arm64 targets, export CROSS_COMPILE and ARCH
 99environment variables before calling make. But do this before clean,
100configuration and header install steps described above. This will direct make to
101build samples for the cross target::
102
103 export ARCH=arm64
104 export CROSS_COMPILE="aarch64-linux-gnu-"
105
106Headers can be also installed on RFS of target board if need to keep them in
107sync (not necessarily and it creates a local "usr/include" directory also)::
108
109 make INSTALL_HDR_PATH=~/some_sysroot/usr headers_install
110
111Pointing LLC and CLANG is not necessarily if it's installed on HOST and have
112in its targets appropriate arm64 arch (usually it has several arches).
113Build samples::
114
115 make M=samples/bpf
116
117Or build samples with SYSROOT if some header or library is absent in toolchain,
118say libelf, providing address to file system containing headers and libs,
119can be RFS of target board::
120
121 make M=samples/bpf SYSROOT=~/some_sysroot
 
 
v5.4
 1eBPF sample programs
 2====================
 3
 4This directory contains a test stubs, verifier test-suite and examples
 5for using eBPF. The examples use libbpf from tools/lib/bpf.
 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
68Cross compiling samples
69-----------------------
70In order to cross-compile, say for arm64 targets, export CROSS_COMPILE and ARCH
71environment variables before calling make. This will direct make to build
72samples for the cross target.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
74export ARCH=arm64
75export CROSS_COMPILE="aarch64-linux-gnu-"
76make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang