Skip to content

Commit 7b65e20

Browse files
olsajiriacmel
authored andcommitted
perf tools: Allow to link with libbpf dynamicaly
Currently we support only static linking with kernel's libbpf (tools/lib/bpf). This patch adds libbpf package detection and support to link perf with it dynamically. The libbpf package status is displayed with: $ make VF=1 Auto-detecting system features: ... ... libbpf: [ on ] It's not checked by default, because it's quite new. Once it's on most distros we can switch it on. For the same reason it's not added to the test-all check. Perf does not need advanced version of libbpf, so we can check just for the base bpf_object__open function. Adding new compile variable to detect libbpf package and link bpf dynamically: $ make LIBBPF_DYNAMIC=1 ... LINK perf $ ldd perf | grep bpf libbpf.so.0 => /lib64/libbpf.so.0 (0x00007f46818bc000) If libbpf is not installed, build stops with: Makefile.config:486: *** Error: No libbpf devel library found,\ please install libbpf-devel. Stop. Committer testing: $ make LIBBPF_DYNAMIC=1 -C tools/perf O=/tmp/build/perf make: Entering directory '/home/acme/git/perf/tools/perf' BUILD: Doing 'make -j8' parallel build Makefile.config:493: *** Error: No libbpf devel library found, please install libbpf-devel. Stop. make[1]: *** [Makefile.perf:225: sub-make] Error 2 make: *** [Makefile:70: all] Error 2 make: Leaving directory '/home/acme/git/perf/tools/perf' $ Signed-off-by: Jiri Olsa <jolsa@kernel.org> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Toke Høiland-Jørgensen <toke@redhat.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com> Cc: Andrii Nakryiko <andriin@fb.com> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: Jesper Dangaard Brouer <brouer@redhat.com> Cc: Martin KaFai Lau <kafai@fb.com> Cc: Michael Petlan <mpetlan@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Song Liu <songliubraving@fb.com> Cc: Yonghong Song <yhs@fb.com> Cc: bpf@vger.kernel.org Cc: netdev@vger.kernel.org Link: http://lore.kernel.org/lkml/20191126121253.28253-1-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent a573268 commit 7b65e20

5 files changed

Lines changed: 28 additions & 2 deletions

File tree

‎tools/build/Makefile.feature‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ FEATURE_TESTS_EXTRA := \
9696
cxx \
9797
llvm \
9898
llvm-version \
99-
clang
99+
clang \
100+
libbpf
100101

101102
FEATURE_TESTS ?= $(FEATURE_TESTS_BASIC)
102103

‎tools/build/feature/Makefile‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ FILES= \
5353
test-zlib.bin \
5454
test-lzma.bin \
5555
test-bpf.bin \
56+
test-libbpf.bin \
5657
test-get_cpuid.bin \
5758
test-sdt.bin \
5859
test-cxx.bin \
@@ -270,6 +271,9 @@ $(OUTPUT)test-get_cpuid.bin:
270271
$(OUTPUT)test-bpf.bin:
271272
$(BUILD)
272273

274+
$(OUTPUT)test-libbpf.bin:
275+
$(BUILD) -lbpf
276+
273277
$(OUTPUT)test-sdt.bin:
274278
$(BUILD)
275279

‎tools/build/feature/test-libbpf.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include <bpf/libbpf.h>
3+
4+
int main(void)
5+
{
6+
return bpf_object__open("test") ? 0 : -1;
7+
}

‎tools/perf/Makefile.config‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,16 @@ ifndef NO_LIBELF
483483
ifeq ($(feature-bpf), 1)
484484
CFLAGS += -DHAVE_LIBBPF_SUPPORT
485485
$(call detected,CONFIG_LIBBPF)
486+
487+
# detecting libbpf without LIBBPF_DYNAMIC, so make VF=1 shows libbpf detection status
488+
$(call feature_check,libbpf)
489+
ifdef LIBBPF_DYNAMIC
490+
ifeq ($(feature-libbpf), 1)
491+
EXTLIBS += -lbpf
492+
else
493+
dummy := $(error Error: No libbpf devel library found, please install libbpf-devel);
494+
endif
495+
endif
486496
endif
487497

488498
ifndef NO_DWARF

‎tools/perf/Makefile.perf‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ include ../scripts/utilities.mak
116116
#
117117
# Define TCMALLOC to enable tcmalloc heap profiling.
118118
#
119+
# Define LIBBPF_DYNAMIC to enable libbpf dynamic linking.
120+
#
119121

120122
# As per kernel Makefile, avoid funny character set dependencies
121123
unexport LC_ALL
@@ -360,7 +362,9 @@ export PERL_PATH
360362

361363
PERFLIBS = $(LIBAPI) $(LIBTRACEEVENT) $(LIBSUBCMD) $(LIBPERF)
362364
ifndef NO_LIBBPF
363-
PERFLIBS += $(LIBBPF)
365+
ifndef LIBBPF_DYNAMIC
366+
PERFLIBS += $(LIBBPF)
367+
endif
364368
endif
365369

366370
# We choose to avoid "if .. else if .. else .. endif endif"

0 commit comments

Comments
 (0)