QiuSimons 707ceada49 vmlinux-btf: rework BTF generation using prepared kernel headers
Replace the full shadow kernel build with a lightweight stub compilation
approach against the target's already-prepared kernel headers:

- Add multi-tier C stub units (shadow_btf_core.c, shadow_btf_modules.c,
  shadow_btf_private.c) that include key kernel headers to capture struct
  layouts with exact fidelity, without modifying or rebuilding the host kernel
- Use pahole on the resulting stub object to produce a detached BTF blob
- Simplify Makefile: drop PKG_SOURCE/PKG_HASH, remove shadow kernel patches
  and kernel download steps; build is now fast, deterministic, and SDK-native
- Add multi-arch GitHub Actions CI workflow building against OpenWrt 24 and 25
  SDKs across aarch64_generic, cortex-a53/a72/a76, and x86_64
- Add pahole binary detection with multi-path fallback and version verification
- Add fallback objcopy path for older pahole versions lacking --btf_encode_detached
2026-10-20 15:19:38 +08:00

vmlinux-btf

OpenWrt package that generates a detached BTF (vmlinux) file from kernel headers and .config, enabling CO-RE (Compile Once – Run Everywhere) eBPF programs on OpenWrt without rebuilding or replacing the running kernel.

Overview

Official OpenWrt release kernels typically omit CONFIG_DEBUG_INFO_BTF=y. Without kernel BTF, modern eBPF tools that rely on CO-RE (such as libbpf-based loaders) cannot resolve kernel type layouts.

Rather than recompiling the entire kernel tree, this package compiles lightweight stub sources (src/shadow_btf_*.c) against the prepared target kernel headers ($(LINUX_DIR)) using the target configuration and toolchain. pahole then extracts the detached BTF blob from the linked object.

Requirements

  • OpenWrt buildroot or SDK environment.
  • Host pahole >= 1.22 (from the dwarves package).

Building

In OpenWrt SDK

git clone https://github.com/QiuSimons/vmlinux-btf.git package/vmlinux-btf
make package/vmlinux-btf/compile V=s

In OpenWrt Buildroot

Select vmlinux-btf under Kernel in make menuconfig, then build:

make package/vmlinux-btf/compile V=s

Installed Files

  • /usr/lib/debug/boot/vmlinux: Detached BTF file.
  • /usr/lib/debug/boot/vmlinux-<release>: Symlink targeting vmlinux (linked to uname -r on target installation).

Standard loaders such as libbpf look for BTF at /usr/lib/debug/boot/vmlinux-$(uname -r) and /usr/lib/debug/boot/vmlinux by default.

License

GPL-3.0-or-later

S
Description
No description provided
Readme
85 KiB
0 Stars 1 Watchers 0 Forks
Languages
Python 76.9%
Makefile 13.3%
C 9.8%