e2fsprogs icon indicating copy to clipboard operation
e2fsprogs copied to clipboard

Having autoconf script check for libexecinfo when looking for backtrace

Open brad0 opened this issue 3 years ago • 1 comments

Currently the autoconf script checks for the execinfo.h header and backtrace function in libc (.e.g. glibc). But FreeBSD / NetBSD / OpenBSD and DragonFlyBSD as well as musl-based Linux OS's use libexecinfo for the backtrace functionality. Please have the script also check for libexecinfo if the function does not exist in libc.

brad0 avatar Jan 30 '22 22:01 brad0

To check for the presence of libexecinfo on BSD-based systems and musl-based Linux OS's in addition to the execinfo.h header and the backtrace function from libc, you can modify your autoconf script as follows:

AC_CHECK_HEADERS([execinfo.h])
AC_CHECK_FUNCS([backtrace])

# Check for libexecinfo
AC_ARG_WITH([libexecinfo],
    AS_HELP_STRING([--with-libexecinfo], [Use libexecinfo for backtrace]),
    [use_libexecinfo="$withval"],
    [use_libexecinfo="no"])

if test "x$use_libexecinfo" = "xyes"; then
    AC_CHECK_LIB([execinfo], [backtrace], [LIBEXECINFO_LIBS="-lexecinfo"])
fi

# Check if backtrace is found
if test -z "$LIBEXECINFO_LIBS"; then
    AC_MSG_ERROR([Cannot find backtrace function or libexecinfo])
fi

AC_SUBST([LIBEXECINFO_LIBS])

In this updated script:

  1. We use AC_ARG_WITH to introduce an optional --with-libexecinfo flag, which allows the user to explicitly specify whether to use libexecinfo or not.

  2. If the user specifies --with-libexecinfo=yes, we check for the presence of libexecinfo using AC_CHECK_LIB.

  3. We then ensure that either the backtrace function from libc or libexecinfo is found. If neither is found, we display an error message.

ljluestc avatar Sep 10 '23 20:09 ljluestc