]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR boehm-gc/34544 (pthread_default_stacksize_np failed.)
authorJohn David Anglin <dave.anglin@nrc-cnrc.gc.ca>
Fri, 11 Feb 2011 03:00:53 +0000 (03:00 +0000)
committerJohn David Anglin <danglin@gcc.gnu.org>
Fri, 11 Feb 2011 03:00:53 +0000 (03:00 +0000)
Backport from mainline:
2011-02-07  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>

* config/pa/pa64-hpux.h (LIB_SPEC): In static links, link against
shared libc if not linking against libpthread.
* config/pa/pa-hpux11.h (LIB_SPEC): Likewise.

2010-08-22  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>

        PR boehm-gc/34544
* gthr-posix.h (__gthread_active_init): Delete.
(__gthread_active_p): Do activity check here.
Don't include errno.h on hppa-hpux.  Update comment.
* gthr-posix95.h (__gthread_active_init): Delete.
(__gthread_active_p): Do activity check here.
Don't include errno.h on hppa-hpux.  Update comment.

From-SVN: r170042

gcc/ChangeLog
gcc/config/pa/pa-hpux11.h
gcc/config/pa/pa64-hpux.h
gcc/gthr-posix.h
gcc/gthr-posix95.h

index c59b37427ff9b9c93a39c02e247438d36f252770..a9de418d518a8b748ebc080b4c5effbf1bd1e887 100644 (file)
@@ -1,3 +1,22 @@
+2011-02-10  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>
+
+       Backport from mainline:
+       2011-02-07  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>
+
+       * config/pa/pa64-hpux.h (LIB_SPEC): In static links, link against
+       shared libc if not linking against libpthread.
+       * config/pa/pa-hpux11.h (LIB_SPEC): Likewise.
+
+       2010-08-22  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>
+
+        PR boehm-gc/34544
+       * gthr-posix.h (__gthread_active_init): Delete.
+       (__gthread_active_p): Do activity check here.
+       Don't include errno.h on hppa-hpux.  Update comment.
+       * gthr-posix95.h (__gthread_active_init): Delete.
+       (__gthread_active_p): Do activity check here.
+       Don't include errno.h on hppa-hpux.  Update comment.
+
 2011-01-31  Nathan Froyd  <froydnj@codesourcery.com>
 
        Backport from mainline:
index 8dd01d2563d6ec4737ec0c3c118ab5edf0bf1cb6..77a899eabd50fdd91c1ec6d602da1cd97cc375b5 100644 (file)
@@ -116,16 +116,17 @@ along with GCC; see the file COPYING3.  If not see
    -z %{mlinker-opt:-O} %{!shared:-u main -u __gcc_plt_call}\
    %{static:-a archive} %{shared:-b}"
 
-/* HP-UX 11 has posix threads.  HP libc contains pthread stubs so that
-   non-threaded applications can be linked with a thread-safe libc
-   without a subsequent loss of performance.  For more details, see
-   <http://docs.hp.com/en/1896/pthreads.html>.  */
+/* HP-UX 11 has posix threads.  HP's shared libc contains pthread stubs
+   so that non-threaded applications can be linked with a thread-safe
+   libc without a subsequent loss of performance.  For more details,
+   see <http://docs.hp.com/en/1896/pthreads.html>.  */
 #undef LIB_SPEC
 #define LIB_SPEC \
   "%{!shared:\
-     %{static|mt|pthread:%{fopenmp:%{static:-a archive_shared} -lrt\
-       %{static:-a archive}} -lpthread} -lc\
-     %{static:%{!nolibdld:-a archive_shared -ldld -a archive -lc}}}\
+     %{fopenmp:%{static:-a archive_shared} -lrt %{static:-a archive}}\
+     %{mt|pthread:-lpthread} -lc\
+     %{static:%{!nolibdld:-a archive_shared -ldld -a archive -lc}\
+       %{!mt:%{!pthread:-a shared -lc -a archive}}}}\
    %{shared:%{mt|pthread:-lpthread}}"
 
 #undef STARTFILE_SPEC
