From: Bruno Haible Date: Sat, 28 Dec 2024 12:03:52 +0000 (+0100) Subject: stack-trace: Fix compilation errors on older BSD systems. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48ac07ef27c422df0166215680b905fd22e68cec;p=thirdparty%2Fgnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 8a6b6903ed..73ccd9ed50 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2024-12-28 Bruno Haible + + 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 Rename module stdbool-h to bool. diff --git a/m4/stack-trace.m4 b/m4/stack-trace.m4 index 2267fcbb81..39106683fd 100644 --- a/m4/stack-trace.m4 +++ b/m4/stack-trace.m4 @@ -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