[PATCH mtd-utils 4/5] configure.ac: Add a check for execinfo and backtrace

Fabio Estevam festevam at gmail.com
Tue Feb 18 14:00:48 PST 2025


Hi Khem,

On Tue, Feb 18, 2025 at 1:21 PM Khem Raj <raj.khem at gmail.com> wrote:

> maybe check for backtrace function in libc first and if not found then
> try libexecinfo check.

I implemented your suggestion like this:

--- a/configure.ac
+++ b/configure.ac
@@ -238,6 +238,17 @@ if test "x$need_cmocka" = "xyes"; then
  PKG_CHECK_MODULES(CMOCKA, [cmocka], [], [cmocka_missing="yes"])
 fi

+AC_CHECK_FUNC([backtrace], [have_backtrace=yes], [have_backtrace=no])
+
+if test "x$have_backtrace" = "xno"; then
+    AC_CHECK_LIB([execinfo], [backtrace],
+        [LIBS="$LIBS -lexecinfo"
+         AC_DEFINE([HAVE_BACKTRACE], [1], [backtrace is available via
libexecinfo])],
+        [AC_MSG_WARN([backtrace support not found])])
+else
+    AC_DEFINE([HAVE_BACKTRACE], [1], [backtrace is available via libc])
+fi
+
 AC_CHECK_HEADERS([execinfo.h])

And tested in two cases:

With glibc:
checking for backtrace... yes

With musl:
checking for backtrace... no
checking for backtrace in -lexecinfo... yes

Does this look good?

Thanks



More information about the linux-mtd mailing list