3.8 KiB
vmlinux-btf
OpenWrt package providing detached BTF for CO-RE eBPF programs on kernels without built-in BTF. It builds type probes against prepared kernel headers, then extracts BTF with pahole. It does not rebuild or replace the kernel.
Requirements
- OpenWrt buildroot or SDK with prepared target kernel headers and configuration.
- Host Python >= 3.7 and
pahole>= 1.22 (dwarves). Python is not needed on the router. - RANDSTRUCT disabled. Randomized layouts require the original kernel build plugins and seed; the build rejects this configuration.
Build
Run from the OpenWrt buildroot or SDK directory:
git clone https://github.com/QiuSimons/vmlinux-btf.git package/vmlinux-btf
make package/vmlinux-btf/compile V=s
In menuconfig, the package is under Kernel. BTF_PYTHON, BTF_CC and BTF_PAHOLE override the host Python, target compiler and host pahole commands.
Installed files
/usr/lib/debug/boot/vmlinux: raw BTF./usr/lib/debug/boot/vmlinux-<release>: symlink for the build kernel release.
Live installation also creates a vmlinux-$(uname -r) alias for loader compatibility. Removal deletes that alias. Offline image installation skips these runtime steps.
libbpf 1.5 searches the versioned debug path when kernel BTF is unavailable; it does not automatically search the unversioned path. Loaders exposing btf_custom_path can select the BTF file explicitly. See libbpf's search paths.
Compatibility
The package aims to support existing OpenWrt installations and does not reject installation because a kernel patch version differs. Kernels sharing x.y may have compatible layouts, but patch releases, OpenWrt backports and configuration can change them. The runtime alias enables lookup; it does not establish layout compatibility.
Installing or removing a compatible kmod-* package does not change the configuration of the running kernel. Probes include header types for built-in and modular features, whether or not a module is installed or loaded. UCI settings do not change compiled type layouts either. A separately built firmware with different kernel options can have different layouts; a single BTF cannot describe conflicting definitions of the same type.
For reliable relocation, use BTF generated from matching kernel sources, patches, configuration, architecture and layout-affecting compiler options. CO-RE cannot correct an inaccurate target BTF. External BTF also does not enable missing kernel features, including attachment modes that require in-kernel BTF.
Type coverage
src/types.json lists optional probe groups: name, kernel-relative header, and named struct, union or enum types. Add entries using definitions from the kernel headers. Do not copy structure layouts or add a C template for each group. src/shadow_btf_core.c contains the core probe; src/btf_probe.h holds the shared macro.
The builder generates one probe per group. sizeof requires complete definitions. If compilation fails, a header-only check distinguishes dependency failures from type failures; type failures are bisected so compatible entries remain. Configuration is taken from the kernel headers, without extra subsystem guards.
The final BTF must contain nonempty definitions of sk_buff, sock, task_struct and net_device. The package build directory contains coverage.json, generated probes and compiler logs. The report records final type coverage, skipped entries, compile attempts and elapsed time. Coverage depends on available headers and configured definitions; types defined only in kernel implementation sources are not collected.
GitHub Actions uploads reports, probe sources and logs as separate diagnostic artifacts, including after failed builds when these files exist. Object files are excluded.
License
GPL-3.0-or-later