Skip to content

Commit 9925495

Browse files
captain5050namhyung
authored andcommitted
perf build: Default BUILD_BPF_SKEL, warn/disable for missing deps
LIBBPF is dependent on zlib so move the NO_ZLIB and feature check early to avoid statically building when zlib is disabled. This avoids a linkage failure with perf and static libbpf when zlib isn't specified. Move BUILD_BPF_SKEL logic to one place and if not defined set BUILD_BPF_SKEL to 1. Detect dependencies of building with BPF skeletons and warn/disable if the dependencies aren't present. Change Makefile.perf to contain BPF skeleton logic dependent on the Makefile.config result and refresh the comment about BUILD_BPF_SKEL. Signed-off-by: Ian Rogers <irogers@google.com> Tested-by: Namhyung Kim <namhyung@kernel.org> Cc: James Clark <james.clark@arm.com> Cc: Nick Terrell <terrelln@fb.com> Cc: Patrice Duroux <patrice.duroux@gmail.com> Cc: Nick Desaulniers <ndesaulniers@google.com> Cc: Andrii Nakryiko <andrii@kernel.org> Cc: Nathan Chancellor <nathan@kernel.org> Cc: Kajol Jain <kjain@linux.ibm.com> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> Cc: Tiezhu Yang <yangtiezhu@loongson.cn> Cc: Tom Rix <trix@redhat.com> Cc: llvm@lists.linux.dev Cc: bpf@vger.kernel.org Link: https://lore.kernel.org/r/20230914211948.814999-3-irogers@google.com Signed-off-by: Namhyung Kim <namhyung@kernel.org>
1 parent 727e431 commit 9925495

File tree

2 files changed

+53
-33
lines changed

2 files changed

+53
-33
lines changed

tools/perf/Makefile.config

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,6 @@ ifeq ($(call get-executable,$(BISON)),)
216216
dummy := $(error Error: $(BISON) is missing on this system, please install it)
217217
endif
218218

219-
ifeq ($(BUILD_BPF_SKEL),1)
220-
ifeq ($(call get-executable,$(CLANG)),)
221-
dummy := $(error $(CLANG) is missing on this system, please install it to be able to build with BUILD_BPF_SKEL=1)
222-
endif
223-
endif
224-
225219
ifneq ($(OUTPUT),)
226220
ifeq ($(shell expr $(shell $(BISON) --version | grep bison | sed -e 's/.\+ \([0-9]\+\).\([0-9]\+\).\([0-9]\+\)/\1\2\3/g') \>\= 371), 1)
227221
BISON_FILE_PREFIX_MAP := --file-prefix-map=$(OUTPUT)=
@@ -530,6 +524,16 @@ ifdef CORESIGHT
530524
endif
531525
endif
532526

527+
ifndef NO_ZLIB
528+
ifeq ($(feature-zlib), 1)
529+
CFLAGS += -DHAVE_ZLIB_SUPPORT
530+
EXTLIBS += -lz
531+
$(call detected,CONFIG_ZLIB)
532+
else
533+
NO_ZLIB := 1
534+
endif
535+
endif
536+
533537
ifndef NO_LIBELF
534538
CFLAGS += -DHAVE_LIBELF_SUPPORT
535539
EXTLIBS += -lelf
@@ -571,22 +575,28 @@ ifndef NO_LIBELF
571575

572576
ifndef NO_LIBBPF
573577
ifeq ($(feature-bpf), 1)
574-
CFLAGS += -DHAVE_LIBBPF_SUPPORT
575-
$(call detected,CONFIG_LIBBPF)
576-
577578
# detecting libbpf without LIBBPF_DYNAMIC, so make VF=1 shows libbpf detection status
578579
$(call feature_check,libbpf)
579580

580581
ifdef LIBBPF_DYNAMIC
581582
ifeq ($(feature-libbpf), 1)
582583
EXTLIBS += -lbpf
584+
CFLAGS += -DHAVE_LIBBPF_SUPPORT
585+
$(call detected,CONFIG_LIBBPF)
583586
$(call detected,CONFIG_LIBBPF_DYNAMIC)
584587
else
585588
dummy := $(error Error: No libbpf devel library found or older than v1.0, please install/update libbpf-devel);
586589
endif
587590
else
588-
# Libbpf will be built as a static library from tools/lib/bpf.
589-
LIBBPF_STATIC := 1
591+
ifeq ($(NO_ZLIB), 1)
592+
dummy := $(warning Warning: Statically building libbpf not possible as zlib is missing)
593+
NO_LIBBPF := 1
594+
else
595+
# Libbpf will be built as a static library from tools/lib/bpf.
596+
LIBBPF_STATIC := 1
597+
$(call detected,CONFIG_LIBBPF)
598+
CFLAGS += -DHAVE_LIBBPF_SUPPORT
599+
endif
590600
endif
591601
endif
592602
endif # NO_LIBBPF
@@ -663,16 +673,36 @@ ifndef NO_LIBBPF
663673
endif
664674
endif
665675

