While the gnulib CI is "green", building a testdir on older BSD platforms leads to compilation errors.
For example, on OpenBSD 6.0, most compilation units fail to compile with these errors: gcc -std=gnu99 -DHAVE_CONFIG_H -DEXEEXT=\"\" -DEXEEXT=\"\" -DNO_XMALLOC -DEXEEXT=\"\" -I. -I../../gllib -I.. -DGNULIB_STRICT_CHECKING=1 -I/home/bruno/include -Wall -fvisibility=hidden -g -O2 -MT argmatch.o -MD -MP -MF $depbase.Tpo -c -o argmatch.o ../../gllib/argmatch.c &&\ mv -f $depbase.Tpo $depbase.Po In file included from ./sys/select.h:102, from /usr/include/sys/types.h:230, from ./sys/types.h:46, from /usr/include/stdio.h:45, from ./stdio.h:55, from ../../gllib/argmatch.h:32, from ../../gllib/argmatch.c:25: ./sys/time.h:651: error: conflicting types for 'gettimeofday' /usr/include/sys/time.h:344: error: previous declaration of 'gettimeofday' was here In file included from ./sys/select.h:131, from /usr/include/sys/types.h:230, from ./sys/types.h:46, from /usr/include/stdio.h:45, from ./stdio.h:55, from ../../gllib/argmatch.h:32, from ../../gllib/argmatch.c:25: ./signal.h:797: error: size of array 'verify_NSIG_constraint' is negative ./signal.h:1025: error: redefinition of 'struct sigaction' gmake[4]: *** [Makefile:11884: argmatch.o] Error 1 The cause is that at configure time, all "checking for <function>" tests fail with /usr/bin/ld: cannot find -lexecinfo This patch fixes it. 2024-12-28 Bruno Haible <br...@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. 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