參考資訊:
https://github.com/nevermosby/linux-bpf-learning/blob/master/bpf/perf-sys.h
問題如下:
$ make M=samples/bpf make -C /usr/src/linux-source-4.19/samples/bpf/../../tools/lib/bpf/ RM='rm -rf' LDFLAGS= srctree=/usr/src/linux-source-4.19/samples/bpf/../../ O= Warning: Kernel ABI header at 'tools/include/uapi/linux/bpf.h' differs from latest version at 'include/uapi/linux/bpf.h' Warning: Kernel ABI header at 'tools/include/uapi/linux/netlink.h' differs from latest version at 'include/uapi/linux/netlink.h' HOSTCC samples/bpf/bpf_load.o In file included from ./tools/perf/perf-sys.h:9, from samples/bpf/bpf_load.c:29: ./tools/perf/perf-sys.h: In function ‘sys_perf_event_open’: ./tools/perf/perf-sys.h:68:15: error: ‘test_attr__enabled’ undeclared (first use in this function) if (unlikely(test_attr__enabled)) ^~~~~~~~~~~~~~~~~~ ./tools/include/linux/compiler.h:74:43: note: in definition of macro ‘unlikely’ # define unlikely(x) __builtin_expect(!!(x), 0) ^ ./tools/perf/perf-sys.h:68:15: note: each undeclared identifier is reported only once for each function it appears in if (unlikely(test_attr__enabled)) ^~~~~~~~~~~~~~~~~~ ./tools/include/linux/compiler.h:74:43: note: in definition of macro ‘unlikely’ # define unlikely(x) __builtin_expect(!!(x), 0) ^ In file included from samples/bpf/bpf_load.c:29: ./tools/perf/perf-sys.h:69:3: warning: implicit declaration of function ‘test_attr__open’ [-Wimplicit-function-declaration] test_attr__open(attr, pid, cpu, fd, group_fd, flags); ^~~~~~~~~~~~~~~ make[1]: *** [scripts/Makefile.host:107: samples/bpf/bpf_load.o] Error 1 make: *** [Makefile:1564: _module_samples/bpf] Error 2
解法如下:
$ vim tools/perf/perf-sys.h 67 #ifdef HAVE_ATTR_TEST 68 //if (unlikely(test_attr__enabled)) 69 //test_attr__open(attr, pid, cpu, fd, group_fd, flags); 70 #endif