Skip to content

Commit 183db6c

Browse files
committed
build: Check unw_init_local() with custom test.
The most popular, HP's implementation of libunwind doesn't provide the unw_init_local() symbol by that name (the actual symbol is `_ULx86_64_init_local`), so it can fail the AC_CHECK_LIB test. Since there is no symbol that we can portably test with AC_CHECK_LIB on libunwind, remove the macro call altogether and favor the test program that I have introduced in 924aa4d. This fixes a regression from commit de6de25. Note: There're two common implementations of libunwind. One is from HP and the other is from LLVM. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
1 parent bf17a7e commit 183db6c

2 files changed

Lines changed: 23 additions & 22 deletions

File tree

CRT.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ in the source distribution for its full text.
2929
#include <sys/mman.h>
3030
#endif
3131

32-
#if defined(HAVE_LIBUNWIND) && defined(HAVE_LOCAL_UNWIND)
32+
#if defined(HAVE_LIBUNWIND_H) && defined(HAVE_LOCAL_UNWIND)
3333
# define PRINT_BACKTRACE
3434
# define UNW_LOCAL_ONLY
3535
# include <libunwind.h>
@@ -1346,7 +1346,7 @@ void CRT_setColors(int colorScheme) {
13461346

13471347
#ifdef PRINT_BACKTRACE
13481348
static void print_backtrace(void) {
1349-
#if defined(HAVE_LIBUNWIND) && defined(HAVE_LOCAL_UNWIND)
1349+
#if defined(HAVE_LIBUNWIND_H) && defined(HAVE_LOCAL_UNWIND)
13501350
unw_context_t context;
13511351
unw_getcontext(&context);
13521352

configure.ac

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -948,33 +948,32 @@ case "$enable_unwind" in
948948
AC_CHECK_LIB([lzma], [lzma_index_buffer_decode])
949949
fi
950950

951-
AC_CHECK_LIB(
952-
[unwind],
953-
[unw_init_local],
954-
[],
955-
[
956-
if test "$enable_unwind" = yes; then
957-
AC_MSG_ERROR([can not find required library libunwind])
958-
fi
959-
enable_unwind=no
960-
]
961-
)
951+
if htop_search_header_dir libunwind.h "/usr/include/libunwind"; then
952+
AC_DEFINE([HAVE_LIBUNWIND_H], 1, [Define to 1 if you have the <libunwind.h> header file.])
953+
elif test "$enable_unwind" = yes; then
954+
AC_MSG_ERROR([can not find required header file libunwind.h])
955+
else
956+
enable_unwind=no
957+
fi
962958
;;
963959
*)
964960
AC_MSG_ERROR([bad value '$enable_unwind' for --enable-unwind])
965961
;;
966962
esac
967963

968-
if test "$enable_unwind" = no; then
969-
:
970-
elif htop_search_header_dir libunwind.h "/usr/include/libunwind"; then
964+
if test "$enable_unwind" != no; then
971965
htop_save_CPPFLAGS=$CPPFLAGS
966+
htop_save_LIBS=$LIBS
972967
CPPFLAGS="$AM_CPPFLAGS $CPPFLAGS"
968+
LIBS="-lunwind $LIBS"
973969

974-
AC_MSG_CHECKING([whether local unwinding works])
970+
# unw_init_local() is a macro in HP's implemention of libunwind
971+
# (the most popular one, Mosberger et al.)
972+
AC_MSG_CHECKING([whether -lunwind supports local unwinding])
975973
AC_LINK_IFELSE(
976974
[AC_LANG_PROGRAM(
977975
[[
976+
#define UNW_LOCAL_ONLY
978977
#include <libunwind.h>
979978
]], [[
980979
/* If libunwind is built with remote unwinding only,
@@ -1013,21 +1012,23 @@ elif htop_search_header_dir libunwind.h "/usr/include/libunwind"; then
10131012
if test "$enable_unwind" = yes; then
10141013
AC_MSG_WARN([this build of libunwind might not support local unwinding])
10151014
else
1015+
LIBS=$htop_save_LIBS
10161016
enable_unwind=no
10171017
fi
10181018
fi
10191019
],
10201020
[
10211021
AC_MSG_RESULT([no])
1022-
AC_MSG_FAILURE([there are problems with libunwind.h])
1022+
if test "$enable_unwind" = yes; then
1023+
AC_MSG_FAILURE([can not link with libunwind])
1024+
else
1025+
LIBS=$htop_save_LIBS
1026+
enable_unwind=no
1027+
fi
10231028
]
10241029
)
10251030

10261031
CPPFLAGS=$htop_save_CPPFLAGS
1027-
elif test "$enable_unwind" = yes; then
1028-
AC_MSG_ERROR([can not find required header file libunwind.h])
1029-
else
1030-
enable_unwind=no
10311032
fi
10321033

10331034
if test "$enable_unwind" != no; then

0 commit comments

Comments
 (0)