Some operating systems (e.g. Linux, FreeBSD) provide the
_Unwind_Backtrace() function in libgcc_s.so, which is automatically
linked into any binary using the functions provided by that library. On
OpenBSD, though, _Unwind_Backtrace() is provided by libc++abi.so, which
is not automatically linked into binaries produced by the stock system C
compiler.
Meanwhile, lib/isc/backtrace.c assumes that any GNU-compatible toolchain
allows _Unwind_Backtrace() to be used without any extra provisions in
the build system. This causes build failures on OpenBSD (and possibly
other systems).
Instead of making assumptions, actually check for _Unwind_Backtrace()
support in the toolchain if the backtrace() function is unavailable.
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
+/* define if the compiler supports _Unwind_Backtrace() */
+#undef HAVE_UNWIND_BACKTRACE
+
/* Define to 1 if you have the `usleep' function. */
#undef HAVE_USLEEP
$as_echo "#define HAVE_LIBCTRACE 1" >>confdefs.h
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <stddef.h>
+int
+main ()
+{
+return _Unwind_Backtrace(NULL, NULL);
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+$as_echo "#define HAVE_UNWIND_BACKTRACE 1" >>confdefs.h
+
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
fi
rm -f core conftest.err conftest.$ac_objext \
[[#include <execinfo.h>]],
[[return (backtrace((void **)0, 0));]]
)],
- [AC_DEFINE([HAVE_LIBCTRACE], [1], [define if system have backtrace function])]
+ [AC_DEFINE([HAVE_LIBCTRACE], [1], [define if system have backtrace function])],
+ [AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <stddef.h>]],
+ [[return _Unwind_Backtrace(NULL, NULL);]]
+ )],
+ [AC_DEFINE([HAVE_UNWIND_BACKTRACE], [1], [define if the compiler supports _Unwind_Backtrace()])]
+ )]
)])
# [pairwise: --enable-symtable, --disable-symtable]
*/
#ifdef HAVE_LIBCTRACE
#define BACKTRACE_LIBC
-#elif defined(__GNUC__) && (defined(__x86_64__) || defined(__ia64__))
+#elif defined(HAVE_UNWIND_BACKTRACE)
#define BACKTRACE_GCC
#elif defined(WIN32)
#define BACKTRACE_WIN32