README.rst 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. eBPF sample programs
  2. ====================
  3. This directory contains a test stubs, verifier test-suite and examples
  4. for using eBPF. The examples use libbpf from tools/lib/bpf.
  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. Clean and configuration
  13. -----------------------
  14. It can be needed to clean tools, samples or kernel before trying new arch or
  15. after some changes (on demand)::
  16. make -C tools clean
  17. make -C samples/bpf clean
  18. make clean
  19. Configure kernel, defconfig for instance::
  20. make defconfig
  21. Kernel headers
  22. --------------
  23. There are usually dependencies to header files of the current kernel.
  24. To avoid installing devel kernel headers system wide, as a normal
  25. user, simply call::
  26. make headers_install
  27. This will creates a local "usr/include" directory in the git/build top
  28. level directory, that the make system automatically pickup first.
  29. Compiling
  30. =========
  31. For building the BPF samples, issue the below command from the kernel
  32. top level directory::
  33. make M=samples/bpf
  34. It is also possible to call make from this directory. This will just
  35. hide the invocation of make as above.
  36. Manually compiling LLVM with 'bpf' support
  37. ------------------------------------------
  38. Since version 3.7.0, LLVM adds a proper LLVM backend target for the
  39. BPF bytecode architecture.
  40. By default llvm will build all non-experimental backends including bpf.
  41. To generate a smaller llc binary one can use::
  42. -DLLVM_TARGETS_TO_BUILD="BPF"
  43. Quick sniplet for manually compiling LLVM and clang
  44. (build dependencies are cmake and gcc-c++)::
  45. $ git clone http://llvm.org/git/llvm.git
  46. $ cd llvm/tools
  47. $ git clone --depth 1 http://llvm.org/git/clang.git
  48. $ cd ..; mkdir build; cd build
  49. $ cmake .. -DLLVM_TARGETS_TO_BUILD="BPF;X86"
  50. $ make -j $(getconf _NPROCESSORS_ONLN)
  51. It is also possible to point make to the newly compiled 'llc' or
  52. 'clang' command via redefining LLC or CLANG on the make command line::
  53. make M=samples/bpf LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
  54. Cross compiling samples
  55. -----------------------
  56. In order to cross-compile, say for arm64 targets, export CROSS_COMPILE and ARCH
  57. environment variables before calling make. But do this before clean,
  58. cofiguration and header install steps described above. This will direct make to
  59. build samples for the cross target::
  60. export ARCH=arm64
  61. export CROSS_COMPILE="aarch64-linux-gnu-"
  62. Headers can be also installed on RFS of target board if need to keep them in
  63. sync (not necessarily and it creates a local "usr/include" directory also)::
  64. make INSTALL_HDR_PATH=~/some_sysroot/usr headers_install
  65. Pointing LLC and CLANG is not necessarily if it's installed on HOST and have
  66. in its targets appropriate arm64 arch (usually it has several arches).
  67. Build samples::
  68. make M=samples/bpf
  69. Or build samples with SYSROOT if some header or library is absent in toolchain,
  70. say libelf, providing address to file system containing headers and libs,
  71. can be RFS of target board::
  72. make M=samples/bpf SYSROOT=~/some_sysroot