PR boehm-gc/34544
authordanglin <danglin@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 22 Aug 2010 16:23:38 +0000 (16:23 +0000)
committerdanglin <danglin@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 22 Aug 2010 16:23:38 +0000 (16:23 +0000)
* 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.
* config.gcc (hppa[12]*-*-hpux11*): Define extra_parts.
* config/pa/pa64-hpux.h (LIB_SPEC): When -static is specified, only
add -lpthread when -mt or -pthread is specified.
* config/pa/pa-hpux11.h (LIB_SPEC): likewise.
(LINK_GCC_C_SEQUENCE_SPEC): Define.
* config/pa/t-pa-hpux11 (LIBGCCSTUB_OBJS): Define.
(stublib.c, pthread_default_stacksize_np-stub.o,
pthread_mutex_lock-stub.o, pthread_mutex_unlock-stub.o,
$(T)libgcc_stub.a): Add methods.
* config/pa/t-pa64 (LIBGCCSTUB_OBJS): Add pthread stubs.
(stublib.c, pthread_default_stacksize_np-stub.o,
pthread_mutex_lock-stub.o, pthread_mutex_unlock-stub.o): Add methods.
* config/pa/stublib.c (pthread_default_stacksize_np, pthread_mutex_lock,
pthread_mutex_unlock): New stubs.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@163461 138bc75d-0d04-0410-961f-82ee72b054a4

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

index ab3cff9..13eb21b 100644 (file)
@@ -1,3 +1,27 @@
+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.
+       * config.gcc (hppa[12]*-*-hpux11*): Define extra_parts.
+       * config/pa/pa64-hpux.h (LIB_SPEC): When -static is specified, only
+       add -lpthread when -mt or -pthread is specified.
+       * config/pa/pa-hpux11.h (LIB_SPEC): likewise.
+       (LINK_GCC_C_SEQUENCE_SPEC): Define.
+       * config/pa/t-pa-hpux11 (LIBGCCSTUB_OBJS): Define.
+       (stublib.c, pthread_default_stacksize_np-stub.o,
+       pthread_mutex_lock-stub.o, pthread_mutex_unlock-stub.o,
+       $(T)libgcc_stub.a): Add methods.
+       * config/pa/t-pa64 (LIBGCCSTUB_OBJS): Add pthread stubs.
+       (stublib.c, pthread_default_stacksize_np-stub.o,
+       pthread_mutex_lock-stub.o, pthread_mutex_unlock-stub.o): Add methods.
+       * config/pa/stublib.c (pthread_default_stacksize_np, pthread_mutex_lock,
+       pthread_mutex_unlock): New stubs.
+
 2010-08-22  Joseph Myers  <joseph@codesourcery.com>
 
        * Makefile.in (gccspec.o, cppspec.o): Update dependencies.
index 62dd9f6..148c99b 100644 (file)
@@ -1106,6 +1106,7 @@ hppa[12]*-*-hpux11*)
        else
            tmake_file="$tmake_file pa/t-slibgcc-dwarf-ver"
        fi
+       extra_parts="libgcc_stub.a"
        case x${enable_threads} in
        x | xyes | xposix )
                thread_file=posix
index 540a93d..dd9f9b5 100644 (file)
@@ -121,11 +121,16 @@ along with GCC; see the file COPYING3.  If not see
 #undef LIB_SPEC
 #define LIB_SPEC \
   "%{!shared:\
-     %{static|mt|pthread:%{fopenmp:%{static:-a archive_shared} -lrt\
-       %{static:-a archive}} -lpthread} -lc\
+     %{fopenmp:%{static:-a archive_shared} -lrt %{static:-a archive}}\
+     %{mt|pthread:-lpthread} -lc\
      %{static:%{!nolibdld:-a archive_shared -ldld -a archive -lc}}}\
    %{shared:%{mt|pthread:-lpthread}}"
 
