From: Andreas Henriksson <andr...@fatal.se>

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 8deb53a..ba88871 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 f7732a6..b9e1bbf 100644
--- a/src/backtrace.c
+++ b/src/backtrace.c
@@ -27,7 +27,7 @@
 #define _GNU_SOURCE
 #include <features.h>
 
-#ifdef HAVE_EXECINFO_H
+#ifdef HAVE_BACKTRACE
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
diff --git a/src/backtrace.h b/src/backtrace.h
index 829ba02..51d4efe 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 8035fa0..e0ccbef 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
 
-- 
2.19.2

Reply via email to