This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

3.4 PATCH: Support POSIX threads on Tru64 UNIX


This patch is the last in a series of three to fully support (and enable by
default) --enable-threads=posix on Tru64 UNIX V4/V5.  The relevant boehm-gc
and libjava patches (still unreviewed)

	http://gcc.gnu.org/ml/java-patches/2003-q3/msg00075.html
	http://gcc.gnu.org/ml/java-patches/2003-q3/msg00076.html

need to go in first to avoid problems with enabling pthread support by
default.

Apart from the necessary configury and doc bits, the patch consists of two
parts:

* Depending on the compiler used, <pthread.h> either uses #pragma
  extern_prefix or redefines to change the external names of some pthread
  functions, like so:

# ifdef _PTHREAD_USE_PTDNAM_
#  pragma extern_prefix "__"
# else
#  define pthread_self __pthread_self
# endif

  Since the macro games cause all sorts of problems and gcc already
  supports #pragma extern_prefix, this patch uses fixincludes to also
  define _PTHREAD_USE_PTDNAM_ if __PRAGMA_EXTERN_PREFIX is defined
  (i.e. gcc's feature test macro to denote its support for the feature).
  This is not strictly necessary, but simplifies the patch alot.

* The main part of the patch deals with the following problem: unlike ELF
  systems, the Tru64 UNIX linker cannot handle weak definitions,
  i.e. symbols whose only definition is #pragma weak <symbol>.  On ELF
  systems, <symbol> becomes defined (weak) with a value of 0.  The Tru64
  UNIX linker treats such a symbol as undefined.  This causes problems for
  users of gthr-posix.h (i.e. libstdc++-v3 and libobjc), which used to rely
  on weak definitions of several POSIX threads functions.  As a workaround,
  this patch adds weak definitions of all functions needed by gthr-posix.h
  in a separate file (gthr-posix.c), which is only used as needed.  These
  are only dummy definitions, patterned after the definitions in the
  Solaris 8 libc wrt. return codes.  gthr-posix.o is added to both
  libgcc_s.so and libgcc.a:

  In libgcc_s.so, the definitions are necessary to resolve the references
  from the various unwind functions without having to link with -lpthread,
  but hidden with linker magic (-hidden_symbol).  I didn't want to leave
  them undefined (to be provided by libgcc.a) since that would break if a
  gcc-compiled shared object is used with a non-gcc compiler, which doesn't
  use or know about libgcc.a.  On the other hand, those symbols don't
  belong to the interface of libgcc_s and thus shouldn't be exported.  To
  make sure the -hidden_symbol flags have the desired effect, I've checked
  (using odump -Dt) that the pthread and sched functions are indeed local
  (i.e. not exported from libgcc_s.so).

  Adding the weak definitions to libgcc.a shouldn't hurt (in the same way
  as the definitions in Solaris 2 libc don't seem to hurt), since any user
  of POSIX threads is expected to link with -lpthread anyway.  This
  provides the necessary definitions for the other runtime libraries that
  need them, namely libstc++ and libobjc.  Since those libraries are
  expected to be gcc-only (there's no other compiler implementing either
  the new C++ ABI or Objective-C on Tru64 UNIX), I didn't try to include
  the weak definitions there.

Bootstrapped (together with the two patches above) on alpha-dec-osf4.0f and
alpha-dec-osf5.1 with only the problems reported with the libjava patch
(which are unrelated to this one).

The fixincl bits (apart from performing the desired fix :-) pass make check
in fixinc (and should go in even if there are concerns about the rest of
the patch).

Ok for mainline?

	Rainer

-----------------------------------------------------------------------------
Rainer Orth, Faculty of Technology, Bielefeld University


Tue Jul  8 15:09:16 2003  Rainer Orth  <ro@TechFak.Uni-Bielefeld.DE>

	* config.gcc (alpha*-dec-osf[45]*): Enable POSIX thread support by
	default.

	* gthr-posix.c: New file.
	* gthr-posix.h: Define _REENTRANT if missing.
	Make _LIBOBJC #pragma weak visible with _LIBOBJC_WEAK.

	* config/alpha/t-osf4 (SHLIB_LINK): Hide dummy functions provided
	by gthr-posix.o.
	* config/alpha/t-osf-pthread: New file.

	* fixinc/inclhack.def (alpha_pthread): New fix.
	* fixinc/fixincl.x: Regenerate.
	* fixinc/tests/base/pthread.h [ALPHA_PTHREAD_CHECK]: New testcase.

	* doc/install.texi (alpha*-dec-osf*): Remove --enable-threads
	warning.
	Fixes PR bootstrap/9330.

Index: gcc/config.gcc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config.gcc,v
retrieving revision 1.331
diff -u -p -r1.331 config.gcc
--- gcc/config.gcc	2 Jul 2003 00:21:55 -0000	1.331
+++ gcc/config.gcc	15 Jul 2003 21:13:08 -0000
@@ -606,6 +606,12 @@ alpha*-dec-osf[45]*)
 	    target_cpu_default=MASK_SUPPORT_ARCH
 	    ;;
 	esac
