havelib: Avoid linking with libc.a on GNU systems.
authorBruno Haible <bruno@clisp.org>
Sat, 19 Sep 2020 23:40:36 +0000 (01:40 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 19 Sep 2020 23:40:36 +0000 (01:40 +0200)
Reported by Bruce Dubbs <bruce.dubbs@gmail.com> in
<https://lists.gnu.org/archive/html/grep-devel/2020-09/msg00052.html>.

* m4/lib-link.m4 (AC_LIB_LINKFLAGS_BODY): When processing the
dependency_libs value of a .la file, ignore '-lc' options on GNU
systems.

ChangeLog
m4/lib-link.m4

index ebaa5fb2af632762d923abdce2aafc6f01dcde86..f094e97f15fd19ac623348833512918633fa961e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2020-09-19  Bruno Haible  <bruno@clisp.org>
+
+       havelib: Avoid linking with libc.a on GNU systems.
+       Reported by Bruce Dubbs <bruce.dubbs@gmail.com> in
+       <https://lists.gnu.org/archive/html/grep-devel/2020-09/msg00052.html>.
+       * m4/lib-link.m4 (AC_LIB_LINKFLAGS_BODY): When processing the
+       dependency_libs value of a .la file, ignore '-lc' options on GNU
+       systems.
+
 2020-09-19  Bruno Haible  <bruno@clisp.org>
 
        Fix recognition of musl libc on Alpine Linux 3.10.
index eecf70ec7647b4a4a58758beb0cbb34eaae340f6..5ce1aa24aed623e5868a3b1f7166bddff74e01d2 100644 (file)
@@ -1,4 +1,4 @@
-# lib-link.m4 serial 31
+# lib-link.m4 serial 32
 dnl Copyright (C) 2001-2020 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -631,7 +631,20 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
                     ;;
                   -l*)
                     dnl Handle this in the next round.
-                    names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'`
+                    dnl But on GNU systems, ignore -lc options, because
+                    dnl   - linking with libc is the default anyway,
+                    dnl   - linking with libc.a may produce an error
+                    dnl     "/usr/bin/ld: dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in `/usr/lib/libc.a(strcmp.o)' can not be used when making an executable; recompile with -fPIE and relink with -pie"
+                    dnl     or may produce an executable that always crashes, see
+                    dnl     <https://lists.gnu.org/archive/html/grep-devel/2020-09/msg00052.html>.
+                    dep=`echo "X$dep" | sed -e 's/^X-l//'`
+                    if test "X$dep" != Xc \
+                       || case $host_os in
+                            linux* | gnu* | k*bsd*-gnu) false ;;
+                            *)                          true ;;
+                          esac; then
+                      names_next_round="$names_next_round $dep"
+                    fi
                     ;;
                   *.la)
                     dnl Handle this in the next round. Throw away the .la's