[6.0] 0f92dccf3 Offer a configure --with-unwind switch
Martin Blix Grydeland
martin at varnish-software.com
Fri Nov 12 12:32:07 UTC 2021
commit 0f92dccf3d557addb1e34ceb1bac9a69cf6a6dca
Author: Guillaume Quintard <guillaume at varnish-software.com>
Date: Wed Sep 4 11:02:12 2019 +0900
Offer a configure --with-unwind switch
Conflicts:
.travis.yml
bin/varnishd/cache/cache_panic.c
diff --git a/.travis.yml b/.travis.yml
index 8d31d9e04..02f080c04 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -40,7 +40,7 @@ before_install:
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
export PATH="/usr/local/opt/sphinx-doc/bin:$PATH"
elif [[ -n "$SAN_FLAGS" ]]; then
- export CONFIGURE_ARGS="--enable-developer-warnings --enable-debugging-symbols --disable-stack-protector --with-persistent-storage ${SAN_FLAGS}"
+ export CONFIGURE_ARGS="--enable-developer-warnings --enable-debugging-symbols --disable-stack-protector --with-persistent-storage --with-unwind ${SAN_FLAGS}"
export ASAN_OPTIONS=abort_on_error=1,detect_odr_violation=1,detect_leaks=1,detect_stack_use_after_return=1,detect_invalid_pointer_pairs=1,handle_segv=0,handle_sigbus=0,use_sigaltstack=0,disable_coredump=0
export LSAN_OPTIONS=abort_on_error=1,use_sigaltstack=0,suppressions=$(pwd)/tools/lsan.suppr
export TSAN_OPTIONS=abort_on_error=1,halt_on_error=1,use_sigaltstack=0,suppressions=$(pwd)/tools/tsan.suppr
diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
index e6e0537e4..bd7bce594 100644
--- a/bin/varnishd/Makefile.am
+++ b/bin/varnishd/Makefile.am
@@ -173,6 +173,11 @@ varnishd_LDADD = \
@PCRE_LIBS@ \
${DL_LIBS} ${PTHREAD_LIBS} ${NET_LIBS} ${RT_LIBS} ${LIBM}
+if WITH_UNWIND
+varnishd_CFLAGS += -DUNW_LOCAL_ONLY
+varnishd_LDADD += ${LIBUNWIND_LIBS}
+endif
+
noinst_PROGRAMS = vhp_gen_hufdec
vhp_gen_hufdec_SOURCES = hpack/vhp_gen_hufdec.c
vhp_gen_hufdec_CFLAGS = @SAN_CFLAGS@ \
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index ef6234374..3a37ea65b 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -29,7 +29,11 @@
#include "config.h"
+#ifdef WITH_UNWIND
+#include <libunwind.h>
+#else
#include <execinfo.h>
+#endif
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -575,6 +579,47 @@ pan_sess(struct vsb *vsb, const struct sess *sp)
/*--------------------------------------------------------------------*/
+#ifdef WITH_UNWIND
+
+static void
+pan_backtrace(struct vsb *vsb)
+{
+ unw_cursor_t cursor; unw_context_t uc;
+ unw_word_t ip, sp;
+ unw_word_t offp;
+ char fname[1024];
+ int ret;
+
+ VSB_printf(vsb, "Backtrace:\n");
+ VSB_indent(vsb, 2);
+
+ ret = unw_getcontext(&uc);
+ if (ret != 0) {
+ VSB_printf(vsb, "Backtrace not available "
+ "(unw_getcontext returned %d)\n", ret);
+ return;
+ }
+ unw_init_local(&cursor, &uc);
+ if (ret != 0) {
+ VSB_printf(vsb, "Backtrace not available "
+ "(unw_init_local returned %d)\n", ret);
+ return;
+ }
+ while (unw_step(&cursor) > 0) {
+ fname[0] = '\0';
+ ip = sp = 0;
+ unw_get_reg(&cursor, UNW_REG_IP, &ip);
+ unw_get_reg(&cursor, UNW_REG_SP, &sp);
+ unw_get_proc_name(&cursor, fname, sizeof(fname), &offp);
+ VSB_printf(vsb, "ip=0x%lx, sp=0x%lx <%s+0x%lx>\n", (long) ip,
+ (long) sp, fname[0] ? fname : "???", offp);
+ }
+
+ VSB_indent(vsb, -2);
+}
+
+#else /* WITH_UNWIND */
+
#define BACKTRACE_LEVELS 10
static void
@@ -616,6 +661,8 @@ pan_backtrace(struct vsb *vsb)
VSB_indent(vsb, -2);
}
+#endif /* WITH_UNWIND */
+
/*--------------------------------------------------------------------*/
static void __attribute__((__noreturn__))
diff --git a/configure.ac b/configure.ac
index bbcbad126..4d4618ec4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -336,9 +336,25 @@ esac
AC_SUBST(JEMALLOC_LDADD)
AC_CHECK_FUNCS([setproctitle])
-AC_SEARCH_LIBS(backtrace, [execinfo], [], [
- AC_MSG_ERROR([Could not find backtrace() support])
-])
+
+# if the default libexecinfo on alpine causes issues, you can use libunwind
+AC_ARG_WITH([unwind],
+ [AS_HELP_STRING([--with-unwind],
+ [use libunwind to print stacktraces (use libexecinfo otherwise). Recommended on alpine linux. Defaults to no.])])
+
+if test "$with_unwind" = yes; then
+ PKG_CHECK_MODULES([LIBUNWIND], [libunwind])
+ AC_DEFINE([WITH_UNWIND], [1],
+ [Define to 1 to use libunwind instead of libexecinfo])
+else
+ AC_SEARCH_LIBS(backtrace, [execinfo], [], [
+ AC_MSG_ERROR([Could not find backtrace() support])
+ ])
+fi
+
+AM_CONDITIONAL([WITH_UNWIND],
+ [test "$with_unwind" = yes])
+
# white lie - we don't actually test it
AC_MSG_CHECKING([whether daemon() works])
case $target in
More information about the varnish-commit
mailing list