]> git.ipfire.org Git - people/ms/linux.git/commitdiff
perf build: Stop using __weak bpf_object__next_map() to handle older libbpf versions
authorJiri Olsa <jolsa@kernel.org>
Tue, 24 May 2022 11:13:17 +0000 (13:13 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 26 May 2022 14:02:02 +0000 (11:02 -0300)
By adding a feature test for bpf_object__next_map() 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_map.make.output
  test-libbpf-bpf_object__next_map.c: In function ‘main’:
  test-libbpf-bpf_object__next_map.c:6:9: error: implicit declaration of function ‘bpf_object__next_map’; did you mean ‘bpf_object__next’? [-Werror=implicit-function-declaration]
      6 |         bpf_object__next_map(NULL /* obj */, NULL /* prev */);
        |         ^~~~~~~~~~~~~~~~~~~~
        |         bpf_object__next
    cc1: all warnings being treated as errors
  $
  $ objdump -dS /tmp/build/perf/perf | grep '<bpf_object__next_map>:' -A20
  00000000005b2e00 <bpf_object__next_map>:
  {
    5b2e00: 55                    push   %rbp
    5b2e01: 48 89 e5              mov    %rsp,%rbp
    5b2e04: 48 83 ec 10           sub    $0x10,%rsp
    5b2e08: 64 48 8b 04 25 28 00  mov    %fs:0x28,%rax
    5b2e0f: 00 00
    5b2e11: 48 89 45 f8           mov    %rax,-0x8(%rbp)
    5b2e15: 31 c0                 xor    %eax,%eax
  return bpf_map__next(prev, obj);
    5b2e17: 48 8b 45 f8           mov    -0x8(%rbp),%rax
    5b2e1b: 64 48 2b 04 25 28 00  sub    %fs:0x28,%rax
    5b2e22: 00 00
    5b2e24: 75 0f                 jne    5b2e35 <bpf_object__next_map+0x35>
  }
    5b2e26: c9                    leave
    5b2e27: 49 89 f8              mov    %rdi,%r8
    5b2e2a: 48 89 f7              mov    %rsi,%rdi
  return bpf_map__next(prev, obj);
    5b2e2d: 4c 89 c6              mov    %r8,%rsi
    5b2e30: e9 cb b1 e5 ff        jmp    40e000 <bpf_map__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>
tools/build/Makefile.feature
tools/build/feature/Makefile
tools/build/feature/test-libbpf-bpf_object__next_map.c [new file with mode: 0644]
tools/perf/Makefile.config
tools/perf/util/bpf-event.c

index 64f8cfa6c9af62a85ff3b5f7c416f7d2c321f672..34cf2bff72ca20e5153e56cdf29d9224d743d75f 100644 (file)
@@ -101,6 +101,7 @@ FEATURE_TESTS_EXTRA :=                  \
          libbpf-btf__load_from_kernel_by_id \
          libbpf-bpf_prog_load           \
          libbpf-bpf_object__next_program \
+         libbpf-bpf_object__next_map    \
          libpfm4                        \
          libdebuginfod                 \
          clang-bpf-co-re
index 6eb829704cb93ec034443960db26cc7818aa82cb..aecb6a28a7702c9d0f16c8c8c112eb8d73b4cf30 100644 (file)
@@ -60,6 +60,7 @@ FILES=                                          \
          test-libbpf-btf__load_from_kernel_by_id.bin   \
          test-libbpf-bpf_prog_load.bin          \
          test-libbpf-bpf_object__next_program.bin \
+         test-libbpf-bpf_object__next_map.bin   \
          test-get_cpuid.bin                     \
          test-sdt.bin                           \
          test-cxx.bin                           \
@@ -299,6 +300,9 @@ $(OUTPUT)test-libbpf-bpf_prog_load.bin:
 $(OUTPUT)test-libbpf-bpf_object__next_program.bin:
        $(BUILD) -lbpf
 
+$(OUTPUT)test-libbpf-bpf_object__next_map.bin:
+       $(BUILD) -lbpf
+
 $(OUTPUT)test-sdt.bin:
        $(BUILD)
 
diff --git a/tools/build/feature/test-libbpf-bpf_object__next_map.c b/tools/build/feature/test-libbpf-bpf_object__next_map.c
new file mode 100644 (file)
index 0000000..64adb51
--- /dev/null
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <bpf/libbpf.h>
+
+int main(void)
+{
+       bpf_object__next_map(NULL /* obj */, NULL /* prev */);
+       return 0;
+}
index 046e10f65ae7ade7881973bce659ce1986946bea..a7a80e2280bd943a55ddd3ac9465c8ca15b313c7 100644 (file)
@@ -581,6 +581,10 @@ ifndef NO_LIBELF
           ifeq ($(feature-libbpf-bpf_object__next_program), 1)
             CFLAGS += -DHAVE_LIBBPF_BPF_OBJECT__NEXT_PROGRAM
           endif
+          $(call feature_check,libbpf-bpf_object__next_map)
+          ifeq ($(feature-libbpf-bpf_object__next_map), 1)
+            CFLAGS += -DHAVE_LIBBPF_BPF_OBJECT__NEXT_MAP
+          endif
         else
           dummy := $(error Error: No libbpf devel library found, please install libbpf-devel);
         endif
@@ -588,6 +592,7 @@ ifndef NO_LIBELF
        CFLAGS += -DHAVE_LIBBPF_BTF__LOAD_FROM_KERNEL_BY_ID
         CFLAGS += -DHAVE_LIBBPF_BPF_PROG_LOAD
         CFLAGS += -DHAVE_LIBBPF_BPF_OBJECT__NEXT_PROGRAM
+        CFLAGS += -DHAVE_LIBBPF_BPF_OBJECT__NEXT_MAP
       endif
     endif
 
index c68d88ca1ecea16d606a7334785f22e30aa92344..91c4c5dcab7faa4604cf1a9b08ec16d2e35339a1 100644 (file)
@@ -61,7 +61,8 @@ bpf_object__next_program(const struct bpf_object *obj, struct bpf_program *prev)
 }
 #endif
 
-struct bpf_map * __weak
+#ifndef HAVE_LIBBPF_BPF_OBJECT__NEXT_MAP
+struct bpf_map *
 bpf_object__next_map(const struct bpf_object *obj, const struct bpf_map *prev)
 {
 #pragma GCC diagnostic push
@@ -69,6 +70,7 @@ bpf_object__next_map(const struct bpf_object *obj, const struct bpf_map *prev)
        return bpf_map__next(prev, obj);
 #pragma GCC diagnostic pop
 }
+#endif
 
 const void * __weak
 btf__raw_data(const struct btf *btf_ro, __u32 *size)