The kernel provides a number of examples in samples/bpf
. I am interested in building one of examples outside of the tree, just like we build a kernel module, where Makefile
can be simple enough. Is it possible to do the same with bpf? I tried it by ripping out unnecessary parts from samples/bpf/Makefile
and keeping dependencies to libbpf
and others, however it turned out to be not that easy.
For example, trying to build samples/bpf/bpf_tcp_kern.c
outside of the kernel tree, with the following command line (I peeked into samples/bpf/Makefile, as well as the output of 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
This is with clang-llvm 3.8.0
And I need libbpf
to build user-side bpf applications. This part works builds just fine.
Am I missing something? I believe this task should be fairly easy ;-)