README.rst 1.9 KB

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