编译libbpf时报如下错误:
libbpf/src/bpf_helpers.h:99:10: error: unknown register name 'r0' in asm
报这个问题是clang版本低导致的,才clang 10以上的版本就不会报这个错误了。
我的clang版本是9 ,所以需要对bpf_helpers.h做些修改,具体如下:
+ #if __clang_major__ >= 10 && defined(__bpf__)
static __always_inline void
bpf_tail_call_static(void *ctx, const void *map, const __u32 slot)
{
if (!__builtin_constant_p(slot))
__bpf_unreachable();
asm volatile("r1 = %[ctx]\n\t"
"r2 = %[map]\n\t"
"r3 = %[slot]\n\t"
"call 12"
:: [ctx]"r"(ctx), [map]"r"(map), [slot]"i"(slot)
: "r0", "r1", "r2", "r3", "r4", "r5");
}
+ #else
+ #define bpf_tail_call_static bpf_tail_call
+ #endif /* __clang_major__ >= 10 && __bpf__ */
头文件中增加关于clang版本的判断 clang_major >= 10, 对于clang版本小于10的,执行#define bpf_tail_call_static bpf_tail_call 语句。