Fix detection and use of `USE_LIBDW`
authorErik de Castro Lopo <erikd@mega-nerd.com>
Tue, 31 May 2016 20:14:00 +0000 (06:14 +1000)
committerErik de Castro Lopo <erikd@mega-nerd.com>
Tue, 31 May 2016 20:14:00 +0000 (06:14 +1000)
Test Plan: Configure/build with and without --enable-libdw

Reviewers: trofi, hvr, austin, simonmar, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2276

configure.ac
distrib/configure.ac.in
mk/config.mk.in
rts/Libdw.c
rts/Libdw.h
rts/LibdwPool.c
rts/LibdwPool.h
rts/ghc.mk
rts/package.conf.in
rts/posix/Signals.c

index 4adf9c5..15561d0 100644 (file)
@@ -1092,14 +1092,22 @@ AC_DEFINE_UNQUOTED([RTS_LINKER_USE_MMAP], [$RtsLinkerUseMmap],
 
 dnl ** Have libdw?
 dnl --------------------------------------------------------------
-AC_ARG_ENABLE(libdw,
+UseLibdw=NO
+USE_LIBDW=0
+AC_ARG_ENABLE(dwarf-unwind,
     [AC_HELP_STRING([--enable-dwarf-unwind],
         [Enable DWARF unwinding support in the runtime system via elfutils' libdw [default=no]])],
-    [AC_CHECK_LIB(dw, dwfl_attach_state, [HaveLibdw=YES], [HaveLibdw=NO])],
-    [HaveLibdw=NO]
+    [AC_CHECK_LIB(dw, dwfl_attach_state, [UseLibdw=YES], [UseLibdw=NO])],
+    [UseLibdw=NO]
 )
-AC_SUBST(HaveLibdw)
+AC_SUBST(UseLibdw)
+if test $UseLibdw = "YES" ; then
+       USE_LIBDW=1
+fi
+AC_DEFINE_UNQUOTED([USE_LIBDW], [$USE_LIBDW], [Set to 1 to use libdw])
 
+dnl ** Documentation
+dnl --------------------------------------------------------------
 if test -n "$SPHINXBUILD"; then
     BUILD_MAN=YES
     BUILD_SPHINX_HTML=YES
index fdd9fd9..33023a7 100644 (file)
@@ -93,9 +93,9 @@ dnl ** Have libdw?
 dnl --------------------------------------------------------------
 dnl Check for a usable version of libdw/elfutils
 dnl Currently we need 0.158 or newer.
-BinDistNeedsLibdw=@HaveLibdw@
+BinDistNeedsLibdw=@UseLibdw@
 if test "x$BinDistNeedsLibdw" = "xyes" ; then
-    AC_CHECK_LIB(dw, dwfl_attach_state, [HaveLibdw=YES],
+    AC_CHECK_LIB(dw, dwfl_attach_state, [UseLibdw=YES],
         [AC_MSG_ERROR([Binary distribution was built with libdw support but target system doesn't have supported libdw version (needs at least 0.158)])]
     )];
 fi
index 5dbde02..47198b9 100644 (file)
@@ -381,7 +381,7 @@ FFIIncludeDir=@FFIIncludeDir@
 
 # GHC needs arch-specific tweak at least in
 #     rts/Libdw.c:set_initial_registers()
-GhcRtsWithLibdw=$(strip $(if $(filter $(TargetArch_CPP),i386 x86_64),@HaveLibdw@,NO))
+GhcRtsWithLibdw=$(strip $(if $(filter $(TargetArch_CPP),i386 x86_64),@UseLibdw@,NO))
 
 ################################################################################
 #
index e796840..a16ea59 100644 (file)
@@ -10,7 +10,7 @@
 #include "RtsUtils.h"
 #include "Libdw.h"
 
-#ifdef USE_LIBDW
+#if USE_LIBDW
 
 #include <elfutils/libdwfl.h>
 #include <dwarf.h>
index e5fa054..bb3e71b 100644 (file)
@@ -16,7 +16,7 @@
 
 #include "BeginPrivate.h"
 
-#ifdef USE_LIBDW
+#if USE_LIBDW
 
 /* Begin a libdw session. A session is tied to a particular capability */
 LibdwSession *libdwInit(void);
index 2363212..8d065c3 100644 (file)
@@ -10,7 +10,7 @@
 #include "RtsUtils.h"
 #include "LibdwPool.h"
 
-#ifdef USE_LIBDW
+#if USE_LIBDW
 
 #include <unistd.h>
 
index a6b670e..3c4216d 100644 (file)
@@ -14,7 +14,7 @@
 #include "Rts.h"
 #include "Libdw.h"
 
-#ifdef USE_LIBDW
+#if USE_LIBDW
 
 /* Initialize the pool */
 void libdwPoolInit(void);
index 6fdc2cc..49eaab5 100644 (file)
@@ -480,14 +480,6 @@ rts_PACKAGE_CPP_OPTS += '-DFFI_LIB="C$(LIBFFI_NAME)"'
 
 endif
 
-#-----------------------------------------------------------------------------
-# Add support for reading DWARF debugging information, if available
-
-ifeq "$(GhcRtsWithLibdw)" "YES"
-rts_CC_OPTS          += -DUSE_LIBDW
-rts_PACKAGE_CPP_OPTS += -DUSE_LIBDW
-endif
-
 # -----------------------------------------------------------------------------
 # dependencies
 
index 5c6d240..b52a867 100644 (file)
@@ -61,7 +61,7 @@ unresolved symbols. */
                               ,"mingwex"
 # endif
 #endif
-#ifdef USE_LIBDW
+#if USE_LIBDW
                              , "elf"
                              , "dw"             /* for backtraces */
 #endif
index 496ec7b..d73143b 100644 (file)
@@ -536,7 +536,7 @@ shutdown_handler(int sig STG_UNUSED)
 static void
 backtrace_handler(int sig STG_UNUSED)
 {
-#ifdef USE_LIBDW
+#if USE_LIBDW
     LibdwSession *session = libdwInit();
     Backtrace *bt = libdwGetBacktrace(session);
     libdwPrintBacktrace(session, stderr, bt);