【发布时间】:2023-03-10 07:47:01
【问题描述】:
内核在samples/bpf 中提供了许多示例。我有兴趣在树之外构建一个示例,就像我们构建一个内核模块一样,Makefile 可以很简单。是否可以对 bpf 做同样的事情?我尝试从samples/bpf/Makefile 中删除不必要的部分,并保持对libbpf 和其他的依赖,但结果并不是那么容易。
例如,尝试使用以下命令行在内核树之外构建samples/bpf/bpf_tcp_kern.c(我查看了samples/bpf/Makefile,以及make samples/bpf V=1 的输出):
clang -nostdinc -isystem /usr/lib/gcc/x86_64-linux-gnu/5/include \
-I/home/mark/work/net-next.git/arch/x86/include -I/home/mark/work/net-next.git/arch/x86/include/generated -I./include -I/home/mark/work/net-next.git/arch/x86/include/uapi -I/home/mark/work/net-next.git/arch/x86/include/generated/uapi -I/home/mark/work/net-next.git/include -I/home/mark/work/net-next.git/generated/uapi -I./ \
-D__KERNEL__ -Wno-unused-value -Wno-pointer-sign \
-D__TARGET_ARCH_x86 -Wno-compare-distinct-pointer-types \
-Wno-gnu-variable-sized-type-not-at-end \
-Wno-address-of-packed-member -Wno-tautological-compare \
-Wno-unknown-warning-option \
-O2 -emit-llvm -c bpf_tcp_kern.c -o -| llc -march=bpf -filetype=obj -o bpf_tcp_kern.o
In file included from bpf_tcp_kern.c:15:
In file included from /home/mark/work/net-next.git/include/uapi/linux/bpf.h:11:
In file included from /home/mark/work/net-next.git/include/linux/types.h:6:
In file included from /home/mark/work/net-next.git/include/uapi/linux/types.h:5:
/home/mark/work/net-next.git/arch/x86/include/uapi/asm/types.h:5:10: fatal error: 'asm-generic/types.h' file not found
#include <asm-generic/types.h>
^
1 error generated
这是clang-llvm 3.8.0
我需要libbpf 来构建用户端 bpf 应用程序。这部分工作正常。
我错过了什么吗?我相信这项任务应该相当容易;-)
【问题讨论】:
标签: linux-kernel jit llvm-clang bpf