perf bpf: Enclose libbpf.h include within HAVE_LIBBPF_SUPPORT
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 20 Oct 2020 17:12:37 +0000 (14:12 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 4 Nov 2020 12:42:40 +0000 (09:42 -0300)
As it uses the 'deprecated' attribute in a way that breaks the build
with old gcc compilers, so to continue being able to build in such
systems where NO_LIBBPF=1 is being used, enclose it under
HAVE_LIBBPF_SUPPORT.

   1 centos:6          : FAIL gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23)
   2 oraclelinux:6     : FAIL gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23.0.1)

    CC       /tmp/build/perf/builtin-record.o
  In file included from util/bpf-loader.h:11,
                   from builtin-record.c:39:
  /git/linux/tools/lib/bpf/libbpf.h:203: error: wrong number of arguments specified for 'deprecated' attribute

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/bpf-loader.h
tools/perf/util/parse-events.c

index 25251d63164ceee62acfc7231aecdc4caec4d24b..5d1c725cea295b28e015316d63698daf272510d7 100644 (file)
@@ -8,6 +8,8 @@
 
 #include <linux/compiler.h>
 #include <linux/err.h>
+
+#ifdef HAVE_LIBBPF_SUPPORT
 #include <bpf/libbpf.h>
 
 enum bpf_loader_errno {
@@ -38,6 +40,7 @@ enum bpf_loader_errno {
        BPF_LOADER_ERRNO__OBJCONF_MAP_IDX2BIG,  /* Index too large */
        __BPF_LOADER_ERRNO__END,
 };
+#endif // HAVE_LIBBPF_SUPPORT
 
 struct evsel;
 struct evlist;
index 3b273580fb840196ea33fe6e510b75afa4bdb715..3b581d7b3213109edf7bba578166264577359574 100644 (file)
@@ -668,6 +668,7 @@ static int add_tracepoint_multi_sys(struct list_head *list, int *idx,
        return ret;
 }
 
+#ifdef HAVE_LIBBPF_SUPPORT
 struct __add_bpf_event_param {
        struct parse_events_state *parse_state;
        struct list_head *list;
@@ -900,6 +901,30 @@ int parse_events_load_bpf(struct parse_events_state *parse_state,
                list_splice_tail(&obj_head_config, head_config);
        return err;
 }
+#else // HAVE_LIBBPF_SUPPORT
+int parse_events_load_bpf_obj(struct parse_events_state *parse_state,
+                             struct list_head *list __maybe_unused,
+                             struct bpf_object *obj __maybe_unused,
+                             struct list_head *head_config __maybe_unused)
+{
+       parse_events__handle_error(parse_state->error, 0,
+                                  strdup("BPF support is not compiled"),
+                                  strdup("Make sure libbpf-devel is available at build time."));
+       return -ENOTSUP;
+}
+
+int parse_events_load_bpf(struct parse_events_state *parse_state,
+                         struct list_head *list __maybe_unused,
+                         char *bpf_file_name __maybe_unused,
+                         bool source __maybe_unused,
+                         struct list_head *head_config __maybe_unused)
+{
+       parse_events__handle_error(parse_state->error, 0,
+                                  strdup("BPF support is not compiled"),
+                                  strdup("Make sure libbpf-devel is available at build time."));
+       return -ENOTSUP;
+}
+#endif // HAVE_LIBBPF_SUPPORT
 
 static int
 parse_breakpoint_type(const char *type, struct perf_event_attr *attr)