emacs-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[debbugs-tracker] bug#20136: closed (25.0.50; [PATCH] Fix broken libpthr


From: GNU bug Tracking System
Subject: [debbugs-tracker] bug#20136: closed (25.0.50; [PATCH] Fix broken libpthread detection)
Date: Thu, 19 Mar 2015 21:38:01 +0000

Your message dated Thu, 19 Mar 2015 14:37:32 -0700
with message-id <address@hidden>
and subject line 25.0.50; [PATCH] Fix broken libpthread detection
has caused the debbugs.gnu.org bug report #20136,
regarding 25.0.50; [PATCH] Fix broken libpthread detection
to be marked as done.

(If you believe you have received this mail in error, please contact
address@hidden)


-- 
20136: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=20136
GNU Bug Tracking System
Contact address@hidden with problems
--- Begin Message --- Subject: 25.0.50; [PATCH] Fix broken libpthread detection Date: Wed, 18 Mar 2015 16:42:04 +0100 User-agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (berkeley-unix)
On FreeBSD, configure emacs (trunk) with, say,

./configure --without-all --with-x --with-x-toolkit=no

and look at what configure thinks about pthread support:

checking for library containing pthread_atfork... none required
[...]
checking whether pthread_sigmask works without -lpthread... no
checking whether pthread_sigmask returns error numbers... yes
checking whether pthread_sigmask unblocks signals correctly... no

The correct results are `-lpthread' instead of `none required' (that is,
if the test were pertinent at all, see below) and `yes' instead of the
last `no'.  The bug is due to 93ca4887 and is not present in emacs-24.

The reason is that while pthread_atfork and some other pthread_ stubs
are indeed present in libc, -lpthread or something equivalent is still
needed for correct behaviour.

The issue is not peculiar to FreeBSD, as GNU libc also contains some
pthread_ symbols, but not those that configure tests, so things happen
to work there.  Allegedly, older versions of Solaris libc contain stubs
for (almost) all pthread_ functions whereas in newer versions those are
not stubs but the real stuff...

Next, the pthread_ functions can really be macros (at least in theory).

Finally, it would be nice (I imagine) to use -pthread instead
of -lpthread if possible.

So I wonder if it wouldn't be better to use the ax_pthread.m4 module
from the autoconf archive, which tackles those problems, see

https://www.gnu.org/software/autoconf-archive/ax_pthread.html

It contains some historical cruft, like tests for linuxthreads or
FreeBSD kthreads, but that could easily be trimmed.

Also, guile uses this module, so I guess that copyright assignment to
the FSF either has already been dealt with or is not an issue here.

In any case, I've written the necessary glue to integrate it into
configure.ac (to test it, you have also to download the latest version
of the module from the link above, put it in m4/ and run ./autogen.sh
after the new file and the patch below are in place):

The subtle art of writing tests which can be compiled and linked but
would break at run time is new to me, though (but ax_pthread.m4 does
this, so why not imitate it).

-- >8 --
Subject: [PATCH] configure.ac: Integrate m4/ax_pthread.m4.

---
 configure.ac | 59 ++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 32 insertions(+), 27 deletions(-)

diff --git a/configure.ac b/configure.ac
index 85e04e9..6ce0c6a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2182,33 +2182,38 @@ LIB_PTHREAD=
 if test "$opsys" != "mingw32"; then
 AC_CHECK_HEADERS_ONCE(pthread.h)
 if test "$ac_cv_header_pthread_h"; then
