]> git.ipfire.org Git - thirdparty/linux.git/commit
bpftool: Support merging multiple module BTFs in btf dump
authorJosef Bacik <josef@toxicpanda.com>
Wed, 4 Mar 2026 20:56:51 +0000 (15:56 -0500)
committerAndrii Nakryiko <andrii@kernel.org>
Thu, 5 Mar 2026 23:03:02 +0000 (15:03 -0800)
commitd8d5c0151148b0194e8bbba66eb56d4d9cab94cd
tree36ac07c725144300f6796e920ed7cd21068a052a
parentbe872ccf370915b858ab693aa0707a2eff4bb1fd
bpftool: Support merging multiple module BTFs in btf dump

Add support for specifying multiple file sources in 'bpftool btf dump'
to generate a single C header containing types from vmlinux plus
multiple kernel modules:

  bpftool btf dump file /sys/kernel/btf/mod1 file /sys/kernel/btf/mod2 format c

This is useful for BPF programs that need to access types defined in
kernel modules. Previously this required a separate bpftool invocation
for each module, producing separate headers that could not be combined
due to overlapping vmlinux type definitions.

The implementation collects all file paths, then for the multi-file
case creates an empty split BTF on the vmlinux base and iteratively
merges each module's types into it via btf__add_btf(). The single-file
code path is preserved exactly to avoid any regression risk.

Auto-detection of vmlinux as the base BTF from sysfs paths works as
before. If vmlinux itself appears in the file list it is skipped with
a warning since its types are already provided by the base.

Assisted-by: Claude:claude-opus-4-6
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
Link: https://lore.kernel.org/bpf/b19c2760ffe48cec546dd3810d237f8cad20d606.1772657690.git.josef@toxicpanda.com
tools/bpf/bpftool/Documentation/bpftool-btf.rst
tools/bpf/bpftool/bash-completion/bpftool
tools/bpf/bpftool/btf.c