From cdb2fd37a703aae73fea981eb2578064871d5e21 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 4 Sep 2014 14:55:12 -0700 Subject: [PATCH] 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. 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 | 13 +++++++++++++ m4/pthread.m4 | 4 ++-- m4/pthread_sigmask.m4 | 7 ++++--- m4/threadlib.m4 | 38 ++++++++++++++++++++++++++++---------- 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index dc88544..a758d6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2014-09-04 Paul Eggert + + 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 error: drop spurious semicolon diff --git a/m4/pthread.m4 b/m4/pthread.m4 index 1ed0dd3..524ac25 100644 --- a/m4/pthread.m4 +++ b/m4/pthread.m4 @@ -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( diff --git a/m4/pthread_sigmask.m4 b/m4/pthread_sigmask.m4 index 2b3347f..5153828 100644 --- a/m4/pthread_sigmask.m4 +++ b/m4/pthread_sigmask.m4 @@ -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], diff --git a/m4/threadlib.m4 b/m4/threadlib.m4 index a881702..dc9a3d8 100644 --- a/m4/threadlib.m4 +++ b/m4/threadlib.m4 @@ -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_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_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 -- 1.9.3