Skip to content

Files

Latest commit

Apr 7, 2025
2940304 · Apr 7, 2025

History

History

libbpf-tools

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Mar 30, 2025
Sep 1, 2022
Aug 29, 2022
Mar 30, 2025
Mar 30, 2025
Mar 30, 2025
Mar 30, 2025
Mar 30, 2025
Oct 30, 2024
Oct 30, 2024
Apr 6, 2022
Apr 6, 2022
Apr 10, 2024
Apr 30, 2024
Dec 18, 2021
Jan 1, 2024
Apr 30, 2024
Oct 25, 2023
Nov 6, 2023
Apr 30, 2024
Oct 1, 2020
Jul 11, 2022
Apr 30, 2024
Oct 1, 2020
Mar 21, 2025
Apr 30, 2024
Oct 1, 2020
Jul 30, 2023
Apr 30, 2024
Oct 1, 2020
Dec 7, 2023
Apr 30, 2024
Sep 19, 2022
Mar 20, 2025
Apr 30, 2024
Oct 1, 2020
Dec 10, 2021
Jul 16, 2020
Apr 6, 2022
Apr 6, 2022
Mar 26, 2023
Apr 30, 2024
Dec 14, 2022
Jun 16, 2024
Dec 14, 2022
Oct 12, 2022
Oct 12, 2022
Dec 31, 2022
Mar 30, 2025
Nov 26, 2022
Apr 30, 2024
Jun 3, 2020
May 2, 2022
Apr 30, 2024
Jan 15, 2021
Dec 31, 2022
Apr 7, 2025
Oct 1, 2020
Apr 7, 2025
Mar 15, 2021
Jun 2, 2020
Feb 29, 2024
Apr 30, 2024
Jul 1, 2021
May 2, 2022
Apr 30, 2024
Aug 8, 2021
Nov 12, 2023
Apr 30, 2024
Nov 12, 2023
Jan 31, 2022
Apr 30, 2024
Jan 31, 2022
Dec 5, 2022
Oct 30, 2024
Dec 5, 2022
Dec 5, 2022
Oct 30, 2024
Dec 5, 2022
May 15, 2023
Apr 30, 2024
Mar 5, 2021
Feb 29, 2024
Aug 4, 2024
Nov 27, 2023
Apr 10, 2024
Nov 9, 2024
Jul 14, 2021
Feb 9, 2025
Oct 20, 2024
Sep 17, 2020
Mar 26, 2025
Jul 19, 2024
Nov 23, 2024
Aug 8, 2022
Mar 14, 2020
Mar 26, 2025
Mar 26, 2025
Mar 26, 2025
Oct 5, 2023
Mar 24, 2023
Jan 10, 2024
Jun 24, 2022
Apr 30, 2024
Jun 24, 2022
May 19, 2024
Jul 9, 2020
Apr 17, 2023
Dec 31, 2022
Apr 30, 2024
Jan 19, 2022
Mar 21, 2025
Mar 21, 2025
Nov 14, 2024
Jan 8, 2025
Jan 8, 2025
Jan 8, 2025
Apr 15, 2024
Apr 30, 2024
Nov 9, 2024
Nov 9, 2024
Oct 20, 2024
Oct 24, 2022
Apr 30, 2024
Feb 11, 2022
Feb 9, 2025
Feb 9, 2025
Feb 9, 2025
Dec 18, 2024
Dec 18, 2024
Jun 22, 2024
Apr 1, 2025
Apr 1, 2025
Oct 1, 2020
Sep 8, 2022
Apr 30, 2024
Sep 17, 2020
Mar 30, 2025
Apr 30, 2024
Sep 18, 2020
Sep 8, 2022
Apr 30, 2024
Aug 20, 2021
Feb 13, 2020
Jul 28, 2024
Mar 3, 2025
Jul 22, 2022
Jul 22, 2022
Dec 18, 2024
Dec 18, 2024
Jun 10, 2022
Feb 11, 2025
Oct 20, 2024
Sep 17, 2020
Jul 1, 2021
Apr 30, 2024
Dec 10, 2022
Jul 29, 2021
Mar 30, 2025
Mar 20, 2025
Mar 20, 2025
Jul 28, 2024
Jul 28, 2024
Jul 28, 2024
Apr 3, 2025
Jun 2, 2020
Jul 3, 2022
May 9, 2024
Jun 2, 2020
Jul 28, 2022
Jul 4, 2024
Jul 28, 2022
Apr 28, 2023
Apr 30, 2024
Nov 30, 2021
Jun 10, 2022
Apr 30, 2024
Jun 10, 2022
Jul 10, 2023
Apr 30, 2024
Jul 10, 2023
Jun 20, 2023
Jul 10, 2023
Apr 30, 2024
Jul 10, 2023
Sep 15, 2022
Apr 30, 2024
Sep 15, 2022
Jan 17, 2022
Apr 30, 2024
Jan 17, 2022
Sep 15, 2022
May 19, 2024
Sep 15, 2022
May 19, 2024
Mar 29, 2025
Apr 30, 2024
Jul 13, 2022
Dec 18, 2024
Dec 18, 2024
Dec 17, 2022
May 1, 2021
May 10, 2024
May 10, 2024
May 10, 2024
Sep 9, 2022
Jul 3, 2024
Sep 9, 2022

