From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#20136: 25.0.50; [PATCH] Fix broken libpthread detection Date: Thu, 19 Mar 2015 14:37:32 -0700 Organization: UCLA Computer Science Department Message-ID: <550B419C.50108@cs.ucla.edu> References: <85wq2e8epr.fsf@iznogoud.viz> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------070303040300020806010808" X-Trace: ger.gmane.org 1426801104 29308 80.91.229.3 (19 Mar 2015 21:38:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 19 Mar 2015 21:38:24 +0000 (UTC) Cc: 20136-done@debbugs.gnu.org To: Wolfgang Jenkner Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Mar 19 22:38: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 1YYi8r-0005nY-Es for geb-bug-gnu-emacs@m.gmane.org; Thu, 19 Mar 2015 22:38:13 +0100 Original-Received: from localhost ([::1]:41364 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYi8q-0006gQ-QH for geb-bug-gnu-emacs@m.gmane.org; Thu, 19 Mar 2015 17:38:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56302) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYi8l-0006fk-Jh for bug-gnu-emacs@gnu.org; Thu, 19 Mar 2015 17:38:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YYi8g-0005a8-Fa for bug-gnu-emacs@gnu.org; Thu, 19 Mar 2015 17:38:07 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:40584) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYi8g-0005a1-As for bug-gnu-emacs@gnu.org; Thu, 19 Mar 2015 17:38:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YYi8g-0005sZ-37 for bug-gnu-emacs@gnu.org; Thu, 19 Mar 2015 17:38:02 -0400 In-Reply-To: <85wq2e8epr.fsf@iznogoud.viz> Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Thu, 19 Mar 2015 21:38:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 20136 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Mail-Followup-To: 20136@debbugs.gnu.org, eggert@cs.ucla.edu, wjenkner@inode.at Original-Received: via spool by 20136-done@debbugs.gnu.org id=D20136.142680106622573 (code D ref 20136); Thu, 19 Mar 2015 21:38:01 +0000 Original-Received: (at 20136-done) by debbugs.gnu.org; 19 Mar 2015 21:37:46 +0000 Original-Received: from localhost ([127.0.0.1]:58591 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YYi8P-0005s0-GC for submit@debbugs.gnu.org; Thu, 19 Mar 2015 17:37:46 -0400 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:47341) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YYi8N-0005rm-1W for 20136-done@debbugs.gnu.org; Thu, 19 Mar 2015 17:37:44 -0400 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id D52B5A60015; Thu, 19 Mar 2015 14:37:36 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CO2sZ9P9Q6ri; Thu, 19 Mar 2015 14:37:33 -0700 (PDT) Original-Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id D87EDA6000F; Thu, 19 Mar 2015 14:37:33 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 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:100671 Archived-At: This is a multi-part message in MIME format. --------------070303040300020806010808 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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? --------------070303040300020806010808 Content-Type: text/x-patch; name="0001-Better-port-of-pthread-usage-to-FreeBSD.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Better-port-of-pthread-usage-to-FreeBSD.patch" >From 2e32ff90a6af9695d812700e9347f15b50d829e5 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 19 Mar 2015 14:14:07 -0700 Subject: [PATCH] Better port of pthread usage to FreeBSD * configure.ac (ac_func_list): Omit pthread_sigmask, since we check for that ourselves rather than relying on gnulib. (HAVE_PTHREAD, LIB_PTHREAD, _THREAD_SAFE): Port better to FreeBSD, by also checking for pthread_create, pthread_self, pthread_sigmask. Tighten the test for pthread_atfork while we're at it. Fixes: bug#20136 --- ChangeLog | 8 ++++++ configure.ac | 87 ++++++++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 66 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9d7ba93..d268ba0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2015-03-19 Paul Eggert + Better port of pthread usage to FreeBSD + * configure.ac (ac_func_list): Omit pthread_sigmask, since + we check for that ourselves rather than relying on gnulib. + (HAVE_PTHREAD, LIB_PTHREAD, _THREAD_SAFE): Port better to FreeBSD, + by also checking for pthread_create, pthread_self, pthread_sigmask. + Tighten the test for pthread_atfork while we're at it. + Fixes: bug#20136 + Merge from gnulib This incorporates: 2015-03-19 fdopendir: port better to MinGW diff --git a/configure.ac b/configure.ac index d65494a..520816b1 100644 --- a/configure.ac +++ b/configure.ac @@ -780,6 +780,12 @@ AC_DEFUN([gl_CRYPTO_CHECK]) # Avoid gnulib's tests for HAVE_WORKING_O_NOATIME and HAVE_WORKING_O_NOFOLLOW, # as we don't use them. AC_DEFUN([gl_FCNTL_O_FLAGS]) +# Avoid gnulib's test for pthread_sigmask. +funcs= +for func in $ac_func_list; do + test $func = pthread_sigmask || AS_VAR_APPEND([funcs], [" $func"]) +done +ac_func_list=$funcs # Use the system putenv even if it lacks GNU features, as we don't need them, # and the gnulib replacement runs afoul of a FreeBSD 10.1 bug; see Bug#19874. AC_CHECK_FUNCS_ONCE([putenv]) @@ -2179,39 +2185,62 @@ AC_CHECK_LIB(Xbsd, main, LD_SWITCH_X_SITE="$LD_SWITCH_X_SITE -lXbsd") dnl Check for the POSIX thread library. 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 +if test "$ac_cv_header_pthread_h" && test "$opsys" != "mingw32"; then + AC_CACHE_CHECK([for pthread library], + [emacs_cv_pthread_lib], + [emacs_cv_pthread_lib=no + OLD_CPPFLAGS=$CPPFLAGS + OLD_LIBS=$LIBS + for emacs_pthread_lib in 'none needed' -lpthread; do + case $emacs_pthread_lib in + -*) LIBS="$OLD_LIBS $emacs_pthread_lib";; + esac + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#include + #include + sigset_t old_mask, new_mask; + void noop (void) {}]], + [[pthread_t th = pthread_self (); + int status = 0; + status += pthread_create (&th, 0, 0, 0); + status += pthread_sigmask (SIG_BLOCK, &new_mask, &old_mask); + status += pthread_kill (th, 0); + #if ! (defined SYSTEM_MALLOC || defined HYBRID_MALLOC \ + || defined DOUG_LEA_MALLOC) + /* Test for pthread_atfork only if gmalloc uses it, + as older-style hosts like MirBSD 10 lack it. */ + status += pthread_atfork (noop, noop, noop); + #endif + return status;]])], + [emacs_cv_pthread_lib=$emacs_pthread_lib]) + LIBS=$OLD_LIBS + if test "$emacs_cv_pthread_lib" != no; then + break + fi + done + CPPFLAGS=$OLD_CPPFLAGS]) + if test "$emacs_cv_pthread_lib" != no; then + AC_DEFINE([HAVE_PTHREAD], 1, [Define to 1 if you have POSIX threads.]) + case $emacs_cv_pthread_lib in + -*) LIB_PTHREAD=$emacs_cv_pthread_lib;; + esac + ac_cv_func_pthread_sigmask=yes + # 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 + hpux* | sol*) + AC_DEFINE([_REENTRANT], 1, + [Define to 1 if your system requires this in multithreaded code.]);; + aix4-2 | darwin | freebsd) + AC_DEFINE([_THREAD_SAFE], 1, + [Define to 1 if your system requires this in multithreaded code.]);; + esac fi - LIBS=$OLD_LIBS fi AC_SUBST([LIB_PTHREAD]) -fi dnl Check for need for bigtoc support on IBM AIX -- 2.1.0 --------------070303040300020806010808--