内核在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 应用程序。这部分工作得很好。
我错过了什么吗?我相信这项任务应该相当容易;-)