+	case x${enable_threads} in
+	x | xyes | xpthreads | xposix)
+	    thread_file='posix'
+	    tmake_file="${tmake_file} alpha/t-osf-pthread"
+	    ;;
+	esac
 	;;
 alpha64-dec-*vms*)
 	tm_file="${tm_file} alpha/vms.h alpha/vms64.h"
Index: gcc/doc/install.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/install.texi,v
retrieving revision 1.206
diff -u -p -r1.206 install.texi
--- gcc/doc/install.texi	20 Jun 2003 11:18:03 -0000	1.206
+++ gcc/doc/install.texi	15 Jul 2003 21:20:41 -0000
@@ -2026,9 +2026,6 @@ As of GNU binutils 2.11.2, neither GNU @
 are supported on Tru64 UNIX, so you must not configure GCC with
 @option{--with-gnu-as} or @option{--with-gnu-ld}.
 
-The @option{--enable-threads} options isn't supported yet.  A patch is
-in preparation for a future release.
-
 GCC writes a @samp{.verstamp} directive to the assembler output file
 unless it is built as a cross-compiler.  It gets the version to use from
 the system header file @file{/usr/include/stamp.h}.  If you install a
Index: gcc/gthr-posix.c
===================================================================
RCS file: gcc/gthr-posix.c
diff -N gcc/gthr-posix.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gcc/gthr-posix.c	15 Jul 2003 21:13:21 -0000
@@ -0,0 +1,207 @@
+/* POSIX threads dummy routines for systems without weak definitions.  */
+/* Compile this one with gcc.  */
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.  */
+
+/* As a special exception, if you link this library with other files,
+   some of which are compiled with GCC, to produce an executable,
+   this library does not by itself cause the resulting executable
+   to be covered by the GNU General Public License.
+   This exception does not however invalidate any other reasons why
+   the executable file might be covered by the GNU General Public License.  */
+
+#include "tconfig.h"
+#include "tm.h"
+/* Define so we provide weak definitions of functions used by libobjc only.  */
+#define _LIBOBJC_WEAK
+#include "gthr.h"
+
+int
+pthread_once (pthread_once_t *once ATTRIBUTE_UNUSED,
+	      void (*func) (void) ATTRIBUTE_UNUSED)
+{
+  return -1;
+}
+
+int
+pthread_key_create (pthread_key_t *key ATTRIBUTE_UNUSED,
+		    void (*dtor) (void *) ATTRIBUTE_UNUSED)
+{
+  return -1;
+}
+
+int
+pthread_key_delete (pthread_key_t key ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+void *
+pthread_getspecific (pthread_key_t key ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+int
+pthread_setspecific (pthread_key_t key ATTRIBUTE_UNUSED,
+		     const void *ptr ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+int
+pthread_create (pthread_t *thread ATTRIBUTE_UNUSED,
+		const pthread_attr_t *attr ATTRIBUTE_UNUSED,
+		void *(*start_routine) (void *) ATTRIBUTE_UNUSED,
+		void *arg ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+int
+pthread_mutex_lock (pthread_mutex_t *mutex ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+int
+pthread_mutex_trylock (pthread_mutex_t *mutex ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+int
+pthread_mutex_unlock (pthread_mutex_t *mutex ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+int
+pthread_cond_broadcast (pthread_cond_t *cond ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+int
+pthread_cond_destroy (pthread_cond_t *cond ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+int
+pthread_cond_init (pthread_cond_t *cond ATTRIBUTE_UNUSED,
+		   const pthread_condattr_t *attr ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+int
+pthread_cond_signal (pthread_cond_t *cond ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+int
+pthread_cond_wait (pthread_cond_t *cond ATTRIBUTE_UNUSED,
+		   pthread_mutex_t *mutex ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+void
+pthread_exit (void *value_ptr ATTRIBUTE_UNUSED)
+{
+}
+
+int
+pthread_mutex_init (pthread_mutex_t *mutex ATTRIBUTE_UNUSED,
+		    const pthread_mutexattr_t *attr ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+int
+pthread_mutex_destroy (pthread_mutex_t *mutex ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+pthread_t
+pthread_self (void)
+{
+  return (pthread_t) 0;
+}
+
+#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
+int
+sched_get_priority_max (int policy ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+int
+sched_get_priority_min (int policy ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+#endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
+
+int
+sched_yield (void)
+{
+  return 0;
+}
+
+int
+pthread_attr_destroy (pthread_attr_t *attr ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+int
+pthread_attr_init (pthread_attr_t *attr ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+int
+pthread_attr_setdetachstate (pthread_attr_t *attr ATTRIBUTE_UNUSED,
+			     int detachstate ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
+int
+pthread_getschedparam (pthread_t thread ATTRIBUTE_UNUSED,
+		       int *policy ATTRIBUTE_UNUSED,
+		       struct sched_param *param ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+int
+pthread_setschedparam (pthread_t thread ATTRIBUTE_UNUSED,
+		       int policy ATTRIBUTE_UNUSED,
+		       const struct sched_param *param ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+#endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
+
Index: gcc/gthr-posix.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gthr-posix.h,v
retrieving revision 1.26
diff -u -p -r1.26 gthr-posix.h
--- gcc/gthr-posix.h	16 Dec 2002 18:19:37 -0000	1.26
+++ gcc/gthr-posix.h	15 Jul 2003 21:13:21 -0000
@@ -1,6 +1,7 @@
 /* Threads compatibility routines for libgcc2 and libobjc.  */
 /* Compile this one with gcc.  */
-/* Copyright (C) 1997, 1999, 2000, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1999, 2000, 2001, 2002, 2003
+   Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -34,6 +35,11 @@ Software Foundation, 59 Temple Place - S
 
 #define __GTHREADS 1
 
+/* Some implementations of <pthread.h> require this to be defined.  */
+#ifndef _REENTRANT
+#define _REENTRANT 1
+#endif
+
 #include <pthread.h>
 #include <unistd.h>
 
@@ -57,7 +63,7 @@ typedef pthread_mutex_t __gthread_mutex_
 #pragma weak pthread_mutex_trylock
 #pragma weak pthread_mutex_unlock
 
-#ifdef _LIBOBJC
+#if defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)
 /* Objective-C.  */
 #pragma weak pthread_cond_broadcast
 #pragma weak pthread_cond_destroy
@@ -82,7 +88,7 @@ typedef pthread_mutex_t __gthread_mutex_
 #pragma weak pthread_getschedparam
 #pragma weak pthread_setschedparam
 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
-#endif /* _LIBOBJC */
+#endif /* _LIBOBJC || _LIBOBJC_WEAK */
 
 static inline int
 __gthread_active_p (void)
Index: gcc/config/alpha/t-osf-pthread
===================================================================
RCS file: gcc/config/alpha/t-osf-pthread
diff -N gcc/config/alpha/t-osf-pthread
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gcc/config/alpha/t-osf-pthread	15 Jul 2003 21:13:21 -0000
@@ -0,0 +1,5 @@
+# Provide dummy POSIX threads functions
+LIB2FUNCS_EXTRA += $(srcdir)/gthr-posix.c
+
+# Compile libgcc2 with POSIX threads supports
+TARGET_LIBGCC2_CFLAGS=-pthread
Index: gcc/config/alpha/t-osf4
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/alpha/t-osf4,v
retrieving revision 1.6
diff -u -p -r1.6 t-osf4
--- gcc/config/alpha/t-osf4	9 Jan 2003 08:00:39 -0000	1.6
+++ gcc/config/alpha/t-osf4	15 Jul 2003 21:13:21 -0000
@@ -10,7 +10,11 @@ SHLIB_NAME = @shlib_base_name@.so
 SHLIB_SONAME = @shlib_base_name@.so.1
 SHLIB_OBJS = @shlib_objs@
 
+# Hide all POSIX threads related symbols provided by gthr-posix.c.  This
+# only has an effect if t-osf-pthread is in use.
 SHLIB_LINK = $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) -shared -nodefaultlibs \
+	-Wl,-hidden_symbol,pthread\* -Wl,-hidden_symbol,__pthread\* \
+	-Wl,-hidden_symbol,sched_get_\* -Wl,-hidden_symbol,sched_yield \
 	-Wl,-msym -Wl,-set_version,gcc.1 -Wl,-soname,$(SHLIB_SONAME) \
 	-o $(SHLIB_NAME) @multilib_flags@ $(SHLIB_OBJS) -lc && \
 	rm -f $(SHLIB_SONAME) && \
Index: gcc/fixinc/inclhack.def
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fixinc/inclhack.def,v
retrieving revision 1.157
diff -u -p -r1.157 inclhack.def
--- gcc/fixinc/inclhack.def	28 May 2003 11:53:34 -0000	1.157
+++ gcc/fixinc/inclhack.def	15 Jul 2003 21:13:35 -0000
@@ -578,6 +578,25 @@ fix = {
 
 
 /*
+ *  Obey __PRAGMA_EXTERN_PREFIX for Tru64 UNIX <pthread.h>.
+ */
+fix = {
+    hackname  = alpha_pthread;
+    files     = pthread.h;
+    select    = "(#[ \t]*if defined \\(_PTHREAD_ENV_DECC\\) || defined \\(_PTHREAD_ENV_EPCC\\))\n"
+		"(#[ \t]*define _PTHREAD_USE_PTDNAM_)";
+
+    mach      = "alpha*-dec-osf*";
+    c_fix     = format;
+    c_fix_arg = "%1 || defined (__PRAGMA_EXTERN_PREFIX)\n%2";
+
+    test_text = "#  if defined (_PTHREAD_ENV_DECC) || defined (_PTHREAD_ENV_EPCC)\n"
+		"#   define _PTHREAD_USE_PTDNAM_\n"
+		"#  endif";
+};
+
+
+/*
  *  Fix return value of sbrk in unistd.h on Alpha OSF/1 V2.0
  */
 fix = {
Index: gcc/fixinc/tests/base/pthread.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fixinc/tests/base/pthread.h,v
retrieving revision 1.9
diff -u -p -r1.9 pthread.h
--- gcc/fixinc/tests/base/pthread.h	22 Mar 2003 21:51:04 -0000	1.9
+++ gcc/fixinc/tests/base/pthread.h	15 Jul 2003 21:13:35 -0000
@@ -15,6 +15,13 @@
 #endif  /* AIX_PTHREAD_CHECK */
 
 
+#if defined( ALPHA_PTHREAD_CHECK )
+#  if defined (_PTHREAD_ENV_DECC) || defined (_PTHREAD_ENV_EPCC) || defined (__PRAGMA_EXTERN_PREFIX)
+#   define _PTHREAD_USE_PTDNAM_
+#  endif
+#endif  /* ALPHA_PTHREAD_CHECK */
+
+
 #if defined( PTHREAD_PAGE_SIZE_CHECK )
 extern int __page_size;
 #endif  /* PTHREAD_PAGE_SIZE_CHECK */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]