我正在尝试从 BPF CO:RE 开发开始。 在 VM 中使用 Ubuntu 20.04 LTS,我需要重新编译内核并安装 pahole(来自 apt install dwarves)以便启用 BTF(我设置 CONFIG_DEBUG_FS=y 和 CONFIG_DEBUG_INFO_BTF=y)。
所以我的设置是:
- Ubuntu 20.04
- 内核 5.4.0-90-generic
- bpftool --version:/usr/lib/linux-tools/5.4.0-90-generic/bpftool v5.4.148
/sys/kernel/btf/vmlinux存在,可以用cat读出。
但是 bpftool 显示以下错误:
$ sudo bpftool btf dump file /sys/kernel/btf/vmlinux format c
libbpf: failed to get EHDR from /sys/kernel/btf/vmlinux
Error: failed to load BTF from /sys/kernel/btf/vmlinux: Unknown error -4001
来自 https://github.com/libbpf/libbpf/blob/master/src/libbpf.h 看起来是 LIBBPF_ERRNO__FORMAT,/* BPF object format invalid */ 但我无法找出问题所在。
有没有人知道错误可能在哪里?
提前致谢!
编辑:添加了 bpftool 版本
最佳答案
您需要更新 bpftool 以支持 a fallback to reading BTF as raw data if the input file is not an object file .所需的最低 bpftool 版本是 v5.5,因为这是安装补丁的 Linux 版本。一般来说,我建议始终使用最新的 bpftool 版本,因为没有向后移植。
关于c++ - Linux BTF : bpftool: Failed to get EHDR from/sys/kernel/btf/vmlinux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70093863/