xref: /freebsd/sys/contrib/openzfs/config/user-libunwind.m4 (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
1dnl
2dnl Checks for libunwind, which usually does a better job than backtrace() when
3dnl resolving symbols in the stack backtrace. Newer versions have support for
4dnl getting info about the object file the function came from, so we look for
5dnl that too and use it if found.
6dnl
7AC_DEFUN([ZFS_AC_CONFIG_USER_LIBUNWIND], [
8	AC_ARG_WITH([libunwind],
9	    AS_HELP_STRING([--with-libunwind],
10		[use libunwind for backtraces in userspace assertions]),
11	    [],
12	    [with_libunwind=auto])
13
14	AS_IF([test "x$with_libunwind" != "xno"], [
15		ZFS_AC_FIND_SYSTEM_LIBRARY(LIBUNWIND, [libunwind], [libunwind.h], [], [unwind], [], [
16			dnl unw_get_elf_filename() is sometimes a macro, other
17			dnl times a proper symbol, so we can't just do a link
18			dnl check; we need to include the header properly.
19			AX_SAVE_FLAGS
20			CFLAGS="$CFLAGS $LIBUNWIND_CFLAGS"
21			LIBS="$LIBS $LIBUNWIND_LIBS"
22			AC_MSG_CHECKING([for unw_get_elf_filename in libunwind])
23			AC_LINK_IFELSE([
24				AC_LANG_PROGRAM([
25					#define UNW_LOCAL_ONLY
26					#include <libunwind.h>
27				], [
28					unw_get_elf_filename(0, 0, 0, 0);
29				])
30			], [
31				AC_MSG_RESULT([yes])
32				AC_DEFINE(HAVE_LIBUNWIND_ELF, 1,
33				    [libunwind has unw_get_elf_filename])
34			], [
35				AC_MSG_RESULT([no])
36			])
37			AX_RESTORE_FLAGS
38		], [
39			AS_IF([test "x$with_libunwind" = "xyes"], [
40				AC_MSG_FAILURE([--with-libunwind was given, but libunwind is not available, try installing libunwind-devel])
41			])
42		])
43	])
44])
45