]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
stack-trace: Fix compilation errors on older BSD systems.
authorBruno Haible <bruno@clisp.org>
Sat, 28 Dec 2024 12:03:52 +0000 (13:03 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 28 Dec 2024 12:03:52 +0000 (13:03 +0100)
* m4/stack-trace.m4 (gl_STACK_TRACE_EARLY): Test whether we can link
with libexecinfo before modifying LIBS.

ChangeLog
m4/stack-trace.m4

index 8a6b6903edf62ac4f6bfb8c919499f5d9b5372f9..73ccd9ed501a4b87577ed601f98d15be14db6bc9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-12-28  Bruno Haible  <bruno@clisp.org>
+
+       stack-trace: Fix compilation errors on older BSD systems.
+       * m4/stack-trace.m4 (gl_STACK_TRACE_EARLY): Test whether we can link
+       with libexecinfo before modifying LIBS.
+
 2024-12-28  Bruno Haible  <bruno@clisp.org>
 
        Rename module stdbool-h to bool.
index 2267fcbb812adfeb1d306f36643ad829d464b43b..39106683fd17fcdf19b85dabe5fb14ec520975cf 100644 (file)
@@ -1,5 +1,5 @@
 # stack-trace.m4
-# serial 3
+# serial 4
 dnl Copyright (C) 2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -57,19 +57,27 @@ AC_DEFUN([gl_STACK_TRACE_EARLY],
         *-gnu* | gnu* | darwin* | freebsd* | dragonfly* | netbsd* | openbsd* | solaris*)
           dnl execinfo might be implemented on this platform.
           CAN_PRINT_STACK_TRACE=1
-          dnl On *BSD system, link all programs with -lexecinfo. Cf. m4/execinfo.m4.
+          dnl On *BSD system, link all programs with -lexecinfo, provided that
+          dnl libexecinfo actually exists. Cf. m4/execinfo.m4.
           case "$host_os" in
             freebsd* | dragonfly* | netbsd* | openbsd*)
-              LIBS="$LIBS -lexecinfo"
-              ;;
-          esac
-          dnl Link all programs in such a way that the stack trace includes the
-          dnl function names. '-rdynamic' is equivalent to '-Wl,-export-dynamic'.
-          case "$host_os" in
-            *-gnu* | gnu* | openbsd*)
-              LDFLAGS="$LDFLAGS -rdynamic"
+              AC_SEARCH_LIBS([backtrace_symbols_fd], [execinfo],
+                [], [CAN_PRINT_STACK_TRACE=0])
+              if test $CAN_PRINT_STACK_TRACE = 1; then
+                LIBS="$LIBS -lexecinfo"
+              fi
               ;;
           esac
+          if test $CAN_PRINT_STACK_TRACE = 1; then
+            dnl Link all programs in such a way that the stack trace includes
+            dnl the function names.
+            dnl '-rdynamic' is equivalent to '-Wl,-export-dynamic'.
+            case "$host_os" in
+              *-gnu* | gnu* | openbsd*)
+                LDFLAGS="$LDFLAGS -rdynamic"
+                ;;
+            esac
+          fi
           ;;
       esac
     fi