1This is a mirror of [bpf-next Linux source 2tree](https://kernel.googlesource.com/pub/scm/linux/kernel/git/bpf/bpf-next)'s 3`tools/lib/bpf` directory plus its supporting header files. 4 5All the gory details of syncing can be found in `scripts/sync-kernel.sh` 6script. 7 8Some header files in this repo (`include/linux/*.h`) are reduced versions of 9their counterpart files at 10[bpf-next](https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/)'s 11`tools/include/linux/*.h` to make compilation successful. 12 13BPF/libbpf usage and questions 14============================== 15 16Please check out [libbpf-bootstrap](https://github.com/libbpf/libbpf-bootstrap) 17and [the companion blog post](https://nakryiko.com/posts/libbpf-bootstrap/) for 18the examples of building BPF applications with libbpf. 19[libbpf-tools](https://github.com/iovisor/bcc/tree/master/libbpf-tools) are also 20a good source of the real-world libbpf-based tracing tools. 21 22See also ["BPF CO-RE reference guide"](https://nakryiko.com/posts/bpf-core-reference-guide/) 23for the coverage of practical aspects of building BPF CO-RE applications and 24["BPF CO-RE"](https://nakryiko.com/posts/bpf-portability-and-co-re/) for 25general introduction into BPF portability issues and BPF CO-RE origins. 26 27All general BPF questions, including kernel functionality, libbpf APIs and 28their application, should be sent to bpf@vger.kernel.org mailing list. You can 29subscribe to it [here](http://vger.kernel.org/vger-lists.html#bpf) and search 30its archive [here](https://lore.kernel.org/bpf/). Please search the archive 31before asking new questions. It very well might be that this was already 32addressed or answered before. 33 34bpf@vger.kernel.org is monitored by many more people and they will happily try 35to help you with whatever issue you have. This repository's PRs and issues 36should be opened only for dealing with issues pertaining to specific way this 37libbpf mirror repo is set up and organized. 38 39Build 40[![Github Actions Builds & Tests](https://github.com/libbpf/libbpf/actions/workflows/test.yml/badge.svg)](https://github.com/libbpf/libbpf/actions/workflows/test.yml) 41[![Total alerts](https://img.shields.io/lgtm/alerts/g/libbpf/libbpf.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/libbpf/libbpf/alerts/) 42[![Coverity](https://img.shields.io/coverity/scan/18195.svg)](https://scan.coverity.com/projects/libbpf) 43[![OSS-Fuzz Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/libbpf.svg)](https://oss-fuzz-build-logs.storage.googleapis.com/index.html#libbpf) 44===== 45libelf is an internal dependency of libbpf and thus it is required to link 46against and must be installed on the system for applications to work. 47pkg-config is used by default to find libelf, and the program called can be 48overridden with `PKG_CONFIG`. 49 50If using `pkg-config` at build time is not desired, it can be disabled by 51setting `NO_PKG_CONFIG=1` when calling make. 52 53To build both static libbpf.a and shared libbpf.so: 54```bash 55$ cd src 56$ make 57``` 58 59To build only static libbpf.a library in directory 60build/ and install them together with libbpf headers in a staging directory 61root/: 62```bash 63$ cd src 64$ mkdir build root 65$ BUILD_STATIC_ONLY=y OBJDIR=build DESTDIR=root make install 66``` 67 68To build both static libbpf.a and shared libbpf.so against a custom libelf 69dependency installed in /build/root/ and install them together with libbpf 70headers in a build directory /build/root/: 71```bash 72$ cd src 73$ PKG_CONFIG_PATH=/build/root/lib64/pkgconfig DESTDIR=/build/root make install 74``` 75 76BPF CO-RE (Compile Once – Run Everywhere) 77========================================= 78 79Libbpf supports building BPF CO-RE-enabled applications, which, in contrast to 80[BCC](https://github.com/iovisor/bcc/), do not require Clang/LLVM runtime 81being deployed to target servers and doesn't rely on kernel-devel headers 82being available. 83 84It does rely on kernel to be built with [BTF type 85information](https://www.kernel.org/doc/html/latest/bpf/btf.html), though. 86Some major Linux distributions come with kernel BTF already built in: 87 - Fedora 31+ 88 - RHEL 8.2+ 89 - OpenSUSE Tumbleweed (in the next release, as of 2020-06-04) 90 - Arch Linux (from kernel 5.7.1.arch1-1) 91 - Manjaro (from kernel 5.4 if compiled after 2021-06-18) 92 - Ubuntu 20.10 93 - Debian 11 (amd64/arm64) 94 95If your kernel doesn't come with BTF built-in, you'll need to build custom 96kernel. You'll need: 97 - `pahole` 1.16+ tool (part of `dwarves` package), which performs DWARF to 98 BTF conversion; 99 - kernel built with `CONFIG_DEBUG_INFO_BTF=y` option; 100 - you can check if your kernel has BTF built-in by looking for 101 `/sys/kernel/btf/vmlinux` file: 102 103```shell 104$ ls -la /sys/kernel/btf/vmlinux 105-r--r--r--. 1 root root 3541561 Jun 2 18:16 /sys/kernel/btf/vmlinux 106``` 107 108To develop and build BPF programs, you'll need Clang/LLVM 10+. The following 109distributions have Clang/LLVM 10+ packaged by default: 110 - Fedora 32+ 111 - Ubuntu 20.04+ 112 - Arch Linux 113 - Ubuntu 20.10 (LLVM 11) 114 - Debian 11 (LLVM 11) 115 - Alpine 3.13+ 116 117Otherwise, please make sure to update it on your system. 118 119The following resources are useful to understand what BPF CO-RE is and how to 120use it: 121- [BPF CO-RE reference guide](https://nakryiko.com/posts/bpf-core-reference-guide/) 122- [BPF Portability and CO-RE](https://nakryiko.com/posts/bpf-portability-and-co-re/) 123- [HOWTO: BCC to libbpf conversion](https://nakryiko.com/posts/bcc-to-libbpf-howto-guide/) 124- [libbpf-tools in BCC repo](https://github.com/iovisor/bcc/tree/master/libbpf-tools) 125 contain lots of real-world tools converted from BCC to BPF CO-RE. Consider 126 converting some more to both contribute to the BPF community and gain some 127 more experience with it. 128 129Distributions 130============= 131 132Distributions packaging libbpf from this mirror: 133 - [Fedora](https://src.fedoraproject.org/rpms/libbpf) 134 - [Gentoo](https://packages.gentoo.org/packages/dev-libs/libbpf) 135 - [Debian](https://packages.debian.org/source/sid/libbpf) 136 - [Arch](https://www.archlinux.org/packages/extra/x86_64/libbpf/) 137 - [Ubuntu](https://packages.ubuntu.com/source/impish/libbpf) 138 - [Alpine](https://pkgs.alpinelinux.org/packages?name=libbpf) 139 140Benefits of packaging from the mirror over packaging from kernel sources: 141 - Consistent versioning across distributions. 142 - No ties to any specific kernel, transparent handling of older kernels. 143 Libbpf is designed to be kernel-agnostic and work across multitude of 144 kernel versions. It has built-in mechanisms to gracefully handle older 145 kernels, that are missing some of the features, by working around or 146 gracefully degrading functionality. Thus libbpf is not tied to a specific 147 kernel version and can/should be packaged and versioned independently. 148 - Continuous integration testing via 149 [TravisCI](https://travis-ci.org/libbpf/libbpf). 150 - Static code analysis via [LGTM](https://lgtm.com/projects/g/libbpf/libbpf) 151 and [Coverity](https://scan.coverity.com/projects/libbpf). 152 153Package dependencies of libbpf, package names may vary across distros: 154 - zlib 155 - libelf 156 157[![libbpf distro packaging status](https://repology.org/badge/vertical-allrepos/libbpf.svg)](https://repology.org/project/libbpf/versions) 158 159License 160======= 161 162This work is dual-licensed under BSD 2-clause license and GNU LGPL v2.1 license. 163You can choose between one of them if you use this work. 164 165`SPDX-License-Identifier: BSD-2-Clause OR LGPL-2.1` 166