+/* The libgcc_stub.a library needs to come last.  */
+#undef LINK_GCC_C_SEQUENCE_SPEC
+#define LINK_GCC_C_SEQUENCE_SPEC \
+  "%G %L %G %{!nostdlib:%{!nodefaultlibs:%{!shared:-lgcc_stub}}}"
+
 #undef STARTFILE_SPEC
 #define STARTFILE_SPEC \
   "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}} \
index 35ea51c..5132b2f 100644 (file)
@@ -59,35 +59,35 @@ 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\
+     %{!p:%{!pg:%{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
+           %{mt|pthread:-lpthread} -lc\
            %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
      %{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\
+          %{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
+          %{mt|pthread:-lpthread} -lc\
           %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
      %{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\
+       %{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
+       %{mt|pthread:-lpthread} -lc\
        %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
    %{shared:%{mt|pthread:-lpthread}}"
 #else
 #define LIB_SPEC \
   "%{!shared:\
-     %{!p:%{!pg:%{static|mt|pthread:%{fopenmp:%{static:-a shared} -lrt\
-                 %{static:-a archive}} -lpthread} -lc\
+     %{!p:%{!pg:%{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
+           %{mt|pthread:-lpthread} -lc\
            %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
      %{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\
+          %{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
+          %{mt|pthread:-lpthread} -lc\
           %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
      %{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\
+       %{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
+       %{mt|pthread:-lpthread} -lc\
        %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
    %{shared:%{mt|pthread:-lpthread}}"
 #endif
index c3f0f45..bcf0a37 100644 (file)
@@ -1,5 +1,5 @@
 /* Stub functions.
-   Copyright (C) 2006, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2009, 2010 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -56,3 +56,33 @@ _Jv_RegisterClasses (void *p)
 {
 }
 #endif
+
+#ifdef L_pthread_default_stacksize_np
+int pthread_default_stacksize_np (unsigned long __attribute__((unused)),
+                                 unsigned long *);
+int
+pthread_default_stacksize_np (unsigned long new, unsigned long *old)
+{
+  if (old)
+    *old = 0;
+  return 0;
+}
+#endif
+
+#ifdef L_pthread_mutex_lock
+int pthread_mutex_lock (void * __attribute__((unused)));
+int
+pthread_mutex_lock (void *p)
+{
+  return 0;
+}
+#endif
+
+#ifdef L_pthread_mutex_unlock
+int pthread_mutex_unlock (void * __attribute__((unused)));
+int
+pthread_mutex_unlock (void *p)
+{
+  return 0;
+}
+#endif
index 2773828..15b0a85 100644 (file)
@@ -1,2 +1,26 @@
 TARGET_LIBGCC2_CFLAGS = -fPIC -frandom-seed=fixed-seed
 LIB2FUNCS_EXTRA=lib2funcs.asm quadlib.c
+LIBGCCSTUB_OBJS = pthread_default_stacksize_np-stub.o \
+       pthread_mutex_lock-stub.o \
+       pthread_mutex_unlock-stub.o
+
+stublib.c: $(srcdir)/config/pa/stublib.c
+       rm -f stublib.c
+       cp $(srcdir)/config/pa/stublib.c .
+
+pthread_default_stacksize_np-stub.o: stublib.c $(GCC_PASSES)
+       $(GCC_FOR_TARGET) -c -O2 -DL_pthread_default_stacksize_np stublib.c \
+         -o pthread_default_stacksize_np-stub.o
+
+pthread_mutex_lock-stub.o: stublib.c $(GCC_PASSES)
+       $(GCC_FOR_TARGET) -c -O2 -DL_pthread_mutex_lock stublib.c \
+         -o pthread_mutex_lock-stub.o
+
+pthread_mutex_unlock-stub.o: stublib.c $(GCC_PASSES)
+       $(GCC_FOR_TARGET) -c -O2 -DL_pthread_mutex_unlock stublib.c \
+         -o pthread_mutex_unlock-stub.o
+
+$(T)libgcc_stub.a: $(LIBGCCSTUB_OBJS)
+       -rm -rf $(T)libgcc_stub.a
+       $(AR) rc $(T)libgcc_stub.a $(LIBGCCSTUB_OBJS)
+       $(RANLIB) $(T)libgcc_stub.a
index 1aa2f3b..0a4827e 100644 (file)
@@ -1,5 +1,5 @@
 # Copyright (C) 2000, 2001, 2002, 2004, 2006,
-# 2007 Free Software Foundation, Inc.
+# 2007, 2010 Free Software Foundation, Inc.
 #
 # This file is part of GCC.
 #
 
 TARGET_LIBGCC2_CFLAGS = -fPIC -Dpa64=1 -DELF=1 -mlong-calls
 LIB2FUNCS_EXTRA = quadlib.c
-LIBGCCSTUB_OBJS = rfi-stub.o dfi-stub.o jvrc-stub.o cxaf-stub.o
+LIBGCCSTUB_OBJS = rfi-stub.o dfi-stub.o jvrc-stub.o cxaf-stub.o \
+       pthread_default_stacksize_np-stub.o \
+       pthread_mutex_lock-stub.o \
+       pthread_mutex_unlock-stub.o
 
 stublib.c: $(srcdir)/config/pa/stublib.c
        rm -f stublib.c
@@ -41,6 +44,18 @@ jvrc-stub.o: stublib.c $(GCC_PASSES)
        $(GCC_FOR_TARGET) -c -O2 -DL_Jv_RegisterClasses stublib.c \
          -o jvrc-stub.o
 
+pthread_default_stacksize_np-stub.o: stublib.c $(GCC_PASSES)
+       $(GCC_FOR_TARGET) -c -O2 -DL_pthread_default_stacksize_np stublib.c \
+         -o pthread_default_stacksize_np-stub.o
+
+pthread_mutex_lock-stub.o: stublib.c $(GCC_PASSES)
+       $(GCC_FOR_TARGET) -c -O2 -DL_pthread_mutex_lock stublib.c \
+         -o pthread_mutex_lock-stub.o
+
+pthread_mutex_unlock-stub.o: stublib.c $(GCC_PASSES)
+       $(GCC_FOR_TARGET) -c -O2 -DL_pthread_mutex_unlock stublib.c \
+         -o pthread_mutex_unlock-stub.o
+
 $(T)libgcc_stub.a: $(LIBGCCSTUB_OBJS)
        -rm -rf $(T)libgcc_stub.a
        $(AR) rc $(T)libgcc_stub.a $(LIBGCCSTUB_OBJS)
index f7f240f..bda43cd 100644 (file)
@@ -260,47 +260,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_active_init (void) __attribute__((noinline));
-static void
-__gthread_active_init (void)
-{
-  static pthread_mutex_t __gthread_active_mutex = PTHREAD_MUTEX_INITIALIZER;
-  size_t __s;
-
-  __gthrw_(pthread_mutex_lock) (&__gthread_active_mutex);
-  if (__gthread_active < 0)
-    {
-      pthread_default_stacksize_np (0, &__s);
-      __gthread_active = __s ? 1 : 0;
-    }
-  __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 d0e0f99..2b26f2d 100644 (file)
@@ -184,47 +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_active_init (void) __attribute__((noinline));
-static void
-__gthread_active_init (void)
-{
-  static pthread_mutex_t __gthread_active_mutex = PTHREAD_MUTEX_INITIALIZER;
-  size_t __s;
-
-  __gthrw_(pthread_mutex_lock) (&__gthread_active_mutex);
-  if (__gthread_active < 0)
-    {
-      pthread_default_stacksize_np (0, &__s);
-      __gthread_active = __s ? 1 : 0;
-    }
-  __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;
     }