libbpf:将 .BTF 加载到内核时出错:-22。错误:无法打开目标文件,vlen != 0

问题描述 投票:0回答:1

我现在正在尝试将一些 bpf 代码插入基于 cilium 的内核中。通过本教程,我一步步按照说明使用其提供的 Makefile 进行编译,然后使用 bpftool 尝试将目标文件加载到内核中,不幸的是它总是显示如图所示的错误,我非常确定我已经安装了所有相关的依赖项,并将我的内核升级到最新的,链接是教程https://github.com/cilium/cilium/tree/main/bpf/custom 也许有人知道为什么我的负载失败

这是我得到的错误:

$ sudo bpftool prog load bpf/custom/bytecount.o /sys/fs/bpf/tc/globals/bytecounter /sys/fs/bpf/tc/globals/bytecounter_maps
libbpf: Error loading BTF: Invalid argument(22) 
libbpf: magic: 0xeb9f
version: 1 
flags: 0x0 
hdrlen: 24 
type_off: 0 
type_len: 1164 
stroff: 1164 
str_len: 1234 
btf_total_size: 2422 
[1] STRICT (anon) size=32 vlen=4 
    type typeid=2 bitsoffset=0 
    key typeid=6 bitsoffset=64 
    value typeid=9 bitsoffset=126 
    max_entries type_id=12 bits_offset=192 
...
[25] INT unsigned char size=1 bits_offset=0 nr_bits=8 encoding=(none) 
[26] FUNC_PROTO (anon) return=3 args=(15 ctx) 
[27] FUNC custom_hook type_id=26 vlen != 0 
libbpf: Error loading .BTF into kernel: -22. Error: failed to open object file
ebpf cilium
1个回答
0
投票

[27] FUNC 自定义钩子 type_id=26 vlen != 0

您似乎遇到了此错误情况:https://github.com/torvalds/linux/blob/85d33df357b634649ddbe0a20fd2d0fc5732c3cb/kernel/bpf/btf.c#L2655

BTF(类型信息)标准已更新,开始使用

vlen
来指示函数的链接类型。内核在 v5.6 之后开始支持此功能。

Clang/LLVM 也已更新(在某些时候)以这种方式发出 BTF,其中 static=0、global=1、external=2

cilium/bpf/custom 中的示例具有全局函数,因此新编译器、旧内核和此代码的组合会导致问题。添加

static
关键字应该可以修复它:

__section(STRINGIFY(BPF_CUSTOM_PROG_NAME))
static int custom_hook(const struct __ctx_buff *ctx)
© www.soinside.com 2019 - 2024. All rights reserved.