Useful links

Building

To build libbpf-based tools, simply run make. This will build all the listed tools/applications. All the build artifacts, by default, go into .output subdirectory to keep source code and build artifacts completely separate. The only exception is resulting tool binaries, which are put in a current directory. make clean will clean up all the build artifacts, including generated binaries.

Given that the libbpf package might not be available across wide variety of distributions, all libbpf-based tools are linked statically against a version of libbpf that BCC links against (from submodule under src/cc/libbpf). This results in binaries with minimal amount of dependencies (libc, libelf, and libz are linked dynamically, though, given their widespread availability). If your build fails because the libbpf submodule is outdated, try running git submodule update --init --recursive.

Tools are expected to follow a simple naming convention:

  • .c contains userspace C code of a tool.
  • .bpf.c contains BPF C code, which gets compiled into BPF ELF file. This ELF file is used to generate BPF skeleton .skel.h, which is subsequently is included from .c.
  • .h can optionally contain any types and constants, shared by both BPF and userspace sides of a tool.

For such cases, simply adding name to Makefile's APPS variable will ensure this tool is built alongside others.

For more complicated applications, some extra Makefile rules might need to be created. For such cases, it is advised to put application into a dedicated subdirectory and link it from main Makefile.

vmlinux.h generation

vmlinux.h contains all kernel types, both exported and internal-only. BPF CO-RE-based applications are expected to include this file in their BPF program C source code to avoid dependency on kernel headers package.

For more reproducible builds, vmlinux.h header file is pre-generated and checked in along the other sources. This is done to avoid dependency on specific user/build server's kernel configuration, because vmlinux.h generation depends on having a kernel with BTF type information built-in (which is enabled by CONFIG_DEBUG_INFO_BTF=y Kconfig option See below).

vmlinux.h is generated from upstream Linux version at particular minor version tag. E.g., vmlinux_505.h is generated from v5.5 tag. Exact set of types available in compiled kernel depends on configuration used to compile it. To generate present vmlinux.h header, default configuration was used, with only extra CONFIG_DEBUG_INFO_BTF=y option enabled.

Given different kernel version can have incompatible type definitions, it might be important to use vmlinux.h of a specific kernel version as a "base" version of header. To that extent, all vmlinux.h headers are versioned by appending suffix to a file name. There is always a symbolic link vmlinux.h, that points to whichever version is deemed to be default (usually, latest).

bpftool

bpftool is a universal tool used for inspection of BPF resources, as well as providing various extra BPF-related facilities, like code-generation of BPF program skeletons. The latter functionality is heavily used by these tools to load and interact with BPF programs.

Given bpftool package can't yet be expected to be available widely across many distributions, bpftool binary is checked in into BCC repository in bin/ subdirectory. Once bpftool package is more widely available, this can be changed in favor of using pre-packaged version of bpftool.

Re-compiling your Kernel with CONFIG_DEBUG_INFO_BTF=y

libbpf probes to see if your sys fs exports the file /sys/kernel/btf/vmlinux (from Kernel 5.5+) or if you have the ELF version in your system code Please note the ELF file could exist without the BTF info in it. Your Kconfig should contain the options below

  1. Compile options
CONFIG_DEBUG_INFO_BTF=y
CONFIG_DEBUG_INFO=y
  1. Also, make sure that you have pahole 1.13 (or preferably 1.16+) during the kernel build (it comes from dwarves package). Without it, BTF won't be generated, and on older kernels you'd get only warning, but still would build kernel successfully

Running in kernels without CONFIG_DEBUG_INFO_BTF=y

It's possible to run some tools in kernels that don't expose /sys/kernel/btf/vmlinux. For those cases, BTFGen and BTFHub can be used to generate small BTF files for the most popular Linux distributions that are shipped with the tools in order to provide the needed information to perform the CO-RE relocations when loading the eBPF programs.

If you haven't cloned the btfhub-archive repository, you can run make and it'll clone it for you into the $HOME/.local/share directory:

make ENABLE_MIN_CORE_BTFS=1 -j$(nproc)

If you have a local copy of such repository, you can pass it's location to avoid cloning it again:

make ENABLE_MIN_CORE_BTFS=1 BTF_HUB_ARCHIVE=<path_to_btfhub-archive> -j$(nproc)