]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Check for _Unwind_Backtrace() support
authorMichał Kępień <michal@isc.org>
Fri, 30 Oct 2020 08:12:50 +0000 (09:12 +0100)
committerMichał Kępień <michal@isc.org>
Fri, 30 Oct 2020 08:42:24 +0000 (09:42 +0100)
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.

(cherry picked from commit 10d705579189c6f4363bc2a85a0b559a6fbcb264)

config.h.in
configure
configure.ac
lib/isc/backtrace.c

index 49b73f89b5f0df2d3dfcceaa3691eebabfe2a4dc..7ba51322db6c566b6a23026a143eceb4faaafc47 100644 (file)
@@ -531,6 +531,9 @@ int sigwait(const unsigned int *set, int *sig);
 /* 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
 
index e92f4c23bac4aff7a18eb4e20e53a1e9054e5527..0faca65f22a9c26def693042e8d5e7d185c67fba 100755 (executable)
--- a/configure
+++ b/configure
@@ -19448,6 +19448,25 @@ if ac_fn_c_try_link "$LINENO"; then :
 
 $as_echo "#define HAVE_LIBCTRACE /**/" >>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 \
     conftest$ac_exeext conftest.$ac_ext
index b743f3e205a21e56b43177de7ff03bfa8a9b1547..45a15241febc7ee10a067a89d5d900e24837d3b1 100644 (file)
@@ -2894,7 +2894,10 @@ yes)
        ISC_PLATFORM_USEBACKTRACE="#define ISC_PLATFORM_USEBACKTRACE 1"
        AC_TRY_LINK([#include <execinfo.h>],
        [return (backtrace((void **)0, 0));],
-       [AC_DEFINE([HAVE_LIBCTRACE], [], [if system have backtrace function])],)
+       [AC_DEFINE([HAVE_LIBCTRACE], [], [if system have backtrace function])],
+       [AC_TRY_LINK([#include <stddef.h>],
+                    [return _Unwind_Backtrace(NULL, NULL);],
+                    [AC_DEFINE([HAVE_UNWIND_BACKTRACE], [1], [define if the compiler supports _Unwind_Backtrace()])])])
        ;;
 *)
        ISC_PLATFORM_USEBACKTRACE="#undef ISC_PLATFORM_USEBACKTRACE"
index 58add09255dd9b2506ca6f3566edd53c88a10b8a..b2d61d6f4a8875ad2371316410c557535dd2717c 100644 (file)
@@ -43,7 +43,7 @@
  */
 #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