Skip to content

Commit 1d0654b

Browse files
blakej11namhyung
authored andcommitted
perf build: detect support for libbpf's emit_strings option
This creates a config option that detects libbpf's ability to display character arrays as strings, which was just added to the BPF tree (https://git.kernel.org/bpf/bpf-next/c/87c9c79a02b4). To test this change, I built perf (from later in this patch set) with: - static libbpf (default, using source from kernel tree) - dynamic libbpf (LIBBPF_DYNAMIC=1 LIBBPF_INCLUDE=/usr/local/include) For both the static and dynamic versions, I used headers with and without the ".emit_strings" option. I verified that of the four resulting binaries, the two with ".emit_strings" would successfully record BPF_METADATA events, and the two without wouldn't. All four binaries would successfully display BPF_METADATA events, because the relevant bit of libbpf code is only used during "perf record". Signed-off-by: Blake Jones <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent 13b38e6 commit 1d0654b

File tree

6 files changed

+25
-0
lines changed

6 files changed

+25
-0
lines changed

tools/build/Makefile.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ FEATURE_TESTS_EXTRA := \
126126
llvm \
127127
clang \
128128
libbpf \
129+
libbpf-strings \
129130
libpfm4 \
130131
libdebuginfod \
131132
clang-bpf-co-re \

tools/build/feature/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ FILES= \
5959
test-lzma.bin \
6060
test-bpf.bin \
6161
test-libbpf.bin \
62+
test-libbpf-strings.bin \
6263
test-get_cpuid.bin \
6364
test-sdt.bin \
6465
test-cxx.bin \
@@ -339,6 +340,9 @@ $(OUTPUT)test-bpf.bin:
339340
$(OUTPUT)test-libbpf.bin:
340341
$(BUILD) -lbpf
341342

343+
$(OUTPUT)test-libbpf-strings.bin:
344+
$(BUILD)
345+
342346
$(OUTPUT)test-sdt.bin:
343347
$(BUILD)
344348

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include <bpf/btf.h>
3+
4+
int main(void)
5+
{
6+
struct btf_dump_type_data_opts opts;
7+
8+
opts.emit_strings = 0;
9+
return opts.emit_strings;
10+
}

tools/perf/Documentation/perf-check.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ feature::
5252
dwarf-unwind / HAVE_DWARF_UNWIND_SUPPORT
5353
auxtrace / HAVE_AUXTRACE_SUPPORT
5454
libbfd / HAVE_LIBBFD_SUPPORT
55+
libbpf-strings / HAVE_LIBBPF_STRINGS_SUPPORT
5556
libcapstone / HAVE_LIBCAPSTONE_SUPPORT
5657
libcrypto / HAVE_LIBCRYPTO_SUPPORT
5758
libdw-dwarf-unwind / HAVE_LIBDW_SUPPORT

tools/perf/Makefile.config

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,16 @@ ifndef NO_LIBELF
595595
LIBBPF_STATIC := 1
596596
$(call detected,CONFIG_LIBBPF)
597597
CFLAGS += -DHAVE_LIBBPF_SUPPORT
598+
LIBBPF_INCLUDE = $(LIBBPF_DIR)/..
598599
endif
599600
endif
601+
602+
FEATURE_CHECK_CFLAGS-libbpf-strings="-I$(LIBBPF_INCLUDE)"
603+
$(call feature_check,libbpf-strings)
604+
ifeq ($(feature-libbpf-strings), 1)
605+
$(call detected,CONFIG_LIBBPF_STRINGS)
606+
CFLAGS += -DHAVE_LIBBPF_STRINGS_SUPPORT
607+
endif
600608
endif
601609
endif # NO_LIBBPF
602610
endif # NO_LIBELF

tools/perf/builtin-check.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct feature_status supported_features[] = {
4343
FEATURE_STATUS("dwarf-unwind", HAVE_DWARF_UNWIND_SUPPORT),
4444
FEATURE_STATUS("auxtrace", HAVE_AUXTRACE_SUPPORT),
4545
FEATURE_STATUS_TIP("libbfd", HAVE_LIBBFD_SUPPORT, "Deprecated, license incompatibility, use BUILD_NONDISTRO=1 and install binutils-dev[el]"),
46+
FEATURE_STATUS("libbpf-strings", HAVE_LIBBPF_STRINGS_SUPPORT),
4647
FEATURE_STATUS("libcapstone", HAVE_LIBCAPSTONE_SUPPORT),
4748
FEATURE_STATUS("libcrypto", HAVE_LIBCRYPTO_SUPPORT),
4849
FEATURE_STATUS("libdw-dwarf-unwind", HAVE_LIBDW_SUPPORT),

0 commit comments

Comments
 (0)