[PATCH v1 05/11] perf dso: missing POSIX headers string.h and limits.h
From: Ian Rogers
Date: Thu Sep 17 2026 - 00:54:13 EST
Sashiko reported:
When building the perf tool on a system using the musl C library,
compilation of tools/perf/util/dso.c fails because it utilizes
standard string operations and the PATH_MAX macro without explicitly
including <string.h> and <limits.h>.
Functions like dso__read_binary_type_filename() allocate arrays
sized by PATH_MAX and perform string manipulations using strncpy(),
strlen(), and strdup(). While glibc implicitly exposes these POSIX
definitions via other included standard library headers such as
<stdlib.h>, musl enforces strict header dependency
boundaries. Consequently, these macros and functions remain
undeclared during preprocessing, resulting in a fatal compiler
error.
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/dso.c | 47 +++++++++++++++++++++++++------------------
1 file changed, 27 insertions(+), 20 deletions(-)
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 42bfe30a3b51..592fb971ffaa 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -1,38 +1,45 @@
// SPDX-License-Identifier: GPL-2.0
+#include "dso.h"
+
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
+
#include <asm/bug.h>
+#include <fcntl.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/zalloc.h>
-#include <sys/time.h>
#include <sys/resource.h>
-#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
#include <unistd.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#ifdef HAVE_LIBBPF_SUPPORT
-#include <bpf/libbpf.h>
-#include "bpf-event.h"
-#include "bpf-utils.h"
-#endif
+
+#include "annotate-data.h"
+#include "auxtrace.h"
#include "compress.h"
+#include "debug.h"
+#include "dsos.h"
#include "env.h"
+#include "libdw.h"
+#include "machine.h"
+#include "map.h"
#include "namespaces.h"
#include "path.h"
-#include "map.h"
-#include "symbol.h"
#include "srcline.h"
-#include "dso.h"
-#include "dsos.h"
-#include "machine.h"
-#include "auxtrace.h"
-#include "util.h" /* O_CLOEXEC for older systems */
-#include "debug.h"
#include "string2.h"
+#include "symbol.h"
+#include "util.h" /* O_CLOEXEC for older systems */
#include "vdso.h"
-#include "annotate-data.h"
-#include "libdw.h"
+
+#ifdef HAVE_LIBBPF_SUPPORT
+#include <bpf/libbpf.h>
+
+#include "bpf-event.h"
+#include "bpf-utils.h"
+#endif
static const char * const debuglink_paths[] = {
"%.0s%s",
--
2.55.0.1082.g2b9226bbc0-goog