-  dnl gmalloc.c uses pthread_atfork, which is not available on older-style
-  dnl hosts such as MirBSD 10, so test for pthread_atfork instead of merely
-  dnl testing for pthread_kill if Emacs uses gmalloc.c.
-  if test "$GMALLOC_OBJ" = gmalloc.o; then
-    emacs_pthread_function=pthread_atfork
-  else
-    emacs_pthread_function=pthread_kill
-  fi
-  OLD_LIBS=$LIBS
-  AC_SEARCH_LIBS([$emacs_pthread_function], [pthread],
-    [AC_DEFINE([HAVE_PTHREAD], [1],
-       [Define to 1 if you have pthread (-lpthread).])
-     # Some systems optimize for single-threaded programs by default, and
-     # need special flags to disable these optimizations. For example, the
-     # definition of 'errno' in <errno.h>.
-     case $opsys in
-       sol*)
-         AC_DEFINE([_REENTRANT], 1,
-       [Define to 1 if your system requires this in multithreaded code.]);;
-       aix4-2)
-         AC_DEFINE([_THREAD_SAFE], 1,
-       [Define to 1 if your system requires this in multithreaded code.]);;
-     esac])
- if test "X$LIBS" != "X$OLD_LIBS"; then
-    eval LIB_PTHREAD=\$ac_cv_search_$emacs_pthread_function
-  fi
-  LIBS=$OLD_LIBS
+  OLD_CC="$CC"
+  OLD_CFLAGS="$CFLAGS"
+  OLD_LDFLAGS="$LDFLAGS"
+  OLD_LIBS="$LIBS"
+  ACX_PTHREAD([CC="$PTHREAD_CC"
+    CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
+    dnl XXX Might not always work?
+    LDFLAGS="$PTHREAD_CFLAGS $LDFLAGS"
+    LIBS="$PTHREAD_LIBS $LIBS"
+    dnl gmalloc.c uses pthread_atfork, which is not available on older-style
+    dnl hosts such as MirBSD 10, so test for pthread_atfork instead of merely
+    dnl testing for pthread_kill if Emacs uses gmalloc.c.
+    if test "$GMALLOC_OBJ" = gmalloc.o; then
+      emacs_pthread_function=pthread_atfork
+      emacs_pthread_args="NULL, NULL, NULL"
+    else
+      emacs_pthread_function=pthread_kill
+      emacs_pthread_args="tid, 0"
+    fi
+    AC_MSG_CHECKING([for $emacs_pthread_function])
+    AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>
+pthread_t tid;]],
+      [[pthread_create (&tid, NULL, NULL, NULL);
+$emacs_pthread_function ($emacs_pthread_args)]])],
+      [AC_MSG_RESULT([yes])
+       AC_DEFINE([HAVE_PTHREAD], [1], [Define to 1 if you have pthread.])
+       LIB_PTHREAD="$PTHREAD_LIBS"],
+      [AC_MSG_RESULT([no])
+       CC="$OLD_CC"
+       CFLAGS="$OLD_CFLAGS"
+       LDFLAGS="$OLD_LDFLAGS"])
+    LIBS="$OLD_LIBS"])
 fi
 AC_SUBST([LIB_PTHREAD])
 fi
-- 
2.3.3




--- End Message ---
--- Begin Message --- Subject: 25.0.50; [PATCH] Fix broken libpthread detection Date: Thu, 19 Mar 2015 14:37:32 -0700 User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 Thanks for the bug report and suggestion. However, it's probably better to keep Emacs's pthread configuration simple. We're already bypassing both of Gnulib's pthread configuration strategies, so it's not too much of a stretch to also bypass the strategy in the Autoconf archive. All these strategies are hacky and are showing signs of age (Sequent! wow! it's been a while) and I'm sort of hoping that FreeBSD will change its default to be pthread-friendly instead of pthread-hostile so that Emacs and other apps can stop worrying about this gorp. So I installed the attached patch instead, which I tested on Fedora 21 x86-64 and on FreeBSD 9.1 x86-64.

it would be nice (I imagine) to use -pthread instead
of -lpthread if possible.


What does -pthread do that the current approach doesn't?

More generally, if we're worried only about Emacs's runtime behavior, is there anything wrong with compiling with the equivalent of -D_THREAD_SAFE -lpthread?

Attachment: 0001-Better-port-of-pthread-usage-to-FreeBSD.patch
Description: Text Data


--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]