Linux BTF : bpftool: Failed to get EHDR from/sys/kernel/btf/vmlinux
I’m trying to start with BPF CO:RE development.
With Ubuntu 20.04 LTS in the VM, I need to recompile the kernel and install pahole (from apt install dwarves) to enable BTF (I set CONFIG_DEBUG_FS=y and CONFIG_DEBUG_INFO_BTF=y).
So my setup is:
- Ubuntu 20.04
- Kernel 5.4.0-90-generic
- bpftool –version:/usr/lib/linux-tools/5.4.0-90-generic/bpftool v5.4.148
/
sys/kernel/btf/vmlinux exists and can be read out with cat.
But bpftool displays the following error:
$ 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
From https://github.com/libbpf/libbpf/blob/master/src/libbpf.h
Appears to be LIBBPF_ERRNO__FORMAT,/* BPF object format invalid */
But I couldn’t figure out what the problem was.
Does anyone know where the error might be?
Thanks in advance!
EDIT: Added bpftool version
Solution
You need to update bpftool to support a fallback to reading BTF as raw data if the input file is not an object file. In general, I recommend always using the latest bpftool version as there is no backporting.