use libunwind when it actually works

Previously we blindly tried to use libunwind whenever header is
detected. Even if actually working libunwind library is missing. This
is now fixed, so we attempt to use libunwind when it actually works.

Somehow recent freebsd ships libunwind.h (which seems to belong to
llvm's implementation), but apparently without matching .so. So then building
and linking failed.
This commit is contained in:
Aliaksey Kandratsenka 2023-06-21 10:38:31 -04:00
parent 90eff0637b
commit 0451d21e83
4 changed files with 9 additions and 4 deletions

View File

@ -258,6 +258,7 @@ if(gperftools_enable_libunwind)
if(have_libunwind)
set(unwind_libs ${libunwind_location})
set(will_use_libunwind ON)
set(USE_LIBUNWIND 1)
endif()
endif()
endif()

View File

@ -98,6 +98,8 @@
/* Define to 1 if you have the <libunwind.h> header file. */
#cmakedefine HAVE_LIBUNWIND_H
#cmakedefine USE_LIBUNWIND
/* Define to 1 if you have the <linux/ptrace.h> header file. */
#cmakedefine HAVE_LINUX_PTRACE_H

View File

@ -272,8 +272,10 @@ AM_CONDITIONAL(ENABLE_STATIC, test "$enable_static" = yes)
UNWIND_LIBS=
if test "$enable_libunwind" = yes; then
AC_CHECK_HEADERS([libunwind.h],
[AC_CHECK_LIB(unwind, backtrace, UNWIND_LIBS=-lunwind)
will_use_libunwind=yes])
[AC_CHECK_LIB(unwind, backtrace,
[UNWIND_LIBS=-lunwind
AC_DEFINE([USE_LIBUNWIND], [1], [libunwind.h was found and is working])
will_use_libunwind=yes])])
fi
AC_SUBST(UNWIND_LIBS)

View File

@ -102,14 +102,14 @@ struct GetStackImplementation {
// libunwind uses __thread so we check for both libunwind.h and
// __thread support
#if defined(HAVE_LIBUNWIND_H) && defined(HAVE_TLS)
#if defined(USE_LIBUNWIND) && defined(HAVE_TLS)
#define STACKTRACE_INL_HEADER "stacktrace_libunwind-inl.h"
#define GST_SUFFIX libunwind
#include "stacktrace_impl_setup-inl.h"
#undef GST_SUFFIX
#undef STACKTRACE_INL_HEADER
#define HAVE_GST_libunwind
#endif // HAVE_LIBUNWIND_H
#endif // USE_LIBUNWIND
#if defined(__i386__) || defined(__x86_64__)
#define STACKTRACE_INL_HEADER "stacktrace_x86-inl.h"