kallsyms: fix build without execinfo
authorAchill Gilgenast <fossdd@pwned.life>
Sun, 22 Jun 2025 01:45:49 +0000 (03:45 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 10 Jul 2025 04:07:51 +0000 (21:07 -0700)
Some libc's like musl libc don't provide execinfo.h since it's not part of
POSIX.  In order to fix compilation on musl, only include execinfo.h if
available (HAVE_BACKTRACE_SUPPORT)

This was discovered with c104c16073b7 ("Kunit to check the longest symbol
length") which starts to include linux/kallsyms.h with Alpine Linux'
configs.

Link: https://lkml.kernel.org/r/20250622014608.448718-1-fossdd@pwned.life
Fixes: c104c16073b7 ("Kunit to check the longest symbol length")
Signed-off-by: Achill Gilgenast <fossdd@pwned.life>
Cc: Luis Henriques <luis@igalia.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
tools/include/linux/kallsyms.h

index 5a37ccbec54fbc603108ad9346c0351c8a3c56a8..f61a01dd7eb7c7833a335c21b660c0c9332bbeff 100644 (file)
@@ -18,6 +18,7 @@ static inline const char *kallsyms_lookup(unsigned long addr,
        return NULL;
 }
 
+#ifdef HAVE_BACKTRACE_SUPPORT
 #include <execinfo.h>
 #include <stdlib.h>
 static inline void print_ip_sym(const char *loglvl, unsigned long ip)
@@ -30,5 +31,8 @@ static inline void print_ip_sym(const char *loglvl, unsigned long ip)
 
        free(name);
 }
+#else
+static inline void print_ip_sym(const char *loglvl, unsigned long ip) {}
+#endif
 
 #endif