我试着从BPF CO:RE Development开始。在VM中使用Ubuntu20.04LTS时,我需要重新编译内核并安装pahole (来自apt安装矮人),以便启用BTF (我设置了CONFIG_DEBUG_FS=y和CONFIG_DEBUG_INFO_BTF=y)。
所以我的设计是:
/sys/ can /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对象格式无效*/但我找不出出了什么问题。
有人知道错误可能在哪里吗?
提前感谢!
编辑:添加了bpftool版本
发布于 2021-11-25 11:54:29
需要更新bpftool以支持如果输入文件不是对象文件,则作为原始数据读取BTF的回退。。所需的最低bpftool版本是v5.5,因为这是该修补程序登陆的Linux版本。通常,我建议始终使用最新的bpftool版本,因为没有后端。
发布于 2021-11-25 09:47:06
更新:看起来bpftool只接受包含编译的运行内核的ELF文件,但是我的/sys/file/btf/vmlinux不是:
$ file /sys/kernel/btf/vmlinux
/sys/kernel/btf/vmlinux: data/boot/vmlinuz相同:
$ sudo file /boot/vmlinuz-5.4.0-90-generic
/boot/vmlinuz-5.4.0-90-generic: Linux kernel x86 boot executable bzImage, version 5.4.0-90-generic (root@elde-dev) #101+test1 SMP Tue Nov 23 16:38:41 UTC 2021, RO-rootFS, swap_dev 0xD, Normal VGA有人知道为什么我的/sys/内核/btf/vmlinux没有显示正确的格式吗?
我找到了解决办法:
按照这里的建议,使用这个脚本(https://elixir.bootlin.com/linux/latest/source/scripts/extract-vmlinux) (https://unix.stackexchange.com/questions/610672/where-is-the-linux-kernel-elf-file-located),我可以得到“工作的”vmlinux-文件,然后可以通过bpftool读取该文件。但这并不是BPF公司的正确选择:我想.此外,在所有教程中,bpftool直接与/sys/内核/btf/vmlinux一起使用。
那么为什么我会得到错误的格式呢?
编辑:正如上面所建议的,只要下载最新的linux内核,从那里编译bpftool并使用它。
https://stackoverflow.com/questions/70093863
复制相似问题