public inbox for cygwin-apps@cygwin.com
 help / color / mirror / Atom feed
From: Brian Inglis <Brian.Inglis@SystematicSw.ab.ca>
To: Cygwin Applications <cygwin-apps@cygwin.com>
Subject: gnulib m4/threadlib.m4 bug crashing package tests
Date: Wed, 29 Sep 2021 17:46:20 -0600	[thread overview]
Message-ID: <c8cbe929-9b3b-5e5a-bb38-af1d3b70008b@SystematicSw.ab.ca> (raw)

[-- Attachment #1: Type: text/plain, Size: 1136 bytes --]

There is a gnulib bug in threadlib.m4 from at least serial 29 to serial
31 that incorrectly configures Cygwin support of weak references.

This leads to SIGSEGV stack smashing crashes with no backtrace
@ 0x00000000100000000 or 0x0000000500000000 etc. normally during tests.

Akim Demaille on bug-bison referred the issue to bug-gnulib where
Bruno Haible diagnosed and patched the problem to appear in
m4/threadlib.m4 serial 32:

* m4/threadlib.m4 (gl_WEAK_SYMBOLS): Force a "guessing no" result on Cygwin
https://lists.gnu.org/archive/html/bug-gnulib/2021-09/msg00068.html
[gl_cv_have_weak="guessing no"]

The patch has now been applied to bison, wget, and wget2, and I have
attached my patches for the copies in those packages, in case anyone
else has this issue in their (mainly GNU) packages which may incorporate 
by inclusion recently updated gnulib m4 macros used in autotools builds.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.
[Data in binary units and prefixes, physical quantities in SI.]

[-- Attachment #2: threadlib-m4-31-cygwin-weak-no.patch --]
[-- Type: text/plain, Size: 3276 bytes --]

2021-09-17  Bruno Haible  <bruno@clisp.org>

	threadlib: Avoid crashes in thread-related functions on Cygwin 3.2.0.
	Reported by Brian Inglis via Akim Demaille in
	<https://lists.gnu.org/archive/html/bug-gnulib/2021-09/msg00063.html>.
	* m4/threadlib.m4 (gl_WEAK_SYMBOLS): Force a "guessing no" result on
	Cygwin.

diff -w --git origsrc/m4/threadlib.m4 src/m4/threadlib.m4
index 37b797c18..6b43bbdfa 100644
--- origsrc/m4/threadlib.m4	2021-08-02 23:51:08.000000000 -0600
+++ src/m4/threadlib.m4	2021-09-17 15:17:37.103525500 -0600
@@ -1,4 +1,4 @@
-# threadlib.m4 serial 31
+# threadlib.m4 serial 32
 dnl Copyright (C) 2005-2021 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -84,38 +84,48 @@ AC_DEFUN([gl_WEAK_SYMBOLS],
   AC_REQUIRE([AC_CANONICAL_HOST])
   AC_CACHE_CHECK([whether imported symbols can be declared weak],
     [gl_cv_have_weak],
-    [gl_cv_have_weak=no
-     dnl First, test whether the compiler accepts it syntactically.
-     AC_LINK_IFELSE(
-       [AC_LANG_PROGRAM(
-          [[extern void xyzzy ();
+    [case "$host_os" in
+       cygwin*)
+         dnl On Cygwin 3.2.0 with gcc 10.2, the test below would succeed, but
+         dnl programs that use pthread_in_use() with weak symbol references
+         dnl crash miserably at runtime.
+         gl_cv_have_weak="guessing no"
+         ;;
+       *)
+         gl_cv_have_weak=no
+	 dnl First, test whether the compiler accepts it syntactically.
+	 AC_LINK_IFELSE(
+	   [AC_LANG_PROGRAM(
+	      [[extern void xyzzy ();
 #pragma weak xyzzy]],
-          [[xyzzy();]])],
-       [gl_cv_have_weak=maybe])
-     if test $gl_cv_have_weak = maybe; then
-       dnl Second, test whether it actually works. On Cygwin 1.7.2, with
-       dnl gcc 4.3, symbols declared weak always evaluate to the address 0.
-       AC_RUN_IFELSE(
-         [AC_LANG_SOURCE([[
+	      [[xyzzy();]])],
+	   [gl_cv_have_weak=maybe])
+	 if test $gl_cv_have_weak = maybe; then
+	   dnl Second, test whether it actually works. On Cygwin 1.7.2, with
+	   dnl gcc 4.3, symbols declared weak always evaluate to the address 0.
+	   AC_RUN_IFELSE(
+	     [AC_LANG_SOURCE([[
 #include <stdio.h>
 #pragma weak fputs
 int main ()
 {
   return (fputs == NULL);
 }]])],
-         [gl_cv_have_weak=yes],
-         [gl_cv_have_weak=no],
-         [dnl When cross-compiling, assume that only ELF platforms support
-          dnl weak symbols.
-          AC_EGREP_CPP([Extensible Linking Format],
-            [#ifdef __ELF__
-             Extensible Linking Format
-             #endif
-            ],
-            [gl_cv_have_weak="guessing yes"],
-            [gl_cv_have_weak="guessing no"])
-         ])
-     fi
+	     [gl_cv_have_weak=yes],
+	     [gl_cv_have_weak=no],
+	     [dnl When cross-compiling, assume that only ELF platforms support
+	      dnl weak symbols.
+	      AC_EGREP_CPP([Extensible Linking Format],
+		[#ifdef __ELF__
+		 Extensible Linking Format
+		 #endif
+		],
+		[gl_cv_have_weak="guessing yes"],
+		[gl_cv_have_weak="guessing no"])
+	     ])
+	 fi
+	 ;;
+     esac
      dnl But when linking statically, weak symbols don't work.
      case " $LDFLAGS " in
        *" -static "*) gl_cv_have_weak=no ;;

[-- Attachment #3: threadlib-m4-29-cygwin-weak-no.patch --]
[-- Type: text/plain, Size: 3507 bytes --]

2021-09-17  Bruno Haible  <bruno@clisp.org>

        threadlib: Avoid crashes in thread-related functions on Cygwin 3.2.0.
        Reported by Brian Inglis via Akim Demaille in
        <https://lists.gnu.org/archive/html/bug-gnulib/2021-09/msg00063.html>.
        * m4/threadlib.m4 (gl_WEAK_SYMBOLS): Force a "guessing no" result on
        Cygwin.

2021-09-27  Brian Inglis  <Brian.Inglis@SystematicSW.ab.ca>

        Original patch backported from m4/threadlib.m4 serial 31 to serial 29

diff -w --git origsrc/m4/threadlib.m4 src/m4/threadlib.m4
index 37b797c18..6b43bbdfa 100644
--- origsrc/m4/threadlib.m4	2021-08-02 23:51:08.000000000 -0600
+++ src/m4/threadlib.m4	2021-09-17 15:17:37.103525500 -0600
@@ -1,4 +1,4 @@
-# threadlib.m4 serial 29
+# threadlib.m4 serial 30
 dnl Copyright (C) 2005-2021 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -84,38 +84,48 @@ AC_DEFUN([gl_WEAK_SYMBOLS],
   AC_REQUIRE([AC_CANONICAL_HOST])
   AC_CACHE_CHECK([whether imported symbols can be declared weak],
     [gl_cv_have_weak],
-    [gl_cv_have_weak=no
-     dnl First, test whether the compiler accepts it syntactically.
-     AC_LINK_IFELSE(
-       [AC_LANG_PROGRAM(
-          [[extern void xyzzy ();
+    [case "$host_os" in
+       cygwin*)
+         dnl On Cygwin 3.2.0 with gcc 10.2, the test below would succeed, but
+         dnl programs that use pthread_in_use() with weak symbol references
+         dnl crash miserably at runtime.
+         gl_cv_have_weak="guessing no"
+         ;;
+       *)
+         gl_cv_have_weak=no
+	  dnl First, test whether the compiler accepts it syntactically.
+	  AC_LINK_IFELSE(
+	    [AC_LANG_PROGRAM(
+	       [[extern void xyzzy ();
 #pragma weak xyzzy]],
-          [[xyzzy();]])],
-       [gl_cv_have_weak=maybe])
-     if test $gl_cv_have_weak = maybe; then
-       dnl Second, test whether it actually works. On Cygwin 1.7.2, with
-       dnl gcc 4.3, symbols declared weak always evaluate to the address 0.
-       AC_RUN_IFELSE(
-         [AC_LANG_SOURCE([[
+	       [[xyzzy();]])],
+	    [gl_cv_have_weak=maybe])
+	  if test $gl_cv_have_weak = maybe; then
+	    dnl Second, test whether it actually works. On Cygwin 1.7.2, with
+	    dnl gcc 4.3, symbols declared weak always evaluate to the address 0.
+	    AC_RUN_IFELSE(
+	      [AC_LANG_SOURCE([[
 #include <stdio.h>
 #pragma weak fputs
 int main ()
 {
   return (fputs == NULL);
 }]])],
-         [gl_cv_have_weak=yes],
-         [gl_cv_have_weak=no],
-         [dnl When cross-compiling, assume that only ELF platforms support
-          dnl weak symbols.
-          AC_EGREP_CPP([Extensible Linking Format],
-            [#ifdef __ELF__
-             Extensible Linking Format
-             #endif
-            ],
-            [gl_cv_have_weak="guessing yes"],
-            [gl_cv_have_weak="guessing no"])
-         ])
-     fi
+	         [gl_cv_have_weak=yes],
+	         [gl_cv_have_weak=no],
+	         [dnl When cross-compiling, assume that only ELF platforms support
+	          dnl weak symbols.
+	          AC_EGREP_CPP([Extensible Linking Format],
+		    [#ifdef __ELF__
+		     Extensible Linking Format
+		     #endif
+		    ],
+		    [gl_cv_have_weak="guessing yes"],
+		    [gl_cv_have_weak="guessing no"])
+	    ])
+	  fi
+	  ;;
+     esac
      dnl But when linking statically, weak symbols don't work.
      case " $LDFLAGS " in
        *" -static "*) gl_cv_have_weak=no ;;

             reply	other threads:[~2021-09-29 23:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29 23:46 Brian Inglis [this message]
2021-11-25 16:26 ` Ken Brown
2021-11-25 18:25   ` Yaakov Selkowitz
2021-11-26  4:48     ` Brian Inglis
2021-11-26 13:08     ` Ken Brown
2021-11-26 17:34       ` Brian Inglis
2021-11-26 18:17         ` Ken Brown
2021-11-28 15:42     ` Achim Gratz
2021-11-28 15:56       ` Ken Brown
2021-11-28 16:33         ` Achim Gratz
2021-11-28 18:21           ` Ken Brown
2021-11-29 16:39             ` Achim Gratz
2021-12-08 18:49               ` Achim Gratz
2021-12-09  4:41                 ` Brian Inglis
2021-11-28 16:23       ` Achim Gratz
2021-11-28 18:34         ` Brian Inglis
2021-11-29 17:38           ` Achim Gratz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c8cbe929-9b3b-5e5a-bb38-af1d3b70008b@SystematicSw.ab.ca \
    --to=brian.inglis@systematicsw.ab.ca \
    --cc=cygwin-apps@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).