Mercurial > hg > octave-jordi > gnulib-hg
changeset 17751:9e8d98ca3311
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.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Thu, 04 Sep 2014 14:55:12 -0700 |
parents | 7355c636029c |
children | 89ba0beadf6a |
files | ChangeLog m4/pthread.m4 m4/pthread_sigmask.m4 m4/threadlib.m4 |
diffstat | 4 files changed, 47 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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 @@ [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(
--- 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 @@ 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_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 @@ dnl no effect. if test -z "$LIB_PTHREAD_SIGMASK"; then case " $LIBS " in + *' -pthread '*) ;; *' -lpthread '*) ;; *) AC_CACHE_CHECK([whether pthread_sigmask works without -lpthread],
--- 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 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 @@ # 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 @@ [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 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