clang -I ./headers/ -O2 -target bpf -c tc-xdp-drop-tcp.c -o tc-xdp-drop-tcp.o
In file included from tc-xdp-drop-tcp.c:2:
In file included from /usr/include/linux/bpf.h:11:
/usr/include/linux/types.h:5:10: fatal error: 'asm/types.h' file not found
#include <asm/types.h>
^~~~~~~~~~~~~
1 error generated.
如上述问题中的asm相关文件,asm全称Architecture Specific Macros,直译过来“与机器架构相关的宏文件”,顾名思义它是跟机器架构密切相关的,不同的架构x86、x64、arm实现是不一样的,而操作系统并没有提供/usr/include/asm/这样通用的目录,只提供了具体架构相关的目录,如/usr/include/x86_64-linux-gnu/asm/,因此无法找到引用。
解决方案
添加软链/usr/include/asm/,指向操作系统自带的asm目录:
cd /usr/include
ln -s ./x86_64-linux-gnu/asm asm
2. 'bpf/bpf_helpers.h' file not found
解决方案
apt-get install libbpf-dev
# run `apt-file update` if needed
apt-file list libbpf-dev | grep bpf_helpers.h
# you will get the result like: libbpf-dev: /usr/include/bpf/bpf_helpers.h
你好 clang完.c没有问题,但是加载内核的时候出现12 bytes struct bpf_elf_map fixup performed due to size mismatch!
ELF contains relo data for non ld64 instruction at offset 19! Compiler bug?!
Try to annotate functions with always_inline attribute!
Error fetching program/map!
是什么情况呢