This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] PR bootstrap/9330: -pthread required to include <pthread.h>
- From: Roger Sayle <roger at eyesopen dot com>
- To: gcc-patches at gcc dot gnu dot org, <libstdc++ at gcc dot gnu dot org>, <java-patches at gcc dot gnu dot org>
- Date: Thu, 26 Jun 2003 09:44:04 -0600 (MDT)
- Subject: [PATCH] PR bootstrap/9330: -pthread required to include <pthread.h>
Dara Hazeghi has asked me to investigate PR bootstrap/9330 which is
a bootstrap failure on alphaev56-dec-osf5.1 when configured with
--enable-threads=posix. Unfortunately, I can't reproduce the bootstrap
failure on a clean alphaev67-dec-osf5.1 system, however I am able to edit
my machine's /usr/include/pthreads.h to emulate the failure mode described
in the PR.
Even on my Tru64 box, the pthreads.h header file is emphatic that
_REENTRANT must be defined before including this file. To quote the
comments:
> Or, finally, by modifying your Makefile (or manual build sequence) to
> use the -D compiler option. (Note: you must ALWAYS define _REENTRANT
> when compiling threaded or thread-safe code on Tru64 UNIX. Using
> "cc -threads" or "cc -pthread" does this automatically.)
Hence, I simply added an "#ifndef _REENTRANT" around a "#error" to the
top of this file to see reproduce the environment reported in the PR.
And of course, GCC mainline then failed to compile as in PR/9330.
The patch below is my "straw man" for a potential fix to the problem.
I'm unsure of all the issues involved, but the patch below allows the
compiler to bootstrap [the test results don't look so good, but atleast
the current PR is in the "bootstrap" category].
The only failure in building the compilers themselves was building
the unwind*.c files in libgcc, which seem to be the only place where
we include gthr.h. The fix below follows the netbsd/openbsd solution
of using a tmake_file fragment to define TARGET_LIBGCC2_CFLAGS to be
"-pthread".
The next failure came when building libstdc++. Although Ben Kosnik
has mentioned as recently as yesterday that the -pthread option may be
required to build some libstdc++ files, I was unable to find where
this mechanism is specified/used. My work around to handle this case
was to add
#ifndef _REENTRANT
#define _REENTRANT 1
#endif
to gthr-posix.h, hoping that this would fix the failure on the failing
Tru64 releases, and do no harm on most other platforms. I may be wrong.
Finally, the third and final failure was building libjava which includes
<pthread.h> directly. Here the fix was to tweak configure.in such that
in addition to adding -lpthread to THREADLIBS when using posix threads,
on alpha*-dec-osf5*, we also set THREADINCS to "-pthread". I hope
this is a resonable location, there didn't appear to be a THREADCFLAGS
option.
As decribed, these three fixes allow the compiler to survive a complete
bootstrap, all languages except Ada and treelang, on my "modified"
alphaev67-dec-osf5.1, and atleast runs the testsuite with lots more
failures than with the default, --enable-threads=single.
Ok for mainline? And more importantly, if not, what should be done
differently. I now nothing of the build machinery, so your patience
is very much appreciated.
Many thanks in advance,
Roger
--
2003-06-26 Roger Sayle <roger@eyesopen.com>
PR bootstrap/9330
* config.gcc (alpha*-dec-osf*): Add alpha/t-osf-thread to tmake
if using posix pthreads.
* config/alpha/t-osf-thread: New file. Also use -pthread compiler
option when compiling libgcc.
* gthr-posix.h: Make sure _REENTRANT is defined before including
<pthread.h>.
libjava/
* configure.in: Add -pthread to THREADINCS if using posix threads
on alpha*-dec-osf5*.
* configure: Regenerate.
Index: config.gcc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config.gcc,v
retrieving revision 1.325
diff -c -3 -p -r1.325 config.gcc
*** config.gcc 18 Jun 2003 16:36:10 -0000 1.325
--- config.gcc 23 Jun 2003 20:49:55 -0000
*************** alpha*-dec-osf[45]*)
*** 606,611 ****
--- 606,617 ----
target_cpu_default=MASK_SUPPORT_ARCH
;;
esac
+ case x${enable_threads} in
+ xpthreads | xposix)
+ thread_file='posix'
+ tmake_file="${tmake_file} alpha/t-osf-thread"
+ ;;
+ esac
;;
alpha64-dec-*vms*)
tm_file="${tm_file} alpha/vms.h alpha/vms64.h"
*** /dev/null Mon Jun 23 14:17:24 2003
--- config/alpha/t-osf-thread Mon Jun 23 14:19:09 2003
***************
*** 0 ****
--- 1,3 ----
+ # This is currently needed to compile libgcc2 for pthreads support
+ TARGET_LIBGCC2_CFLAGS=-pthread
+
Index: gthr-posix.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gthr-posix.h,v
retrieving revision 1.26
diff -c -3 -p -r1.26 gthr-posix.h
*** gthr-posix.h 16 Dec 2002 18:19:37 -0000 1.26
--- gthr-posix.h 23 Jun 2003 23:02:50 -0000
*************** Software Foundation, 59 Temple Place - S
*** 34,39 ****
--- 34,44 ----
#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>
Index: configure.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/configure.in,v
retrieving revision 1.157
diff -c -3 -p -r1.157 configure.in
*** configure.in 17 Jun 2003 15:56:07 -0000 1.157
--- configure.in 24 Jun 2003 14:54:09 -0000
*************** changequote([,])
*** 466,471 ****
--- 466,476 ----
THREADLDFLAGS=-pthread
THREADSPEC=-lc_r
;;
+ alpha*-dec-osf5*)
+ THREADINCS=-pthread
+ THREADLIBS=-lpthread
+ THREADSPEC=-lpthread
+ ;;
*)
THREADLIBS=-lpthread
THREADSPEC=-lpthread
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833