[PATCH v1 03/11] perf unwind-libdw: missing <stdlib.h> in libdw_set_initial_registers()

From: Ian Rogers

Date: Thu Sep 17 2026 - 00:53:58 EST


Sashiko reported:

When building the perf tool against strict C standard libraries
(such as musl libc), compilation fails in
tools/perf/util/unwind-libdw.c due to implicit declarations of
memory allocation functions.

The libdw_set_initial_registers() function dynamically allocates an
array of DWARF registers using calloc() and subsequently releases it
with free(). However, the source file lacks an explicit #include
<stdlib.h>. On build environments where standard headers do not
implicitly chain-include <stdlib.h>, these functions remain
undeclared, resulting in fatal implicit function declaration errors
that break the build.

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/unwind-libdw.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/tools/perf/util/unwind-libdw.c b/tools/perf/util/unwind-libdw.c
index ebea101e1001..714ff455f28b 100644
--- a/tools/perf/util/unwind-libdw.c
+++ b/tools/perf/util/unwind-libdw.c
@@ -1,24 +1,29 @@
// SPDX-License-Identifier: GPL-2.0
+#include "unwind-libdw.h"
+
#include <assert.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <stdlib.h>
+
#include <linux/compiler.h>
+#include <linux/types.h>
+#include <linux/zalloc.h>
+
+#include <dwarf-regs.h>
#include <elfutils/libdw.h>
#include <elfutils/libdwfl.h>
-#include <inttypes.h>
-#include <errno.h>
+
+#include "callchain.h"
#include "debug.h"
#include "dso.h"
-#include <dwarf-regs.h>
-#include "unwind.h"
-#include "unwind-libdw.h"
+#include "event.h"
#include "machine.h"
#include "map.h"
+#include "perf_regs.h"
#include "symbol.h"
#include "thread.h"
-#include <linux/types.h>
-#include <linux/zalloc.h>
-#include "event.h"
-#include "perf_regs.h"
-#include "callchain.h"
+#include "unwind.h"
#include "util/env.h"

/*
--
2.55.0.1082.g2b9226bbc0-goog