mirror of
https://github.com/torvalds/linux.git
synced 2024-11-10 14:11:52 +00:00
perf build: Stop using __weak bpf_object__next_program() to handle older libbpf versions
By adding a feature test for bpf_object__next_program() and providing a fallback if it isn't present in older versions of libbpf. Committer testing: $ rpm -q libbpf-devel libbpf-devel-0.4.0-2.fc35.x86_64 $ make -C tools/perf LIBBPF_DYNAMIC=1 O=/tmp/build/perf install-bin $ cat /tmp/build/perf/feature/test-libbpf-bpf_object__next_program.make.output test-libbpf-bpf_object__next_program.c: In function ‘main’: test-libbpf-bpf_object__next_program.c:6:9: error: implicit declaration of function ‘bpf_object__next_program’; did you mean ‘bpf_object__unpin_programs’? [-Werror=implicit-function-declaration] 6 | bpf_object__next_program(NULL /* obj */, NULL /* prev */); | ^~~~~~~~~~~~~~~~~~~~~~~~ | bpf_object__unpin_programs cc1: all warnings being treated as errors $ $ objdump -dS /tmp/build/perf/perf | grep '<bpf_object__next_program>:' -A20 00000000005b2dc0 <bpf_object__next_program>: { 5b2dc0: 55 push %rbp 5b2dc1: 48 89 e5 mov %rsp,%rbp 5b2dc4: 48 83 ec 10 sub $0x10,%rsp 5b2dc8: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax 5b2dcf: 00 00 5b2dd1: 48 89 45 f8 mov %rax,-0x8(%rbp) 5b2dd5: 31 c0 xor %eax,%eax return bpf_program__next(prev, obj); 5b2dd7: 48 8b 45 f8 mov -0x8(%rbp),%rax 5b2ddb: 64 48 2b 04 25 28 00 sub %fs:0x28,%rax 5b2de2: 00 00 5b2de4: 75 0f jne 5b2df5 <bpf_object__next_program+0x35> } 5b2de6: c9 leave 5b2de7: 49 89 f8 mov %rdi,%r8 5b2dea: 48 89 f7 mov %rsi,%rdi return bpf_program__next(prev, obj); 5b2ded: 4c 89 c6 mov %r8,%rsi 5b2df0: e9 3b b4 e5 ff jmp 40e230 <bpf_program__next@plt> $ Signed-off-by: Jiri Olsa <jolsa@kernel.org> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Heiko Carstens <hca@linux.ibm.com> Cc: Ian Rogers <irogers@google.com> Cc: Ilya Leoshkevich <iii@linux.ibm.com> Cc: Sumanth Korikkar <sumanthk@linux.ibm.com> Cc: Sven Schnelle <svens@linux.ibm.com> Cc: Thomas Richter <tmricht@linux.ibm.com> Cc: Vasily Gorbik <gor@linux.ibm.com> Link: http://lore.kernel.org/linux-perf-users/YozLKby7ITEtchC9@krava Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
5c83eff381
commit
8916d72554
@ -100,6 +100,7 @@ FEATURE_TESTS_EXTRA := \
|
||||
libbpf \
|
||||
libbpf-btf__load_from_kernel_by_id \
|
||||
libbpf-bpf_prog_load \
|
||||
libbpf-bpf_object__next_program \
|
||||
libpfm4 \
|
||||
libdebuginfod \
|
||||
clang-bpf-co-re
|
||||
|
@ -59,6 +59,7 @@ FILES= \
|
||||
test-libbpf.bin \
|
||||
test-libbpf-btf__load_from_kernel_by_id.bin \
|
||||
test-libbpf-bpf_prog_load.bin \
|
||||
test-libbpf-bpf_object__next_program.bin \
|
||||
test-get_cpuid.bin \
|
||||
test-sdt.bin \
|
||||
test-cxx.bin \
|
||||
@ -295,6 +296,9 @@ $(OUTPUT)test-libbpf-btf__load_from_kernel_by_id.bin:
|
||||
$(OUTPUT)test-libbpf-bpf_prog_load.bin:
|
||||
$(BUILD) -lbpf
|
||||
|
||||
$(OUTPUT)test-libbpf-bpf_object__next_program.bin:
|
||||
$(BUILD) -lbpf
|
||||
|
||||
$(OUTPUT)test-sdt.bin:
|
||||
$(BUILD)
|
||||
|
||||
|
@ -0,0 +1,8 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include <bpf/libbpf.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
bpf_object__next_program(NULL /* obj */, NULL /* prev */);
|
||||
return 0;
|
||||
}
|
@ -577,12 +577,17 @@ ifndef NO_LIBELF
|
||||
ifeq ($(feature-libbpf-bpf_prog_load), 1)
|
||||
CFLAGS += -DHAVE_LIBBPF_BPF_PROG_LOAD
|
||||
endif
|
||||
$(call feature_check,libbpf-bpf_object__next_program)
|
||||
ifeq ($(feature-libbpf-bpf_object__next_program), 1)
|
||||
CFLAGS += -DHAVE_LIBBPF_BPF_OBJECT__NEXT_PROGRAM
|
||||
endif
|
||||
else
|
||||
dummy := $(error Error: No libbpf devel library found, please install libbpf-devel);
|
||||
endif
|
||||
else
|
||||
CFLAGS += -DHAVE_LIBBPF_BTF__LOAD_FROM_KERNEL_BY_ID
|
||||
CFLAGS += -DHAVE_LIBBPF_BPF_PROG_LOAD
|
||||
CFLAGS += -DHAVE_LIBBPF_BPF_OBJECT__NEXT_PROGRAM
|
||||
endif
|
||||
endif
|
||||
|
||||
|
@ -50,7 +50,8 @@ int bpf_prog_load(enum bpf_prog_type prog_type,
|
||||
}
|
||||
#endif
|
||||
|
||||
struct bpf_program * __weak
|
||||
#ifndef HAVE_LIBBPF_BPF_OBJECT__NEXT_PROGRAM
|
||||
struct bpf_program *
|
||||
bpf_object__next_program(const struct bpf_object *obj, struct bpf_program *prev)
|
||||
{
|
||||
#pragma GCC diagnostic push
|
||||
@ -58,6 +59,7 @@ bpf_object__next_program(const struct bpf_object *obj, struct bpf_program *prev)
|
||||
return bpf_program__next(prev, obj);
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
#endif
|
||||
|
||||
struct bpf_map * __weak
|
||||
bpf_object__next_map(const struct bpf_object *obj, const struct bpf_map *prev)
|
||||
|
Loading…
Reference in New Issue
Block a user