From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Wolfgang Jenkner Newsgroups: gmane.emacs.bugs Subject: bug#20136: 25.0.50; [PATCH] Fix broken libpthread detection Date: Wed, 18 Mar 2015 16:42:04 +0100 Message-ID: <85wq2e8epr.fsf@iznogoud.viz> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1426695387 3746 80.91.229.3 (18 Mar 2015 16:16:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 18 Mar 2015 16:16:27 +0000 (UTC) Cc: Paul Eggert To: 20136@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Mar 18 17:16:14 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YYGdh-0001fh-Aj for geb-bug-gnu-emacs@m.gmane.org; Wed, 18 Mar 2015 17:16:13 +0100 Original-Received: from localhost ([::1]:34687 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYGdg-0001Bh-IL for geb-bug-gnu-emacs@m.gmane.org; Wed, 18 Mar 2015 12:16:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54239) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYGdb-0001BP-NF for bug-gnu-emacs@gnu.org; Wed, 18 Mar 2015 12:16:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YYGdX-0005qn-6V for bug-gnu-emacs@gnu.org; Wed, 18 Mar 2015 12:16:07 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:53242) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYGdX-0005qj-3I for bug-gnu-emacs@gnu.org; Wed, 18 Mar 2015 12:16:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YYGdV-0004Oc-Rw; Wed, 18 Mar 2015 12:16:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Wolfgang Jenkner Original-Sender: "Debbugs-submit" Resent-CC: eggert@cs.ucla.edu, bug-gnu-emacs@gnu.org Resent-Date: Wed, 18 Mar 2015 16:16:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 20136 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: Paul Eggert Original-Received: via spool by submit@debbugs.gnu.org id=B.142669531916842 (code B ref -1); Wed, 18 Mar 2015 16:16:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 18 Mar 2015 16:15:19 +0000 Original-Received: from localhost ([127.0.0.1]:51808 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YYGcn-0004NZ-PO for submit@debbugs.gnu.org; Wed, 18 Mar 2015 12:15:18 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:52423) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YYGcm-0004NR-59 for submit@debbugs.gnu.org; Wed, 18 Mar 2015 12:15:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YYGch-0005Si-Kr for submit@debbugs.gnu.org; Wed, 18 Mar 2015 12:15:15 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:37474) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYGch-0005SY-IJ for submit@debbugs.gnu.org; Wed, 18 Mar 2015 12:15:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYGcb-000132-Sp for bug-gnu-emacs@gnu.org; Wed, 18 Mar 2015 12:15:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YYGcX-00056r-QX for bug-gnu-emacs@gnu.org; Wed, 18 Mar 2015 12:15:05 -0400 Original-Received: from b2bfep12.mx.upcmail.net ([62.179.121.57]:43943) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYGcX-00052I-8I for bug-gnu-emacs@gnu.org; Wed, 18 Mar 2015 12:15:01 -0400 Original-Received: from edge12.upcmail.net ([192.168.13.82]) by b2bfep12.mx.upcmail.net (InterMail vM.8.01.05.11 201-2260-151-128-20120928) with ESMTP id <20150318161457.DLJS14748.b2bfep12-int.chello.at@edge12.upcmail.net> for ; Wed, 18 Mar 2015 17:14:57 +0100 Original-Received: from iznogoud.viz ([91.119.220.43]) by edge12.upcmail.net with edge id 54Ex1q0030wmnzP0C4ExsT; Wed, 18 Mar 2015 17:14:57 +0100 X-SourceIP: 91.119.220.43 Original-Received: from wolfgang by iznogoud.viz with local (Exim 4.85 (FreeBSD)) (envelope-from ) id 1YYGcS-0003WM-PL for bug-gnu-emacs@gnu.org; Wed, 18 Mar 2015 17:14:56 +0100 User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (berkeley-unix) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:100618 Archived-At: 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 . - 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_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