This is an automated email from Gerrit.

"R. Diez <[email protected]>" just uploaded a new patch set to Gerrit, which 
you can find at https://review.openocd.org/c/openocd/+/9394

-- gerrit

commit 62dfc0499feedb14dcbdf0b9135fad3c1082e3c7
Author: R. Diez <[email protected]>
Date:   Mon Jan 19 18:12:46 2026 +0100

    configure.ac: Detect mallinfo automatically
    
    Previously, configure.ac only checked whether glibc was available,
    but other C runtime libraries like Newlib have mallinfo too.
    
    This is a first step to remove configuration option --enable-malloc-logging
    and replace it with a debug level configurable at runtime.
    
    Change-Id: If30fc98a84158459e222fddf08043f46d6fa4112
    Signed-off-by: R. Diez <[email protected]>

diff --git a/configure.ac b/configure.ac
index d0ab15b624..cb48e1737a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -56,15 +56,9 @@ AC_CHECK_TYPE([Elf64_Ehdr],
        AC_DEFINE([HAVE_ELF64], [1], [Define to 1 if the system has the type 
'Elf64_Ehdr'.]),
        [], [[#include <elf.h>]])
 
-AC_MSG_CHECKING([for glibc])
-AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <features.h>]], [[int v = 
__GLIBC__;return 0;]])],
-       [have_glibc=yes], [have_glibc=no])
-AC_MSG_RESULT($have_glibc)
-
 AC_CHECK_HEADERS([fcntl.h])
 AC_CHECK_HEADERS([linux/pci.h])
 AC_CHECK_HEADERS([linux/spi/spidev.h])
-AC_CHECK_HEADERS([malloc.h])
 AC_CHECK_HEADERS([netdb.h])
 AC_CHECK_HEADERS([poll.h])
 AC_CHECK_HEADERS([strings.h])
@@ -102,6 +96,8 @@ AC_CHECK_FUNCS([strnlen])
 AC_CHECK_FUNCS([gettimeofday])
 AC_CHECK_FUNCS([usleep])
 AC_CHECK_FUNCS([realpath])
+AC_CHECK_FUNCS([mallinfo],  [has_at_least_one_mallinfo=yes])
+AC_CHECK_FUNCS([mallinfo2], [has_at_least_one_mallinfo=yes])
 
 # guess-rev.sh only exists in the repository, not in the released archives
 AC_MSG_CHECKING([whether to build a release])
@@ -276,7 +272,10 @@ AC_ARG_ENABLE([malloc_logging],
 
 AC_MSG_CHECKING([whether to enable malloc free space logging]);
 AC_MSG_RESULT([$debug_malloc])
-AS_IF([test "x$debug_malloc" = "xyes" -a "x$have_glibc" = "xyes"], [
+AS_IF([test "x$debug_malloc" = "xyes"], [
+       AS_IF([test "x$has_at_least_one_mallinfo" != "xyes"], [
+               AC_MSG_ERROR([Option --enable-malloc-logging needs a libc with 
mallinfo or mallinfo2.])
+       ])
   AC_DEFINE([_DEBUG_FREE_SPACE_],[1], [Include malloc free space in logging])
 ])
 
diff --git a/src/helper/log.c b/src/helper/log.c
index 0fff674f76..f8aaa49c07 100644
--- a/src/helper/log.c
+++ b/src/helper/log.c
@@ -25,23 +25,7 @@
 #include <stdarg.h>
 
 #ifdef _DEBUG_FREE_SPACE_
-#ifdef HAVE_MALLOC_H
-#include <malloc.h>
-#else
-#error "malloc.h is required to use --enable-malloc-logging"
-#endif
-
-#ifdef __GLIBC__
-#if __GLIBC_PREREQ(2, 33)
-#define FORDBLKS_FORMAT " %zu"
-#else
-/* glibc older than 2.33 (2021-02-01) use mallinfo(). Overwrite it */
-#define mallinfo2 mallinfo
-#define FORDBLKS_FORMAT " %d"
-#endif
-#else
-#error "GNU glibc is required to use --enable-malloc-logging"
-#endif
+#include <malloc.h>  // For mallinfo/mallinfo2.
 #endif
 
 int debug_level = LOG_LVL_INFO;
@@ -118,11 +102,23 @@ static void log_puts(enum log_levels level,
                /* print with count and time information */
                int64_t t = timeval_ms() - start;
 #ifdef _DEBUG_FREE_SPACE_
+#ifdef HAVE_MALLINFO2
                struct mallinfo2 info = mallinfo2();
+#elif defined(HAVE_MALLINFO)
+               struct mallinfo info = mallinfo();
+#else
+#error "Configuration error: Neither mallinfo() nor mallinfo2() are available."
+#endif
 #endif
                fprintf(log_output, "%s%d %" PRId64 " %s:%d %s()"
 #ifdef _DEBUG_FREE_SPACE_
-                       FORDBLKS_FORMAT
+#ifdef HAVE_MALLINFO2
+                       " %zu"
+#elif defined(HAVE_MALLINFO)
+                       " %d"
+#else
+#error "Configuration error: Neither mallinfo() nor mallinfo2() are available."
+#endif
 #endif
                        ": %s", log_strings[level + 1], count, t, file, line, 
function,
 #ifdef _DEBUG_FREE_SPACE_

-- 

Reply via email to