path: root/tools/build
diff options
authorWang Nan <>2015-07-01 02:13:51 +0000
committerArnaldo Carvalho de Melo <>2015-08-07 10:16:56 -0300
commit1b76c13e4b36f978ea45af079f38ad423a229630 (patch)
tree9706e80cd3e58779edb2e1b820d7817f1ed56bc0 /tools/build
parent1354ac6ad84395660f551d0614a6ca39e5bfe8e3 (diff)
bpf tools: Introduce 'bpf' library and add bpf feature check
This is the first patch of libbpf. The goal of libbpf is to create a standard way for accessing eBPF object files. This patch creates 'Makefile' and 'Build' for it, allows 'make' to build libbpf.a and, 'make install' to put them into proper directories. Most part of Makefile is borrowed from traceevent. Before building, it checks the existence of libelf in Makefile, and deny to build if not found. Instead of throwing an error if libelf not found, the error raises in a phony target "elfdep". This design is to ensure 'make clean' still workable even if libelf is not found. Because libbpf requires 'kern_version' field set for 'union bpf_attr' (bpfdep" is used for that dependency), Kernel BPF API is also checked by intruducing a new feature check 'bpf' into tools/build/feature, which checks the existence and version of linux/bpf.h. When building libbpf, it searches that file from include/uapi/linux in kernel source tree (controlled by FEATURE_CHECK_CFLAGS-bpf). Since it searches kernel source tree it reside, installing of newest kernel headers is not required, except we are trying to port these files to an old kernel. To avoid checking that file when perf building, the newly introduced 'bpf' feature check doesn't added into FEATURE_TESTS and FEATURE_DISPLAY by default in tools/build/Makefile.feature, but added into libbpf's specific. Signed-off-by: Wang Nan <> Acked-by: Alexei Starovoitov <> Cc: Brendan Gregg <> Cc: Daniel Borkmann <> Cc: David Ahern <> Cc: He Kuang <> Cc: Jiri Olsa <> Cc: Kaixu Xia <> Cc: Masami Hiramatsu <> Cc: Namhyung Kim <> Cc: Peter Zijlstra <> Cc: Zefan Li <> Bcc: Link: Signed-off-by: Arnaldo Carvalho de Melo <>
Diffstat (limited to 'tools/build')
2 files changed, 23 insertions, 1 deletions
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index 463ed8f2a267..1c0d69f44552 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -33,7 +33,8 @@ FILES= \
test-compile-32.bin \
test-compile-x32.bin \
test-zlib.bin \
- test-lzma.bin
+ test-lzma.bin \
+ test-bpf.bin
@@ -156,6 +157,9 @@ test-zlib.bin:
$(BUILD) -llzma
+ $(BUILD)
-include *.d
diff --git a/tools/build/feature/test-bpf.c b/tools/build/feature/test-bpf.c
new file mode 100644
index 000000000000..062bac811af9
--- /dev/null
+++ b/tools/build/feature/test-bpf.c
@@ -0,0 +1,18 @@
+#include <linux/bpf.h>
+int main(void)
+ union bpf_attr attr;
+ attr.prog_type = BPF_PROG_TYPE_KPROBE;
+ attr.insn_cnt = 0;
+ attr.insns = 0;
+ attr.license = 0;
+ attr.log_buf = 0;
+ attr.log_size = 0;
+ attr.log_level = 0;
+ attr.kern_version = 0;
+ attr = attr;
+ return 0;