[PATCH v1 09/11] perf mem: missing stdio.h and limits.h in mem-events.c

From: Ian Rogers

Date: Thu Sep 17 2026 - 00:57:35 EST


Sashiko reported:

When compiling the perf tool against a strict POSIX C library such
as musl libc, tools/perf/util/mem-events.c fails to build due to the
use of undeclared standard symbols.

The source file defines an array using PATH_MAX in
perf_pmu__mem_events_supported(), and utilizes fprintf() with stderr
in perf_pmu__mem_events_list():

Because the required <limits.h> and <stdio.h> headers are not
explicitly included, these symbols remain undeclared. While glibc
masks this omission by implicitly pulling in these definitions via
other standard headers, musl libc adheres strictly to POSIX
inclusions. This causes the compiler to reject the undeclared
PATH_MAX macro, the stderr stream, and the fprintf() function,
halting the build process on systems utilizing strict libc
implementations.

Add the header files and use git clang-format to sort.

Reported-by: sashiko-bot@xxxxxxxxxx
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/util/mem-events.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c
index 0b49fce251fc..64aecc2b67e5 100644
--- a/tools/perf/util/mem-events.c
+++ b/tools/perf/util/mem-events.c
@@ -1,22 +1,28 @@
// SPDX-License-Identifier: GPL-2.0
+#include "mem-events.h"
+
+#include <errno.h>
+#include <limits.h>
#include <stddef.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <errno.h>
-#include <sys/types.h>
+
+#include <linux/kernel.h>
#include <sys/stat.h>
+#include <sys/types.h>
#include <unistd.h>
+
#include <api/fs/fs.h>
-#include <linux/kernel.h>
+
#include "cpumap.h"
-#include "map_symbol.h"
-#include "mem-events.h"
-#include "mem-info.h"
#include "debug.h"
#include "evsel.h"
-#include "symbol.h"
+#include "map_symbol.h"
+#include "mem-info.h"
#include "pmu.h"
#include "pmus.h"
+#include "symbol.h"

unsigned int perf_mem_events__loads_ldlat = 30;

--
2.55.0.1082.g2b9226bbc0-goog