]> Savannah Git Hosting - gnulib.git/commitdiff
pthread, pthread_sigmask, threadlib: port to Ubuntu 14.04
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 4 Sep 2014 21:55:12 +0000 (14:55 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 4 Sep 2014 21:57:45 +0000 (14:57 -0700)
Problem reported by Assaf Gordon in:
http://lists.gnu.org/archive/html/bug-gnulib/2014-09/msg00023.html
Apparently Ubuntu is doing some fancy link-time optimization
that doesn't work with -lpthread but does work with -pthread.
Work around the bug by preferring -pthread to -lpthread.
This change affects only LIBS, not CFLAGS, which is a little
weird, but it works.
* m4/pthread.m4 (gl_PTHREAD_CHECK):
* m4/threadlib.m4 (gl_THREADLIB_BODY): Prefer -pthread to -lpthread.
* m4/pthread_sigmask.m4 (gl_FUNC_PTHREAD_SIGMASK):
Treat -pthread like -lpthread.

ChangeLog
m4/pthread.m4
m4/pthread_sigmask.m4
m4/threadlib.m4

index dc88544f06b3b551d8ce3b205eecf19e46193223..a758d6bab97e9fc79e78181cffc9eeab937c20ba 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2014-09-04  Paul Eggert  <eggert@cs.ucla.edu>
+
+       pthread, pthread_sigmask, threadlib: port to Ubuntu 14.04
+       Problem reported by Assaf Gordon in:
+       http://lists.gnu.org/archive/html/bug-gnulib/2014-09/msg00023.html
+       Apparently Ubuntu is doing some fancy link-time optimization
+       that doesn't work with -lpthread but does work with -pthread.
+       Work around the bug by preferring -pthread to -lpthread.
+       * m4/pthread.m4 (gl_PTHREAD_CHECK):
+       * m4/threadlib.m4 (gl_THREADLIB_BODY): Prefer -pthread to -lpthread.
+       * m4/pthread_sigmask.m4 (gl_FUNC_PTHREAD_SIGMASK):
+       Treat -pthread like -lpthread.
+
 2014-09-04  Eric Blake  <eblake@redhat.com>
 
        error: drop spurious semicolon
index 1ed0dd335ed8091f39b412771b7b2bcbbe6c4381..524ac25b9c4449b880edf65b78a61444895a62dc 100644 (file)
@@ -1,4 +1,4 @@
-# pthread.m4 serial 8
+# pthread.m4 serial 9
 dnl Copyright (C) 2009-2014 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -63,7 +63,7 @@ AC_DEFUN([gl_PTHREAD_CHECK],
        [gl_cv_lib_pthread],
        [gl_saved_libs=$LIBS
         gl_cv_lib_pthread=
-        for gl_lib_prefix in '' '-lpthread'; do
+        for gl_lib_prefix in '' '-pthread' '-lpthread'; do
           LIBS="$gl_lib_prefix $gl_saved_libs"
           AC_LINK_IFELSE(
             [AC_LANG_PROGRAM(
index 2b3347f992dc557c4bf2fb254f75bc2136f88145..5153828a969ec6fb1bbd35b0cb6008d16f8808ed 100644 (file)
@@ -1,4 +1,4 @@
-# pthread_sigmask.m4 serial 14
+# pthread_sigmask.m4 serial 15
 dnl Copyright (C) 2011-2014 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -40,7 +40,7 @@ AC_DEFUN([gl_FUNC_PTHREAD_SIGMASK],
              LIBS="$gl_save_LIBS"
             ])
           if test $gl_cv_func_pthread_sigmask_in_LIBMULTITHREAD = yes; then
-            dnl pthread_sigmask is available with -lpthread.
+            dnl pthread_sigmask is available with -pthread or -lpthread.
             LIB_PTHREAD_SIGMASK="$LIBMULTITHREAD"
           else
             dnl pthread_sigmask is not available at all.
@@ -86,7 +86,7 @@ AC_DEFUN([gl_FUNC_PTHREAD_SIGMASK],
   AC_SUBST([LIB_PTHREAD_SIGMASK])
   dnl We don't need a variable LTLIB_PTHREAD_SIGMASK, because when
   dnl "$gl_threads_api" = posix, $LTLIBMULTITHREAD and $LIBMULTITHREAD are the
-  dnl same: either both empty or both "-lpthread".
+  dnl same.
 
   dnl Now test for some bugs in the system function.
   if test $HAVE_PTHREAD_SIGMASK = 1; then
@@ -98,6 +98,7 @@ AC_DEFUN([gl_FUNC_PTHREAD_SIGMASK],
     dnl no effect.
     if test -z "$LIB_PTHREAD_SIGMASK"; then
       case " $LIBS " in
+        *' -pthread '*) ;;
         *' -lpthread '*) ;;
        *)
          AC_CACHE_CHECK([whether pthread_sigmask works without -lpthread],
index a88170261760153ec8609453f9b6ce8fa30340e7..dc9a3d8e8442cac5529422d9c8ef3fe9ee52c415 100644 (file)
@@ -1,4 +1,4 @@
-# threadlib.m4 serial 10 (gettext-0.18.2)
+# threadlib.m4 serial 11 (gettext-0.18.2)
 dnl Copyright (C) 2005-2014 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -22,7 +22,7 @@ dnl libtool).
 dnl Sets the variables LIBMULTITHREAD and LTLIBMULTITHREAD similarly, for
 dnl programs that really need multithread functionality. The difference
 dnl between LIBTHREAD and LIBMULTITHREAD is that on platforms supporting weak
-dnl symbols, typically LIBTHREAD="" whereas LIBMULTITHREAD="-lpthread".
+dnl symbols, typically LIBTHREAD is empty whereas LIBMULTITHREAD is not.
 dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for
 dnl multithread-safe programs.
 
@@ -162,15 +162,31 @@ int main ()
         # Test whether both pthread_mutex_lock and pthread_mutexattr_init exist
         # in libc. IRIX 6.5 has the first one in both libc and libpthread, but
         # the second one only in libpthread, and lock.c needs it.
-        AC_LINK_IFELSE(
-          [AC_LANG_PROGRAM(
-             [[#include <pthread.h>]],
-             [[pthread_mutex_lock((pthread_mutex_t*)0);
-               pthread_mutexattr_init((pthread_mutexattr_t*)0);]])],
-          [gl_have_pthread=yes])
+        #
+        # If -pthread works, prefer it to -lpthread, since Ubuntu 14.04
+        # needs -pthread for some reason.  See:
+        # http://lists.gnu.org/archive/html/bug-gnulib/2014-09/msg00023.html
+        save_LIBS=$LIBS
+        for gl_pthread in '' '-pthread'; do
+          LIBS="$LIBS $gl_pthread"
+          AC_LINK_IFELSE(
+            [AC_LANG_PROGRAM(
+               [[#include <pthread.h>
+                 pthread_mutex_t m;
+                 pthread_mutexattr_t ma;
+               ]],
+               [[pthread_mutex_lock (&m);
+                 pthread_mutexattr_init (&ma);]])],
+            [gl_have_pthread=yes
+             LIBTHREAD=$gl_pthread LTLIBTHREAD=$gl_pthread
+             LIBMULTITHREAD=$gl_pthread LTLIBMULTITHREAD=$gl_pthread])
+          LIBS=$save_LIBS
+          test -n "$gl_have_pthread" && break
+        done
+
         # Test for libpthread by looking for pthread_kill. (Not pthread_self,
         # since it is defined as a macro on OSF/1.)
-        if test -n "$gl_have_pthread"; then
+        if test -n "$gl_have_pthread" && test -z "$LIBTHREAD"; then
           # The program links fine without libpthread. But it may actually
           # need to link with libpthread in order to create multiple threads.
           AC_CHECK_LIB([pthread], [pthread_kill],
@@ -185,7 +201,7 @@ int main ()
                    [Define if the pthread_in_use() detection is hard.])
              esac
             ])
-        else
+        elif test -z "$gl_have_pthread"; then
           # Some library is needed. Try libpthread and libc_r.
           AC_CHECK_LIB([pthread], [pthread_kill],
             [gl_have_pthread=yes
@@ -326,6 +342,8 @@ dnl Linux 2.4/glibc    posix      -lpthread       Y      OK
 dnl
 dnl GNU Hurd/glibc     posix
 dnl
+dnl Ubuntu 14.04       posix      -pthread        Y      OK
+dnl
 dnl FreeBSD 5.3        posix      -lc_r           Y
 dnl                    posix      -lkse ?         Y
 dnl                    posix      -lpthread ?     Y