84.6. bpftrace-0.27.0
High-level tracing language for eBPF, for tracing inside the kernel
| Version | 0.27.0, release 2 |
| Shelf | devtools — Debuggers, tracers, profilers, analysers, linters, language servers and developer utilities |
| Phase | 41_system (System), 377 of 1047 in build order |
| Licence | Apache-2.0 |
| Homepage | https://bpftrace.org/ |
| Build time | 3.6 SBU |
| Installed size | 14.9 MiB in 88 files |
| Recipe | ports/core/devtools/bpftrace/kpkgbuild |
About
bpftrace is a tracing language for the kernel’s eBPF machinery: a one-line script names a probe (a kprobe, a uprobe, a tracepoint, a timer) and what to record when it fires, and bpftrace compiles it with LLVM into BPF bytecode, loads it, and prints the maps it fills. It is how to ask why something is slow when the answer lies inside the kernel. It needs a kernel with the bpf() system call, the BPF JIT, kprobes, uprobes and BTF type information. The kernel the linux port builds from its kdos.config has all of them, and that port’s build stops if CONFIG_ is lost, so this port needs no kernel change of its own.
Why it is in KDOS
The comment above it in script/phases/41_system/packages.d/devtools.txt:
Every kernel prerequisite is already set in kdos.config — DEBUG_INFO_BTF, BPF_SYSCALL, BPF_JIT, KPROBES, UPROBES — which is what makes bpftrace a port rather than a kernel change plus a port.
Sources
bpftrace-0.27.0.tar.gz(1.5 MiB)
sha25687bf01fc3269ada7109531b0d964ceb5527d1ef7b9c9a4269b3aabdf872f0e26
upstream: https://github.com/bpftrace/bpftrace/archive/refs/tags/v0.27.0.tar.gz
archive copy: sources-1/devtools--bpftrace-0.27.0.tar.gz
Dependencies
Depends on: cmake, ninja, pkgconf, flex, bison, llvm, clang, elfutils, zlib, zstd, libbpf, bcc, cereal, libpcap, binutils, asciidoctor, gzip.
Required by: no port names it.
Patches
build.sh applies these; kpkg applies nothing by itself.
llvm-definitions.patch—LLVMConfig.cmakeexportsLLVM_DEFINITIONSas one space-separated string, andadd_definitions()takes it as one definition whose value is the rest of the string. The patch splits the string into a list before handing it on. LLVM built against libstdc++ exports-D_GLIBCXX_USE_CXX11_ABI=1first, so unpatched, the whole string becomes the value of that one macro and every compile fails under-Werror=undef.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install bpftrace'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/devtools/bpftrace.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/devtools/bpftrace
echo '87bf01fc3269ada7109531b0d964ceb5527d1ef7b9c9a4269b3aabdf872f0e26 bpftrace-0.27.0.tar.gz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/bpftrace
SRC=$SRC_ROOT/bpftrace-0.27.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf bpftrace-0.27.0.tar.gz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
patch -p1 -i $PORT_SRC/llvm-definitions.patch
mkdir -p build && cd build
cmake .. -G Ninja \
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr \
-DUSE_SYSTEM_LIBBPF=ON \
-DBUILD_TESTING=OFF \
-DENABLE_MAN=ON \
-DASCIIDOCTOR=/usr/bin/asciidoctor \
-DENABLE_SKB_OUTPUT=ON \
-DENABLE_SYSTEMD=OFF \
-DCMAKE_REQUIRE_FIND_PACKAGE_LibBfd=ON \
-DCMAKE_REQUIRE_FIND_PACKAGE_LibOpcodes=ON \
-DCMAKE_REQUIRE_FIND_PACKAGE_LibDw=ON \
-DCMAKE_REQUIRE_FIND_PACKAGE_LibPcap=ON \
-DCMAKE_DISABLE_FIND_PACKAGE_LibBlazesym=ON \
-DSTATIC_LINKING=OFF \
-DCMAKE_CXX_STANDARD_LIBRARIES="$(llvm-config --libs)"
ninja
DESTDIR=$PKG ninja install
The switches, and why each is set:
-DUSE_SYSTEM_LIBBPF=ON— By default bpftrace builds the libbpf in itslibbpf/git submodule. A GitHub tag archive carries that directory empty, so the default cannot build. With the switch, bpftrace takes the headers and the staticlibbpf.athat the libbpf port installs. It insists on the static archive, because it embeds libbpf’s headers into the code it generates.-DENABLE_MAN=ON,-DASCIIDOCTOR=/usr/bin/asciidoctor—ENABLE_MAN(on by default) rendersbpftrace(8)fromman/adoc/bpftrace.adoc.man/adoc/CMakeLists.txtlooks forasciidoctorwithfind_program, and when the search fails it only skips the page; naming the program’s path makes the man target fail instead if asciidoctor is missing.-DENABLE_SKB_OUTPUT=ON— On by default. It looks for libpcap and, when it is found, builds the PCAP writer behind theskboutput()builtin, which writes the data of a socket buffer to a PCAP file.-DENABLE_SYSTEMD=OFF— Off by default; when on, it linkslibsystemd. KDOS has no systemd (see No systemd).-DCMAKE_REQUIRE_FIND_PACKAGE_LibBfd=ON,-DCMAKE_REQUIRE_FIND_PACKAGE_LibOpcodes=ON,-DCMAKE_REQUIRE_FIND_PACKAGE_LibDw=ON,-DCMAKE_REQUIRE_FIND_PACKAGE_LibPcap=ON— bpftrace callsfind_package()for these four libraries withoutREQUIRED, and builds without any it does not find. This CMake switch makes eachfind_packageof that name fatal. libbfd and libopcodes, from binutils, give bpftrace its disassembler, which it uses to refuse a uprobe placed in the middle of an instruction. libdw, from elfutils, lets it read a program’s function arguments and types from DWARF. libpcap, from libpcap, isskboutput().-DCMAKE_DISABLE_FIND_PACKAGE_LibBlazesym=ON— bpftrace looks for blazesym, a Rust symbolisation library, and resolves kernel and user-space addresses to symbols with it when it finds it. The tree has no blazesym port. Disabling the search keeps the build the same whatever else is installed.-DSTATIC_LINKING=OFF— Off by default. On, it links bpftrace against the static clang and LLVM libraries; the llvm port builds LLVM as shared libraries.-DCMAKE_CXX_STANDARD_LIBRARIES— CMake appends this to the end of every C++ link line. The value is the output ofllvm-config --libs, every LLVM component library. This tree’s LLVM is built withBUILD_SHARED_LIBS=ON, one shared library per component, and CMake puts on a link line only the few components bpftrace names. A target that calls none of them, such asbpftrace-aotrt, has each one dropped by the tree’s--as-needed, and the libraries those components need (LLVMSupport,LLVMObject,LLVMDebugInfoDWARFamong them) are then never searched: the link fails onllvm::raw_ostreamandllvm::object::createBinary. With every component named, each library a binary uses is found, and--as-neededstill records only those.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/bpftrace, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf bpftrace-0.27.0-2.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/bpftrace, and runs the triggers its paths call for.
Contents
Installed programs: bpftrace, bpftrace-aotrt.
Installed directories: /usr/share/bpftrace, /usr/share/licenses/bpftrace.
Short descriptions
bpftrace |
a high-level tracing language |