index 16f5a3e4b09281a6bdee7eb27e15f5a0664fedd3..155ce486b600290cf5bd07ef25f2902245df1f7c 100644 (file)
@@ -57,36 +57,42 @@ along with GCC; see the file COPYING3.  If not see
 #if ((TARGET_DEFAULT | TARGET_CPU_DEFAULT) & MASK_GNU_LD)
 #define LIB_SPEC \
   "%{!shared:\
-     %{!p:%{!pg:%{static|mt|pthread:%{fopenmp:%{static:-a shared} -lrt\
-                 %{static:-a archive}} -lpthread} -lc\
-           %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
+     %{!p:%{!pg:%{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
+           %{mt|pthread:-lpthread} -lc\
+           %{static:%{!nolibdld:-a shared -ldld -a archive -lc}\
+               %{!mt:%{!pthread:-a shared -lc -a archive}}}}}\
      %{p:%{!pg:%{static:%{!mhp-ld:-a shared}%{mhp-ld:-a archive_shared}}\
           -lprof %{static:-a archive}\
-          %{static|mt|pthread:%{fopenmp:%{static:-a shared} -lrt\
-            %{static:-a archive}} -lpthread} -lc\
-          %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
+          %{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
+          %{mt|pthread:-lpthread} -lc\
+          %{static:%{!nolibdld:-a shared -ldld -a archive -lc}\
+               %{!mt:%{!pthread:-a shared -lc -a archive}}}}}\
      %{pg:%{static:%{!mhp-ld:-a shared}%{mhp-ld:-a archive_shared}}\
        -lgprof %{static:-a archive}\
-       %{static|mt|pthread:%{fopenmp:%{static:-a shared} -lrt\
-        %{static:-a archive}} -lpthread} -lc\
-       %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
+       %{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
+       %{mt|pthread:-lpthread} -lc\
+       %{static:%{!nolibdld:-a shared -ldld -a archive -lc}\
+               %{!mt:%{!pthread:-a shared -lc -a archive}}}}}\
    %{shared:%{mt|pthread:-lpthread}}"
 #else
 #define LIB_SPEC \
   "%{!shared:\
-     %{!p:%{!pg:%{static|mt|pthread:%{fopenmp:%{static:-a shared} -lrt\
-                 %{static:-a archive}} -lpthread} -lc\
-           %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
+     %{!p:%{!pg:%{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
+           %{mt|pthread:-lpthread} -lc\
+           %{static:%{!nolibdld:-a shared -ldld -a archive -lc}\
+               %{!mt:%{!pthread:-a shared -lc -a archive}}}}}\
      %{p:%{!pg:%{static:%{mgnu-ld:-a shared}%{!mgnu-ld:-a archive_shared}}\
           -lprof %{static:-a archive}\
-          %{static|mt|pthread:%{fopenmp:%{static:-a shared} -lrt\
-            %{static:-a archive}} -lpthread} -lc\
-          %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
+          %{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
+          %{mt|pthread:-lpthread} -lc\
+          %{static:%{!nolibdld:-a shared -ldld -a archive -lc}\
+               %{!mt:%{!pthread:-a shared -lc -a archive}}}}}\
      %{pg:%{static:%{mgnu-ld:-a shared}%{!mgnu-ld:-a archive_shared}}\
        -lgprof %{static:-a archive}\
-       %{static|mt|pthread:%{fopenmp:%{static:-a shared} -lrt\
-        %{static:-a archive}} -lpthread} -lc\
-       %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
+       %{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
+       %{mt|pthread:-lpthread} -lc\
+       %{static:%{!nolibdld:-a shared -ldld -a archive -lc}\
+               %{!mt:%{!pthread:-a shared -lc -a archive}}}}}\
    %{shared:%{mt|pthread:-lpthread}}"
 #endif
 
index 82a3c581c0a0e9d8b0adf99d9611e073f66eedc9..4264bcc0209a6690c47905895b573fefa8ad2b9a 100644 (file)
@@ -250,61 +250,34 @@ __gthread_active_p (void)
    calls in shared flavors of the HP-UX C library.  Most of the stubs
    have no functionality.  The details are described in the "libc cumulative
    patch" for each subversion of HP-UX 11.  There are two special interfaces
-   provided for checking whether an application is linked to a pthread
+   provided for checking whether an application is linked to a shared pthread
    library or not.  However, these interfaces aren't available in early
-   libc versions.  We also can't use pthread_once as some libc versions
-   call the init function.  So, we use pthread_create to check whether it
-   is possible to create a thread or not.  The stub implementation returns
-   the error number ENOSYS.  */
+   libpthread libraries.  We also need a test that works for archive
+   libraries.  We can't use pthread_once as some libc versions call the
+   init function.  We also can't use pthread_create or pthread_attr_init
+   as these create a thread and thereby prevent changing the default stack
+   size.  The function pthread_default_stacksize_np is available in both
+   the archive and shared versions of libpthread.   It can be used to
+   determine the default pthread stack size.  There is a stub in some
+   shared libc versions which returns a zero size if pthreads are not
+   active.  We provide an equivalent stub to handle cases where libc
+   doesn't provide one.  */
 
 #if defined(__hppa__) && defined(__hpux__)
 
-#include <errno.h>
-
 static volatile int __gthread_active = -1;
 
-static void *
-__gthread_start (void *__arg __attribute__((unused)))
-{
-  return NULL;
-}
-
-static void __gthread_active_init (void) __attribute__((noinline));
-static void
-__gthread_active_init (void)
-{
-  static pthread_mutex_t __gthread_active_mutex = PTHREAD_MUTEX_INITIALIZER;
-  pthread_t __t;
-  pthread_attr_t __a;
-  int __result;
-
-  __gthrw_(pthread_mutex_lock) (&__gthread_active_mutex);
-  if (__gthread_active < 0)
-    {
-      __gthrw_(pthread_attr_init) (&__a);
-      __gthrw_(pthread_attr_setdetachstate) (&__a, PTHREAD_CREATE_DETACHED);
-      __result = __gthrw_(pthread_create) (&__t, &__a, __gthread_start, NULL);
-      if (__result != ENOSYS)
-       __gthread_active = 1;
-      else
-       __gthread_active = 0;
-      __gthrw_(pthread_attr_destroy) (&__a);
-    }
-  __gthrw_(pthread_mutex_unlock) (&__gthread_active_mutex);
-}
-
 static inline int
 __gthread_active_p (void)
 {
   /* Avoid reading __gthread_active twice on the main code path.  */
   int __gthread_active_latest_value = __gthread_active;
+  size_t __s;
 
-  /* This test is not protected to avoid taking a lock on the main code
-     path so every update of __gthread_active in a threaded program must
-     be atomic with regard to the result of the test.  */
   if (__builtin_expect (__gthread_active_latest_value < 0, 0))
     {
-      __gthread_active_init ();
+      pthread_default_stacksize_np (0, &__s);
+      __gthread_active = __s ? 1 : 0;
       __gthread_active_latest_value = __gthread_active;
     }
 
index 8772c977a28bc48eaa99036506165230a8b81858..98471d6c05965748158488810e48fcec6ab5d612 100644 (file)
@@ -184,61 +184,34 @@ __gthread_active_p (void)
    calls in shared flavors of the HP-UX C library.  Most of the stubs
    have no functionality.  The details are described in the "libc cumulative
    patch" for each subversion of HP-UX 11.  There are two special interfaces
-   provided for checking whether an application is linked to a pthread
+   provided for checking whether an application is linked to a shared pthread
    library or not.  However, these interfaces aren't available in early
-   libc versions.  We also can't use pthread_once as some libc versions
-   call the init function.  So, we use pthread_create to check whether it
-   is possible to create a thread or not.  The stub implementation returns
-   the error number ENOSYS.  */
+   pthread libraries.  We also need a test that works for archive
+   libraries.  We can't use pthread_once as some libc versions call the
+   init function.  We also can't use pthread_create or pthread_attr_init
+   as these create a thread and thereby prevent changing the default stack
+   size.  The function pthread_default_stacksize_np is available in both
+   the archive and shared versions of libpthread.   It can be used to
+   determine the default pthread stack size.  There is a stub in some
+   shared libc versions which returns a zero size if pthreads are not
+   active.  We provide an equivalent stub to handle cases where libc
+   doesn't provide one.  */
 
 #if defined(__hppa__) && defined(__hpux__)
 
-#include <errno.h>
-
 static volatile int __gthread_active = -1;
 
-static void *
-__gthread_start (void *arg __attribute__((unused)))
-{
-  return NULL;
-}
-
-static void __gthread_active_init (void) __attribute__((noinline));
-static void
-__gthread_active_init (void)
-{
-  static pthread_mutex_t __gthread_active_mutex = PTHREAD_MUTEX_INITIALIZER;
-  pthread_t t;
-  pthread_attr_t a;
-  int result;
-
-  __gthrw_(pthread_mutex_lock) (&__gthread_active_mutex);
-  if (__gthread_active < 0)
-    {
-      __gthrw_(pthread_attr_init) (&a);
-      __gthrw_(pthread_attr_setdetachstate) (&a, PTHREAD_CREATE_DETACHED);
-      result = __gthrw_(pthread_create) (&t, &a, __gthread_start, NULL);
-      if (result != ENOSYS)
-       __gthread_active = 1;
-      else
-       __gthread_active = 0;
-      __gthrw_(pthread_attr_destroy) (&a);
-    }
-  __gthrw_(pthread_mutex_unlock) (&__gthread_active_mutex);
-}
-
 static inline int
 __gthread_active_p (void)
 {
   /* Avoid reading __gthread_active twice on the main code path.  */
   int __gthread_active_latest_value = __gthread_active;
+  size_t __s;
 
-  /* This test is not protected to avoid taking a lock on the main code
-     path so every update of __gthread_active in a threaded program must
-     be atomic with regard to the result of the test.  */
   if (__builtin_expect (__gthread_active_latest_value < 0, 0))
     {
-      __gthread_active_init ();
+      pthread_default_stacksize_np (0, &__s);
+      __gthread_active = __s ? 1 : 0;
       __gthread_active_latest_value = __gthread_active;
     }