From b6910e12108282577ae27e1ed496e5ead1fa7cec Mon Sep 17 00:00:00 2001 From: Andreas Henriksson Date: Sat, 24 Nov 2018 03:27:04 +0100 Subject: [PATCH] build: only enable backtrace(3) in maintainer mode Using backtrace() is of no use when building with PIE (which most distro compilers do by default) and prevents catching the coredump for later retracing, which is needed since distros usually don't install debug symbols by default either. This patch thus only enables backtrace() when --enable-maintainer-mode is passed and also tries to explicitly disable PIE. --- configure.ac | 12 ++++++++++-- src/backtrace.c | 2 +- src/backtrace.h | 2 +- src/main.c | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 8deb53aa..1aeb149a 100644 --- a/configure.ac +++ b/configure.ac @@ -80,8 +80,16 @@ AC_DEFINE_UNQUOTED(WIRED_STORAGEDIR, "${wired_storagedir}", AC_CHECK_HEADERS(linux/types.h linux/if_alg.h) -AC_CHECK_HEADERS_ONCE(execinfo.h) -AC_CHECK_LIB(execinfo, backtrace) +# In maintainer mode: try to build with application backtrace and disable PIE. +if (test "${USE_MAINTAINER_MODE}" = yes); then + AC_SEARCH_LIBS([backtrace], [execinfo], + [ + AC_DEFINE([HAVE_BACKTRACE], [1], + [Define to 1 if you have backtrace(3).]) + CFLAGS="$CFLAGS -fno-PIE" + LDFLAGS="$LDFLAGS -no-pie" + ]) +fi AC_ARG_ENABLE([daemon], AC_HELP_STRING([--disable-daemon], [don't install iwd system daemon]), diff --git a/src/backtrace.c b/src/backtrace.c index f7732a63..b9e1bbfa 100644 --- a/src/backtrace.c +++ b/src/backtrace.c @@ -27,7 +27,7 @@ #define _GNU_SOURCE #include -#ifdef HAVE_EXECINFO_H +#ifdef HAVE_BACKTRACE #include #include #include diff --git a/src/backtrace.h b/src/backtrace.h index 829ba020..51d4efe3 100644 --- a/src/backtrace.h +++ b/src/backtrace.h @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ -#ifdef HAVE_EXECINFO_H +#ifdef HAVE_BACKTRACE void __iwd_backtrace_init(); void __iwd_backtrace_print(unsigned int offset); #endif diff --git a/src/main.c b/src/main.c index 8035fa06..e0ccbef2 100644 --- a/src/main.c +++ b/src/main.c @@ -445,7 +445,7 @@ int main(int argc, char *argv[]) if (debugopt) l_debug_enable(debugopt); -#ifdef HAVE_EXECINFO_H +#ifdef HAVE_BACKTRACE __iwd_backtrace_init(); #endif