Skip to contentSkip to conversation

libperf: Compile using -std=gnu17 to deal with visibility attribute issues

PATCH In review Arnaldo Carvalho de Melo 3 participants 3 messages Dec 3, 2025 – Dec 4, 2025 perf events

lore
Share & tools
lore

Arnaldo Carvalho de Melo

author maintainer
#0 lore raw

PATCH 1/1 libperf: Compile using -std=gnu17 to deal with visibility attribute issues

We seem to need a more invasive patch using 'extern' on all LIBPERF_API prefixed functions to be future proof, so use -std=gnu17 which is the one in gcc 14, present in the distro generation before ubuntu 25.10 (gcc 15).

But to make progress and avoid this on Ubuntu 25.10/gcc 15, lets to with the easy workaround:

evlist.c: In function 'perf_evlist__purge':
evlist.c:202:17: error: implicit declaration of function 'perf_evsel__delete'; did you mean 'perf_evsel__exit'? [-Wimplicit-function-declaration]

    202 |                 perf_evsel__delete(pos);
        |                 ^~~~~~~~~~~~~~~~~~
        |                 perf_evsel__exit
  evlist.c:202:17: error: nested extern declaration of 'perf_evsel__delete' [-Werror=nested-externs]
  evlist.c: In function 'perf_evlist__open':
  evlist.c:261:23: error: implicit declaration of function 'perf_evsel__open'; did you mean 'perf_evsel__exit'? [-Wimplicit-function-declaration]
    261 |                 err = perf_evsel__open(evsel, evsel->cpus, evsel->threads);
        |                       ^~~~~~~~~~~~~~~~
        |                       perf_evsel__exit

evlist.c:261:23: error: nested extern declaration of 'perf_evsel__open' [-Werror=nested-externs]

libbpf doesn't experience this because for some other reason it already has this line:

override CFLAGS += -std=gnu89

Cc Adrian Hunter <[email protected]>
Cc Ian Rogers <[email protected]>
Cc James Clark <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/lib/perf/Makefile | 1 +
 1 file changed, 1 insertion(+)
tools/lib/perf/Makefile +1 -0
index 7fbb50b74c00b3b9..5e12fd97f50c1efb 100644
@@ -51,6 +51,7 @@ INCLUDES = \
 -I$(srctree)/tools/include/uapi
 
 # Append required CFLAGS
+override CFLAGS += -std=gnu17
 override CFLAGS += -g -Werror -Wall
 override CFLAGS += -fPIC
 override CFLAGS += $(INCLUDES)
Signature · 1 line
2.52.0
maintainer
#1 lore raw
Quoted 4 lines · Arnaldo Carvalho de Melo

We seem to need a more invasive patch using 'extern' on all LIBPERF_API prefixed functions to be future proof, so use -std=gnu17 which is the one in gcc 14, present in the distro generation before ubuntu 25.10 (gcc 15).

Something like this?

Thanks,
Namhyung

tools/lib/perf/include/perf/core.h +1 -1
index a3f6d68edad76240..06cc132d88cf3436 100644
@@ -5,7 +5,7 @@
 #include <stdarg.h>
 
 #ifndef LIBPERF_API
-#define LIBPERF_API __attribute__((visibility("default")))
+#define LIBPERF_API extern __attribute__((visibility("default")))
 #endif
 
 enum libperf_print_level {
#2 lore raw
Quoted 7 lines · Namhyung Kim
Quoted 4 lines · Arnaldo Carvalho de Melo

We seem to need a more invasive patch using 'extern' on all LIBPERF_API prefixed functions to be future proof, so use -std=gnu17 which is the one in gcc 14, present in the distro generation before ubuntu 25.10 (gcc 15).

Something like this?

Yeah, I probably got carried away with libbpf's accidental way of "dealing" with it.

Will test build it, or have you already?

- Arnaldo

Quoted 10 lines

Thanks,
Namhyung

tools/lib/perf/include/perf/core.h +0 -0
index a3f6d68edad76240..06cc132d88cf3436 100644

tools/lib/perf/include/perf/core.h line 11

Quoted 8 lines
tools/lib/perf/include/perf/core.h +1 -1
@@ -5,7 +5,7 @@
 #include <stdarg.h>
 
 #ifndef LIBPERF_API
-#define LIBPERF_API __attribute__((visibility("default")))
+#define LIBPERF_API extern __attribute__((visibility("default")))
 #endif
 
 enum libperf_print_level {

- Arnaldo