666-
ifdef BUILD_BPF_SKEL
667-
$(call feature_check,clang-bpf-co-re)
668-
ifeq ($(feature-clang-bpf-co-re), 0)
669-
dummy := $(error Error: clang too old/not installed. Please install recent clang to build with BUILD_BPF_SKEL)
670-
endif
676+
ifndef BUILD_BPF_SKEL
677+
# BPF skeletons control a large number of perf features, by default
678+
# they are enabled.
679+
BUILD_BPF_SKEL := 1
680+
endif
681+
682+
ifeq ($(BUILD_BPF_SKEL),1)
671683
ifeq ($(filter -DHAVE_LIBBPF_SUPPORT, $(CFLAGS)),)
672-
dummy := $(error Error: BPF skeleton support requires libbpf)
684+
dummy := $(warning Warning: Disabled BPF skeletons as libbpf is required)
685+
BUILD_BPF_SKEL := 0
686+
else ifeq ($(filter -DHAVE_LIBELF_SUPPORT, $(CFLAGS)),)
687+
dummy := $(warning Warning: Disabled BPF skeletons as libelf is required by bpftool)
688+
BUILD_BPF_SKEL := 0
689+
else ifeq ($(filter -DHAVE_ZLIB_SUPPORT, $(CFLAGS)),)
690+
dummy := $(warning Warning: Disabled BPF skeletons as zlib is required by bpftool)
691+
BUILD_BPF_SKEL := 0
692+
else ifeq ($(call get-executable,$(CLANG)),)
693+
dummy := $(warning Warning: Disabled BPF skeletons as clang ($(CLANG)) is missing)
694+
BUILD_BPF_SKEL := 0
695+
else
696+
$(call feature_check,clang-bpf-co-re)
697+
ifeq ($(feature-clang-bpf-co-re), 0)
698+
dummy := $(warning Warning: Disabled BPF skeletons as clang is too old)
699+
BUILD_BPF_SKEL := 0
700+
endif
701+
endif
702+
ifeq ($(BUILD_BPF_SKEL),1)
703+
$(call detected,CONFIG_PERF_BPF_SKEL)
704+
CFLAGS += -DHAVE_BPF_SKEL
673705
endif
674-
$(call detected,CONFIG_PERF_BPF_SKEL)
675-
CFLAGS += -DHAVE_BPF_SKEL
676706
endif
677707

678708
ifndef GEN_VMLINUX_H
@@ -946,16 +976,6 @@ ifndef NO_DEMANGLE
946976
endif
947977
endif
948978

949-
ifndef NO_ZLIB
950-
ifeq ($(feature-zlib), 1)
951-
CFLAGS += -DHAVE_ZLIB_SUPPORT
952-
EXTLIBS += -lz
953-
$(call detected,CONFIG_ZLIB)
954-
else
955-
NO_ZLIB := 1
956-
endif
957-
endif
958-
959979
ifndef NO_LZMA
960980
ifeq ($(feature-lzma), 1)
961981
CFLAGS += -DHAVE_LZMA_SUPPORT

tools/perf/Makefile.perf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ include ../scripts/utilities.mak
120120
#
121121
# Define NO_LIBDEBUGINFOD if you do not want support debuginfod
122122
#
123-
# Define BUILD_BPF_SKEL to enable BPF skeletons
123+
# Set BUILD_BPF_SKEL to 0 to override BUILD_BPF_SKEL and not build BPF skeletons
124124
#
125125
# Define BUILD_NONDISTRO to enable building an linking against libbfd and
126126
# libiberty distribution license incompatible libraries.
@@ -1042,7 +1042,7 @@ SKELETONS += $(SKEL_OUT)/augmented_raw_syscalls.skel.h
10421042
$(SKEL_TMP_OUT) $(LIBAPI_OUTPUT) $(LIBBPF_OUTPUT) $(LIBPERF_OUTPUT) $(LIBSUBCMD_OUTPUT) $(LIBSYMBOL_OUTPUT):
10431043
$(Q)$(MKDIR) -p $@
10441044

1045-
ifdef BUILD_BPF_SKEL
1045+
ifeq ($(CONFIG_PERF_BPF_SKEL),y)
10461046
BPFTOOL := $(SKEL_TMP_OUT)/bootstrap/bpftool
10471047
# Get Clang's default includes on this system, as opposed to those seen by
10481048
# '--target=bpf'. This fixes "missing" files on some architectures/distros,
@@ -1120,11 +1120,11 @@ bpf-skel: $(SKELETONS)
11201120

11211121
.PRECIOUS: $(SKEL_TMP_OUT)/%.bpf.o
11221122

1123-
else # BUILD_BPF_SKEL
1123+
else # CONFIG_PERF_BPF_SKEL
11241124

11251125
bpf-skel:
11261126

1127-
endif # BUILD_BPF_SKEL
1127+
endif # CONFIG_PERF_BPF_SKEL
11281128

11291129
bpf-skel-clean:
11301130
$(call QUIET_CLEAN, bpf-skel) $(RM) -r $(SKEL_TMP_OUT) $(SKELETONS)

0 commit comments

Comments
 (0)