diff mbox

[build] Move gthr to toplevel libgcc

Message ID yddr54wrp4q.fsf@manam.CeBiTec.Uni-Bielefeld.DE
State New
Headers show

Commit Message

Rainer Orth Aug. 8, 2011, 1:47 p.m. UTC
This patch moves gthr*.h and related code to toplevel libgcc.  Unlike
the other outstanding patches (libgcc1, libgcc2, crtstuff, shlib), it is
pretty independent from the rest, so I'm posting it first.  It was
developed last, so there may be conflicts (gcc/Makefile.in).  It also
depends on the posix95 removal patch.

Instead of cluttering the libgcc directory, all non-generic gthr-*.h
files were moved to their respecitive positions in libgcc/config.  The
patch simplifies gthr.h quite a bit:

* It does away with the need for thread-specific defines:

** HAVE_GTHR_DEFAULT is removed, instead I always create gthr-default.h,
   even if only as a link to gthr-single.h.  That simplifies the calling
   runtime libs which don't need to re-determine that value.

** There's no need to treat gthr-tpf.h specially: tpf is the
   only/default model on s390x-ibm-tpf*, so this can be handled by the
   default case.

** The use of _PTHREADS to select gthr-posix.h is quite inconsistent:
   only a few targets define that macro (m32r/linux.h, mn10300/linux.h,
   netbsd.h, sh/linux.h, sol2.h), and none of them support alternative
   thread models.  Given that everything works fine for every other
   Linux target suggests that this can go.

** _DCE_THREADS is used to select gthr-dce.h, but again dce is the
   only/default model on hppa[12]*-*-hpux10* (pa-hpux10.h), so the
   special-casing can be removed.

** Since gthr-default.h points to gthr-single.h if nothing else, that
   explicit fallback can be removed.

I noticed that config/t-vxworks installs gthr-vxworks.h, gthr-default.h
via EXTRA_HEADERS, but the comment suggests this is only for the benefit
of the runtime libs which know how to find them, so I've removed that.

The gthr*.h headers have GCC_GTHR_* guards right now.  With the move,
one might want to change them to LIBGCC_GTHR_*.  If so, one needs to adapt
libstdc++-v3/include/Makefile.am.  I haven't touched this yet.

The target libraries using gthr.h (libgfortran, libobjc, libstdc++-v3)
need to be adapted to search both libgcc source (for gthr.h etc.) and
build (for gthr-default.h) directories.

I haven't moved two macros used in gthr*.h yet: GTHREAD_USE_WEAK and
SUPPORTS_WEAK.  This seems to warrant a separate followup patch, but for
the record I report my findings:

* GTHREAD_USE_WEAK must be defined explicitly.  It needs to be poisoned
  in system.h after the move.  Right now, only a few targets defined a
  non-default value:

  darwin.h		#define GTHREAD_USE_WEAK 0
  i386/cygwin.h		#define GTHREAD_USE_WEAK 0

  ia64/hpux.h		#define GTHREAD_USE_WEAK 0
  pa/pa64-hpux.h	#define GTHREAD_USE_WEAK 0
  pa/som.h		#define GTHREAD_USE_WEAK 0
    
  The last 3 could be handled in a new hpux-lib.h, but perhaps this
  isn't necessary if ax_sys_weak_alias.m4 works.

* SUPPORTS_WEAK is probably best detected with autoconf.  We have
  libgfortran/acinclude.m4 (LIBGFOR_GTHREAD_WEAK), but should probably
  go for m4/ax_sys_weak_alias.m4 from the autoconf-archive instead.  If
  we're lucky, that macro can detect support for weak definitions and
  replace both SUPPORTS_WEAK and GTHREAD_USE_WEAK.

  We have only 2 non-default definitions right now:

  config/avr/avr.h	#define SUPPORTS_WEAK 1
  config/cris/cris.h	#define SUPPORTS_WEAK 1

  I have no idea why they are made explicit; both are already correct
  from the default in elfos.h (ASM_WEAKEN_LABEL) from what I can see.

  A really ugly point in the gthr.h interface is that all users need to
  define SUPPORTS_WEAK and GTHREAD_USE_WEAK themselves.  It would be far
  better to substitute the result of such a test into gthr.h to avoid
  this complication.

  Currently, this is handled quite inconsistently: libobjc does nothing,
  libstdc++-v3/acinclude.m4 (GLIBCXX_CHECK_GTHREADS) hardcodes
  SUPPORTS_WEAK, GTHREAD_USE_WEAK for posix threads, and
  libgfortran/acinclude.m4 (LIBGFOR_GTHREAD_WEAK) tries to determine a
  sensible value.

As I said, I'd like to handle this aspect in a followup patch and keep
the build part separate.

This patch was bootstrapped without regressions on i386-pc-solaris2.10
and i386-pc-solaris2.11.  It probably needs more testing on other
non-posix platforms.

Comments?

Thanks.
	Rainer


2011-08-06  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	gcc:
	* gthr-posix.h, gthr-single.h, gthr.h: Move to ../libgcc.
	* gthr-aix.h: Move to ../libgcc/config/rs6000.
	* gthr-dce.h: Move to ../libgcc/config/pa.
	* gthr-lynx.h: Move to ../libgcc/config.
	* gthr-mipssde.h: Move to ../libgcc/config/mips.
	* gthr-rtems.h: Move to ../libgcc/config.
	* gthr-tpf.h: Move to ../libgcc/config/s390.
	* gthr-vxworks.h: Move to ../libgcc/config.
	* gthr-win32.h: Move to ../libgcc/config/i386.
	* configure.ac (gthread_flags): Remove
	(gthr-default.h): Don't create.
	(thread_file): Don't substitute.
	* configure: Regenerate.
	* Makefile.in (GCC_THREAD_FILE): Remove.
	(GTHREAD_FLAGS): Remove.
	(libgcc.mvars): Remove GTHREAD_FLAGS.
	* config/m32r/linux.h (SUBTARGET_CPP_SPEC): Don't define _PTHREADS
	if -pthread.
	* config/mn10300/linux.h (CPP_SPEC): Likewise.
	* config/netbsd.h (NETBSD_CPP_SPEC): Likewise.
	* config/sh/linux.h (SUBTARGET_CPP_SPEC): Likewise.
	* config/sol2.h (CPP_SUBTARGET_SPEC): Likewise.
	* config/pa/pa-hpux10.h (CPP_SPEC): Don't define _DCE_THREADS if
	-threads.
	* config/t-vxworks (EXTRA_HEADERS): Remove.

	gcc/po:
	* EXCLUDES (gthr-aix.h, gthr-dce.h, gthr-posix.c, gthr-posix.h)
	(gthr-rtems.h, gthr-single.h, gthr-solaris.h, gthr-vxworks.h)
	(gthr-win32.h, gthr.h): Remove.

	libgcc:
	* gthr-posix.h, gthr-single.h, gthr.h: New files.
	* config/gthr-lynx.h, config/gthr-rtems.h, config/gthr-vxworks.h,
	config/i386/gthr-win32.h, config/mips/gthr-mipssde.h,
	config/pa/gthr-dce.h, config/rs6000/gthr-aix.h,
	config/s390/gthr-tpf.h: New files.
	* config/i386/gthr-win32.c: Include "gthr-win32.h".
	* config.host (thread_header, thread_dir): New variables.
	Set it depending on target_thread_file.
	* configure.ac (gthr-default.h): Link from $thread_header.
	* configure: Regenerate.
	* Makefile.in (LIBGCC2_CFLAGS): Remove $(GTHREAD_FLAGS).

	libgfortran:
	* Makefile.am (AM_CPPFLAGS): Add
	-I$(srcdir)/$(MULTISRCTOP)../libgcc, -I$(MULTIBUILDTOP)../libgcc.
	* Makefile.in: Regenerate.
	* acinclude.m4 (LIBGFOR_CHECK_GTHR_DEFAULT): Remove.
	* configure.ac (LIBGFOR_CHECK_GTHR_DEFAULT): Likewise.
	* configure: Regenerate.
	* config.h.in: Regenerate.

	libobjc:
	* Makefile.in (INCLUDES): Add -I$(MULTIBUILDTOP)../libgcc.
	* configure.ac (target_thread_file, HAVE_GTHR_DEFAULT): Remove.
	* configure: Regenerate.
	* config.h.in: Regenerate.

	libstdc++-v3:
	* acinclude.m4 (GLIBCXX_CONFIGURE): Determine and substitute
	toplevel_builddir.
	(GLIBCXX_ENABLE_THREADS): Remove glibcxx_thread_h,
	HAVE_GTHR_DEFAULT, enable_thread.
	(GLIBCXX_CHECK_GTHREADS): Reflect gthr move to libgcc.
	* include/Makefile.am (thread_host_headers): Remove
	${host_builddir}/gthr-tpf.h.
	(${host_builddir}/gthr.h): Reflect gthr move to libgcc.
	Use $<.
	(${host_builddir}/gthr-single.h): Likewise.
	(${host_builddir}/gthr-posix.h): Likewise.
	(${host_builddir}/gthr-tpf.h): Remove.
	(${host_builddir}/gthr-default.h): Likewise.
	* configure, config.h.in: Regenerate.
	* Makefile.in, doc/Makefile.in, include/Makefile.in,
	libsupc++/Makefile.in, po/Makefile.in, python/Makefile.in,
	src/Makefile.intestsuite/Makefile.in: Regenerate.

Comments

Paolo Bonzini Aug. 8, 2011, 2:57 p.m. UTC | #1
On 08/08/2011 03:47 PM, Rainer Orth wrote:
>
> This patch was bootstrapped without regressions on i386-pc-solaris2.10
> and i386-pc-solaris2.11.  It probably needs more testing on other
> non-posix platforms.

Did you include Ada?

Paolo
Rainer Orth Aug. 8, 2011, 2:58 p.m. UTC | #2
Paolo Bonzini <bonzini@gnu.org> writes:

> On 08/08/2011 03:47 PM, Rainer Orth wrote:
>>
>> This patch was bootstrapped without regressions on i386-pc-solaris2.10
>> and i386-pc-solaris2.11.  It probably needs more testing on other
>> non-posix platforms.
>
> Did you include Ada?

sure, all languages, even Go and Objective-C++.

	Rainer
Paolo Bonzini Aug. 8, 2011, 3:17 p.m. UTC | #3
On 08/08/2011 03:47 PM, Rainer Orth wrote:
> This patch moves gthr*.h and related code to toplevel libgcc.  Unlike
> the other outstanding patches (libgcc1, libgcc2, crtstuff, shlib), it is
> pretty independent from the rest, so I'm posting it first.  It was
> developed last, so there may be conflicts (gcc/Makefile.in).  It also
> depends on the posix95 removal patch.
>
> Instead of cluttering the libgcc directory, all non-generic gthr-*.h
> files were moved to their respecitive positions in libgcc/config.  The
> patch simplifies gthr.h quite a bit:
>
> * It does away with the need for thread-specific defines:
>
> ** HAVE_GTHR_DEFAULT is removed, instead I always create gthr-default.h,
>     even if only as a link to gthr-single.h.  That simplifies the calling
>     runtime libs which don't need to re-determine that value.

That's a good cleanup.

> ** The use of _PTHREADS to select gthr-posix.h is quite inconsistent:
>     only a few targets define that macro (m32r/linux.h, mn10300/linux.h,
>     netbsd.h, sh/linux.h, sol2.h), and none of them support alternative
>     thread models.  Given that everything works fine for every other
>     Linux target suggests that this can go.

_PTHREADS is used in the wild, I'm not sure about removing it from the 
specs, especially for netbsd.h and sol2.h.

> ** _DCE_THREADS is used to select gthr-dce.h, but again dce is the
>     only/default model on hppa[12]*-*-hpux10* (pa-hpux10.h), so the
>     special-casing can be removed.

Agreed, but again I'm not sure about removing it from the spec.

> I noticed that config/t-vxworks installs gthr-vxworks.h, gthr-default.h
> via EXTRA_HEADERS, but the comment suggests this is only for the benefit
> of the runtime libs which know how to find them, so I've removed that.

Looks good, but should also be added to changes.html.

> The gthr*.h headers have GCC_GTHR_* guards right now.  With the move,
> one might want to change them to LIBGCC_GTHR_*.  If so, one needs to adapt
> libstdc++-v3/include/Makefile.am.  I haven't touched this yet.

No hurry.

>    A really ugly point in the gthr.h interface is that all users need to
>    define SUPPORTS_WEAK and GTHREAD_USE_WEAK themselves.  It would be far
>    better to substitute the result of such a test into gthr.h to avoid
>    this complication.

Yes, and they can also be unified.  The advantage of toplevel libgcc 
move is that the configury becomes self-contained and it is "easy" to 
spot these historical problems...

>    Currently, this is handled quite inconsistently: libobjc does nothing,
>    libstdc++-v3/acinclude.m4 (GLIBCXX_CHECK_GTHREADS) hardcodes
>    SUPPORTS_WEAK, GTHREAD_USE_WEAK for posix threads, and
>    libgfortran/acinclude.m4 (LIBGFOR_GTHREAD_WEAK) tries to determine a
>    sensible value.

I think libgfortran's approach is the nicest to be added in 
libgcc/configure.ac.

> As I said, I'd like to handle this aspect in a followup patch and keep
> the build part separate.

That's fine.

Let's wait for result of testing, especially Win32 (Kai?).

Paolo
John David Anglin Aug. 8, 2011, 3:42 p.m. UTC | #4
On 8-Aug-11, at 9:47 AM, Rainer Orth wrote:

> ** _DCE_THREADS is used to select gthr-dce.h, but again dce is the
>   only/default model on hppa[12]*-*-hpux10* (pa-hpux10.h), so the
>   special-casing can be removed.

DCE threads and thread single are both supported.  There are multilibs
for both.  Different libraries are needed for threaded and non  
threaded programs,
and there is no mechanism to detect whether threads are active or not.

>
> I haven't moved two macros used in gthr*.h yet: GTHREAD_USE_WEAK and
> SUPPORTS_WEAK.  This seems to warrant a separate followup patch, but  
> for
> the record I report my findings:
>
> * GTHREAD_USE_WEAK must be defined explicitly.  It needs to be  
> poisoned
>  in system.h after the move.  Right now, only a few targets defined a
>  non-default value:
>
>  darwin.h		#define GTHREAD_USE_WEAK 0
>  i386/cygwin.h		#define GTHREAD_USE_WEAK 0
>
>  ia64/hpux.h		#define GTHREAD_USE_WEAK 0
>  pa/pa64-hpux.h	#define GTHREAD_USE_WEAK 0
>  pa/som.h		#define GTHREAD_USE_WEAK 0
>
>  The last 3 could be handled in a new hpux-lib.h, but perhaps this
>  isn't necessary if ax_sys_weak_alias.m4 works.

I'm not sure this is possible in general on HP-UX.

> * SUPPORTS_WEAK is probably best detected with autoconf.  We have
>  libgfortran/acinclude.m4 (LIBGFOR_GTHREAD_WEAK), but should probably
>  go for m4/ax_sys_weak_alias.m4 from the autoconf-archive instead.  If
>  we're lucky, that macro can detect support for weak definitions and
>  replace both SUPPORTS_WEAK and GTHREAD_USE_WEAK.

There are multiple meanings for SUPPORTS_WEAK.  Within the compiler,
SUPPORTS_WEAK implies that multiple definitions of code and data symbols
are possible.  At the moment, there is no need for undefined weak or  
weak
aliases.  The situation is different in the gthr* headers and compiled  
code
such as libgfortran.

On PA HP-UX, the compiler "weak" support is implemented using COMDAT
and secondary definitions.  Neither of these support undefined weak.

Dave
Paolo Bonzini Aug. 8, 2011, 3:49 p.m. UTC | #5
On 08/08/2011 05:42 PM, John David Anglin wrote:
>
>
>> ** _DCE_THREADS is used to select gthr-dce.h, but again dce is the
>> only/default model on hppa[12]*-*-hpux10* (pa-hpux10.h), so the
>> special-casing can be removed.
>
> DCE threads and thread single are both supported.  There are
> multilibs for both.  Different libraries are needed for threaded and
> non threaded programs, and there is no mechanism to detect whether
> threads are active or not.

Rainer used _REENTRANT for that, because it's already in the spec.  Is 
that ok?

Paolo
Rainer Orth Aug. 8, 2011, 3:51 p.m. UTC | #6
Paolo Bonzini <bonzini@gnu.org> writes:

>> ** The use of _PTHREADS to select gthr-posix.h is quite inconsistent:
>>     only a few targets define that macro (m32r/linux.h, mn10300/linux.h,
>>     netbsd.h, sh/linux.h, sol2.h), and none of them support alternative
>>     thread models.  Given that everything works fine for every other
>>     Linux target suggests that this can go.
>
> _PTHREADS is used in the wild, I'm not sure about removing it from the
> specs, especially for netbsd.h and sol2.h.

Given it's inconsistent definition across platforms and the fact that
it's an implementation artefact, I'd argue for removing it.  I've just
did a google search and there aren't too many uses, many of them
misguided or using constructs like defined(_REENTRANT) ||
defined(_PTHREADS) which continue to work.  Of course we should announce
this, together with the posix95 removal.

>> ** _DCE_THREADS is used to select gthr-dce.h, but again dce is the
>>     only/default model on hppa[12]*-*-hpux10* (pa-hpux10.h), so the
>>     special-casing can be removed.
>
> Agreed, but again I'm not sure about removing it from the spec.

I could find no use outside of gthr.h/gthr-dce.h, and the platform is
old (I may say so, being the keeper of historical OSes myself :-).

>> I noticed that config/t-vxworks installs gthr-vxworks.h, gthr-default.h
>> via EXTRA_HEADERS, but the comment suggests this is only for the benefit
>> of the runtime libs which know how to find them, so I've removed that.
>
> Looks good, but should also be added to changes.html.

Agreed.

>>    A really ugly point in the gthr.h interface is that all users need to
>>    define SUPPORTS_WEAK and GTHREAD_USE_WEAK themselves.  It would be far
>>    better to substitute the result of such a test into gthr.h to avoid
>>    this complication.
>
> Yes, and they can also be unified.  The advantage of toplevel libgcc move
> is that the configury becomes self-contained and it is "easy" to spot these
> historical problems...

Right: nobody in his right mind would look at this stuff otherwise :-)

>>    Currently, this is handled quite inconsistently: libobjc does nothing,
>>    libstdc++-v3/acinclude.m4 (GLIBCXX_CHECK_GTHREADS) hardcodes
>>    SUPPORTS_WEAK, GTHREAD_USE_WEAK for posix threads, and
>>    libgfortran/acinclude.m4 (LIBGFOR_GTHREAD_WEAK) tries to determine a
>>    sensible value.
>
> I think libgfortran's approach is the nicest to be added in
> libgcc/configure.ac.

I'm not convinced: when it was introduced (or used more extensively), I
was already bitten by the fact that the GTHREAD_USE_WEAK test uses a
hardcoded list, instead of really checking what it is meant to test:
support for weak definitions.  Perhaps the autoconf-archive macro is
better in this respect.

>> As I said, I'd like to handle this aspect in a followup patch and keep
>> the build part separate.
>
> That's fine.
>
> Let's wait for result of testing, especially Win32 (Kai?).

Certainly: this is far too risky with testing only on posix systems.

Thanks.
        Rainer
Rainer Orth Aug. 8, 2011, 3:53 p.m. UTC | #7
Paolo Bonzini <bonzini@gnu.org> writes:

> On 08/08/2011 05:42 PM, John David Anglin wrote:
>>
>>
>>> ** _DCE_THREADS is used to select gthr-dce.h, but again dce is the
>>> only/default model on hppa[12]*-*-hpux10* (pa-hpux10.h), so the
>>> special-casing can be removed.
>>
>> DCE threads and thread single are both supported.  There are
>> multilibs for both.  Different libraries are needed for threaded and
>> non threaded programs, and there is no mechanism to detect whether
>> threads are active or not.
>
> Rainer used _REENTRANT for that, because it's already in the spec.  Is that
> ok?

I could find no indication that HP-UX 10 supported anything but DCE
threads (especially no POSIX threads), so _REENTRANT being defined must
meant DCE threads, unless I'm mistaken.

	Rainer
Paolo Bonzini Aug. 8, 2011, 3:55 p.m. UTC | #8
On 08/08/2011 05:51 PM, Rainer Orth wrote:
>>>     libgfortran/acinclude.m4 (LIBGFOR_GTHREAD_WEAK) tries to determine a
>>>      sensible value.
>>
>>  I think libgfortran's approach is the nicest to be added in
>>  libgcc/configure.ac.
>
> I'm not convinced: when it was introduced (or used more extensively), I
> was already bitten by the fact that the GTHREAD_USE_WEAK test uses a
> hardcoded list, instead of really checking what it is meant to test:
> support for weak definitions.  Perhaps the autoconf-archive macro is
> better in this respect.

I was talking in general about the approach, not the implementation. :)

Paolo
Rainer Orth Aug. 8, 2011, 3:56 p.m. UTC | #9
Paolo Bonzini <bonzini@gnu.org> writes:

> On 08/08/2011 05:51 PM, Rainer Orth wrote:
>>>>     libgfortran/acinclude.m4 (LIBGFOR_GTHREAD_WEAK) tries to determine a
>>>>      sensible value.
>>>
>>>  I think libgfortran's approach is the nicest to be added in
>>>  libgcc/configure.ac.
>>
>> I'm not convinced: when it was introduced (or used more extensively), I
>> was already bitten by the fact that the GTHREAD_USE_WEAK test uses a
>> hardcoded list, instead of really checking what it is meant to test:
>> support for weak definitions.  Perhaps the autoconf-archive macro is
>> better in this respect.
>
> I was talking in general about the approach, not the implementation. :)

I see.  You're right, of course: it's much better to test for the
feature than keep lists of targets supporting it :-)

	Rainer
John David Anglin Aug. 8, 2011, 4:14 p.m. UTC | #10
On 8-Aug-11, at 11:53 AM, Rainer Orth wrote:

> Paolo Bonzini <bonzini@gnu.org> writes:
>
>> On 08/08/2011 05:42 PM, John David Anglin wrote:
>>>
>>>
>>>> ** _DCE_THREADS is used to select gthr-dce.h, but again dce is the
>>>> only/default model on hppa[12]*-*-hpux10* (pa-hpux10.h), so the
>>>> special-casing can be removed.
>>>
>>> DCE threads and thread single are both supported.  There are
>>> multilibs for both.  Different libraries are needed for threaded and
>>> non threaded programs, and there is no mechanism to detect whether
>>> threads are active or not.
>>
>> Rainer used _REENTRANT for that, because it's already in the spec.   
>> Is that
>> ok?
>
> I could find no indication that HP-UX 10 supported anything but DCE
> threads (especially no POSIX threads), so _REENTRANT being defined  
> must
> meant DCE threads, unless I'm mistaken.

_REENTRANT doesn't imply DCE threads.  The reentrant routines were added
to the non threaded version of libc in HP-UX 10 in preparation for the  
transition
to POSIX threads in HP-UX 11.  We define _REENTRANT under other
circumstances in pa-hpux10.h as the reentrant routines are needed for  
libgfortran,
etc.

The multilib thread setup is done in t-dce-thr.

Dave
Rainer Orth Aug. 8, 2011, 4:24 p.m. UTC | #11
John David Anglin <dave.anglin@nrc-cnrc.gc.ca> writes:

>> I could find no indication that HP-UX 10 supported anything but DCE
>> threads (especially no POSIX threads), so _REENTRANT being defined must
>> meant DCE threads, unless I'm mistaken.
>
> _REENTRANT doesn't imply DCE threads.  The reentrant routines were added
> to the non threaded version of libc in HP-UX 10 in preparation for the
> transition
> to POSIX threads in HP-UX 11.  We define _REENTRANT under other
> circumstances in pa-hpux10.h as the reentrant routines are needed for
> libgfortran,
> etc.

One could argue that it's the responsibility of libgfortran to do so if
necessary, though.

But ok, I'll restore the definition and use of _DCE_THREADS in
pa-hpux10.h and gthr-dce.h.

Could you test the patch with those changes, please?

Thanks.
        Rainer
Rainer Orth Aug. 8, 2011, 4:29 p.m. UTC | #12
John David Anglin <dave.anglin@nrc-cnrc.gc.ca> writes:

>> I haven't moved two macros used in gthr*.h yet: GTHREAD_USE_WEAK and
>> SUPPORTS_WEAK.  This seems to warrant a separate followup patch, but for
>> the record I report my findings:
>>
>> * GTHREAD_USE_WEAK must be defined explicitly.  It needs to be poisoned
>>  in system.h after the move.  Right now, only a few targets defined a
>>  non-default value:
>>
>>  darwin.h		#define GTHREAD_USE_WEAK 0
>>  i386/cygwin.h		#define GTHREAD_USE_WEAK 0
>>
>>  ia64/hpux.h		#define GTHREAD_USE_WEAK 0
>>  pa/pa64-hpux.h	#define GTHREAD_USE_WEAK 0
>>  pa/som.h		#define GTHREAD_USE_WEAK 0
>>
>>  The last 3 could be handled in a new hpux-lib.h, but perhaps this
>>  isn't necessary if ax_sys_weak_alias.m4 works.
>
> I'm not sure this is possible in general on HP-UX.

Do you suggest that support for weak definitions (undefined weak) cannot
be detected by a configure test on HP-UX?

>> * SUPPORTS_WEAK is probably best detected with autoconf.  We have
>>  libgfortran/acinclude.m4 (LIBGFOR_GTHREAD_WEAK), but should probably
>>  go for m4/ax_sys_weak_alias.m4 from the autoconf-archive instead.  If
>>  we're lucky, that macro can detect support for weak definitions and
>>  replace both SUPPORTS_WEAK and GTHREAD_USE_WEAK.
>
> There are multiple meanings for SUPPORTS_WEAK.  Within the compiler,
> SUPPORTS_WEAK implies that multiple definitions of code and data symbols
> are possible.  At the moment, there is no need for undefined weak or weak
> aliases.  The situation is different in the gthr* headers and compiled code
> such as libgfortran.

I was only talking about autoconfiguring the equivalent of SUPPORTS_WEAK
&& GTHREAD_USE_WEAK in the target libraries that need it.  There will be
no change in gcc/config, of course.

> On PA HP-UX, the compiler "weak" support is implemented using COMDAT
> and secondary definitions.  Neither of these support undefined weak.

The latter is also missing on Tru64 UNIX, so I'm working on such a
platform myself and have introduced gthr-posix.c to deal with it.

	Rainer
John David Anglin Aug. 8, 2011, 5:04 p.m. UTC | #13
On 8-Aug-11, at 12:29 PM, Rainer Orth wrote:

> John David Anglin <dave.anglin@nrc-cnrc.gc.ca> writes:
>
>>> I haven't moved two macros used in gthr*.h yet: GTHREAD_USE_WEAK and
>>> SUPPORTS_WEAK.  This seems to warrant a separate followup patch,  
>>> but for
>>> the record I report my findings:
>>>
>>> * GTHREAD_USE_WEAK must be defined explicitly.  It needs to be  
>>> poisoned
>>> in system.h after the move.  Right now, only a few targets defined a
>>> non-default value:
>>>
>>> darwin.h		#define GTHREAD_USE_WEAK 0
>>> i386/cygwin.h		#define GTHREAD_USE_WEAK 0
>>>
>>> ia64/hpux.h		#define GTHREAD_USE_WEAK 0
>>> pa/pa64-hpux.h	#define GTHREAD_USE_WEAK 0
>>> pa/som.h		#define GTHREAD_USE_WEAK 0
>>>
>>> The last 3 could be handled in a new hpux-lib.h, but perhaps this
>>> isn't necessary if ax_sys_weak_alias.m4 works.
>>
>> I'm not sure this is possible in general on HP-UX.
>
> Do you suggest that support for weak definitions (undefined weak)  
> cannot
> be detected by a configure test on HP-UX?

Undefined weak support can be detected with a simple link test.

The situation with aliases is more complex.

Dave
Hans-Peter Nilsson Aug. 9, 2011, 1:52 a.m. UTC | #14
On Mon, 8 Aug 2011, Rainer Orth wrote:
> * SUPPORTS_WEAK is probably best detected with autoconf.  We have
>   libgfortran/acinclude.m4 (LIBGFOR_GTHREAD_WEAK), but should probably
>   go for m4/ax_sys_weak_alias.m4 from the autoconf-archive instead.  If
>   we're lucky, that macro can detect support for weak definitions and
>   replace both SUPPORTS_WEAK and GTHREAD_USE_WEAK.
>
>   We have only 2 non-default definitions right now:
>
>   config/avr/avr.h	#define SUPPORTS_WEAK 1
>   config/cris/cris.h	#define SUPPORTS_WEAK 1
>
>   I have no idea why they are made explicit; both are already correct
>   from the default in elfos.h (ASM_WEAKEN_LABEL) from what I can see.

For CRIS, history, IIRC.  There used to be a cris-aout port as
well, which mattered in some way, and even a unified
elf-and-a.out-port.  Possibly the default SUPPORTS_WEAK was
different too then.

brgds, H-P
Rainer Orth Aug. 9, 2011, 12:01 p.m. UTC | #15
Hans-Peter Nilsson <hp@bitrange.com> writes:

> On Mon, 8 Aug 2011, Rainer Orth wrote:
>> * SUPPORTS_WEAK is probably best detected with autoconf.  We have
>>   libgfortran/acinclude.m4 (LIBGFOR_GTHREAD_WEAK), but should probably
>>   go for m4/ax_sys_weak_alias.m4 from the autoconf-archive instead.  If
>>   we're lucky, that macro can detect support for weak definitions and
>>   replace both SUPPORTS_WEAK and GTHREAD_USE_WEAK.
>>
>>   We have only 2 non-default definitions right now:
>>
>>   config/avr/avr.h	#define SUPPORTS_WEAK 1
>>   config/cris/cris.h	#define SUPPORTS_WEAK 1
>>
>>   I have no idea why they are made explicit; both are already correct
>>   from the default in elfos.h (ASM_WEAKEN_LABEL) from what I can see.
>
> For CRIS, history, IIRC.  There used to be a cris-aout port as
> well, which mattered in some way, and even a unified
> elf-and-a.out-port.  Possibly the default SUPPORTS_WEAK was
> different too then.

I see, thanks.  I'll probably just remove it when I get around to the
macro part of the gthr move, unless you beat me to it.

	Rainer
Nathan Sidwell Aug. 21, 2011, 7:44 p.m. UTC | #16
On 08/08/11 08:47, Rainer Orth wrote:
> This patch moves gthr*.h and related code to toplevel libgcc.  Unlike
> the other outstanding patches (libgcc1, libgcc2, crtstuff, shlib), it is
> pretty independent from the rest, so I'm posting it first.  It was
> developed last, so there may be conflicts (gcc/Makefile.in).  It also
> depends on the posix95 removal patch.
>
> Instead of cluttering the libgcc directory, all non-generic gthr-*.h
> files were moved to their respecitive positions in libgcc/config.  The
> patch simplifies gthr.h quite a bit:


> 2011-08-06  Rainer Orth<ro@CeBiTec.Uni-Bielefeld.DE>
>
> 	gcc:

> 	* gthr-vxworks.h: Move to ../libgcc/config.

A fine idea, I have no objections.

nathan
diff mbox

Patch

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -527,9 +527,7 @@  lang_opt_files=@lang_opt_files@ $(srcdir
 lang_specs_files=@lang_specs_files@
 lang_tree_files=@lang_tree_files@
 target_cpu_default=@target_cpu_default@
-GCC_THREAD_FILE=@thread_file@
 OBJC_BOEHM_GC=@objc_boehm_gc@
-GTHREAD_FLAGS=@gthread_flags@
 extra_modes_file=@extra_modes_file@
 extra_opt_files=@extra_opt_files@
 host_hook_obj=@out_host_hook_obj@
@@ -1784,7 +1782,6 @@  libgcc-support: libgcc.mvars stmp-int-hd
 libgcc.mvars: config.status Makefile specs xgcc$(exeext)
 	: > tmp-libgcc.mvars
 	echo GCC_CFLAGS = '$(GCC_CFLAGS)' >> tmp-libgcc.mvars
-	echo GTHREAD_FLAGS = '$(GTHREAD_FLAGS)' >> tmp-libgcc.mvars
 	echo INHIBIT_LIBC_CFLAGS = '$(INHIBIT_LIBC_CFLAGS)' >> tmp-libgcc.mvars
 	echo TARGET_SYSTEM_ROOT = '$(TARGET_SYSTEM_ROOT)' >> tmp-libgcc.mvars
 
diff --git a/gcc/config/m32r/linux.h b/gcc/config/m32r/linux.h
--- a/gcc/config/m32r/linux.h
+++ b/gcc/config/m32r/linux.h
@@ -84,7 +84,7 @@ 
 #undef  SUBTARGET_CPP_SPEC
 #define SUBTARGET_CPP_SPEC "\
    %{posix:-D_POSIX_SOURCE} \
-   %{pthread:-D_REENTRANT -D_PTHREADS} \
+   %{pthread:-D_REENTRANT} \
 "
                                                                                 
 #define TARGET_OS_CPP_BUILTINS() GNU_USER_TARGET_OS_CPP_BUILTINS()
diff --git a/gcc/config/mn10300/linux.h b/gcc/config/mn10300/linux.h
--- a/gcc/config/mn10300/linux.h
+++ b/gcc/config/mn10300/linux.h
@@ -28,7 +28,7 @@ 
 #undef  CPP_SPEC
 #define CPP_SPEC "%{mam33:-D__AM33__} %{!mam33:-D__AM33__=2 -D__AM33_2__} \
   %{posix:-D_POSIX_SOURCE} \
-  %{pthread:-D_REENTRANT -D_PTHREADS}"
+  %{pthread:-D_REENTRANT}"
 
 #undef  ASM_SPEC
 #define ASM_SPEC ""
diff --git a/gcc/config/netbsd.h b/gcc/config/netbsd.h
--- a/gcc/config/netbsd.h
+++ b/gcc/config/netbsd.h
@@ -33,7 +33,7 @@  along with GCC; see the file COPYING3.  
 /* CPP_SPEC parts common to all NetBSD targets.  */
 #define NETBSD_CPP_SPEC				\
   "%{posix:-D_POSIX_SOURCE} \
-   %{pthread:-D_REENTRANT -D_PTHREADS}"
+   %{pthread:-D_REENTRANT}"
 
 /* NETBSD_NATIVE is defined when gcc is integrated into the NetBSD
    source tree so it can be configured appropriately without using
diff --git a/gcc/config/pa/pa-hpux10.h b/gcc/config/pa/pa-hpux10.h
--- a/gcc/config/pa/pa-hpux10.h
+++ b/gcc/config/pa/pa-hpux10.h
@@ -1,6 +1,6 @@ 
 /* Definitions of target machine for GNU compiler, for HP PA-RISC
    Copyright (C) 1995, 1996, 1997, 2000, 2001, 2002, 2003, 2004,
-   2007, 2008, 2010 Free Software Foundation, Inc.
+   2007, 2008, 2010, 2011 Free Software Foundation, Inc.
    Contributed by Tim Moore (moore@defmacro.cs.utah.edu)
 
 This file is part of GCC.
@@ -77,7 +77,7 @@  along with GCC; see the file COPYING3.  
     }									\
   while (0)
 
-#define CPP_SPEC "%{threads: -D_REENTRANT -D_DCE_THREADS}"
+#define CPP_SPEC "%{threads: -D_REENTRANT}"
 
 /* We can debug dynamically linked executables on hpux9; we also want
    dereferencing of a NULL pointer to cause a SEGV.  */
diff --git a/gcc/config/sh/linux.h b/gcc/config/sh/linux.h
--- a/gcc/config/sh/linux.h
+++ b/gcc/config/sh/linux.h
@@ -28,7 +28,7 @@  along with GCC; see the file COPYING3.  
 #undef SUBTARGET_CPP_SPEC
 #define SUBTARGET_CPP_SPEC "\
    %{posix:-D_POSIX_SOURCE} \
-   %{pthread:-D_REENTRANT -D_PTHREADS} \
+   %{pthread:-D_REENTRANT} \
 "
 
 #define TARGET_OS_CPP_BUILTINS() \
diff --git a/gcc/config/sol2.h b/gcc/config/sol2.h
--- a/gcc/config/sol2.h
+++ b/gcc/config/sol2.h
@@ -72,8 +72,7 @@  along with GCC; see the file COPYING3.  
 #define UINTPTR_TYPE (LONG_TYPE_SIZE == 64 ? "long unsigned int" : "unsigned int")
 
 #undef CPP_SUBTARGET_SPEC
-#define CPP_SUBTARGET_SPEC "\
-%{pthreads|pthread:-D_REENTRANT -D_PTHREADS}"
+#define CPP_SUBTARGET_SPEC "%{pthreads|pthread:-D_REENTRANT}"
 
 /* Names to predefine in the preprocessor for this target machine.  */
 #define TARGET_SUB_OS_CPP_BUILTINS()
diff --git a/gcc/config/t-vxworks b/gcc/config/t-vxworks
--- a/gcc/config/t-vxworks
+++ b/gcc/config/t-vxworks
@@ -17,10 +17,6 @@ 
 # along with GCC; see the file COPYING3.  If not see
 # <http://www.gnu.org/licenses/>.
 
-# Some runtime modules need these.  Can't set extra_headers in config.gcc
-# because the paths are always made absolute to the cpu config dir.
-EXTRA_HEADERS += $(srcdir)/gthr-vxworks.h gthr-default.h
-
 # Both the kernel and RTP headers provide limits.h.
 LIMITS_H_TEST = true
 
diff --git a/gcc/configure.ac b/gcc/configure.ac
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -1370,19 +1370,6 @@  if test x${thread_file} = x; then
   thread_file=${target_thread_file}
 fi
 
-# Make gthr-default.h if we have a thread file.
-gthread_flags=
-if test $thread_file != single; then
-  echo "#include \"gthr-${thread_file}.h\"" > gthr-default.h-t
-  if diff gthr-default.h-t gthr-default.h 2>/dev/null; then
-    rm -f gthr-default.h-t
-  else
-    mv -f gthr-default.h-t gthr-default.h
-  fi
-  gthread_flags=-DHAVE_GTHR_DEFAULT
-fi
-AC_SUBST(gthread_flags)
-
 # --------
 # UNSORTED
 # --------
@@ -4883,7 +4870,6 @@  AC_SUBST(out_file)
 AC_SUBST(out_object_file)
 AC_SUBST(common_out_file)
 AC_SUBST(common_out_object_file)
-AC_SUBST(thread_file)
 AC_SUBST(tm_file_list)
 AC_SUBST(tm_include_list)
 AC_SUBST(tm_defines)
diff --git a/gcc/po/EXCLUDES b/gcc/po/EXCLUDES
--- a/gcc/po/EXCLUDES
+++ b/gcc/po/EXCLUDES
@@ -24,16 +24,6 @@ 
 #   These files are part of libgcc, or target headers provided by gcc.
 gcov-io.h
 gcov-iov.c
-gthr-aix.h
-gthr-dce.h
-gthr-posix.c
-gthr-posix.h
-gthr-rtems.h
-gthr-single.h
-gthr-solaris.h
-gthr-vxworks.h
-gthr-win32.h
-gthr.h
 limitx.h
 limity.h
 
diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in
--- a/libgcc/Makefile.in
+++ b/libgcc/Makefile.in
@@ -223,8 +223,7 @@  endif
 #
 LIBGCC2_DEBUG_CFLAGS = -g
 LIBGCC2_CFLAGS = -O2 $(LIBGCC2_INCLUDES) $(GCC_CFLAGS) $(HOST_LIBGCC2_CFLAGS) \
-		 $(LIBGCC2_DEBUG_CFLAGS) $(GTHREAD_FLAGS) \
-		 -DIN_LIBGCC2 \
+		 $(LIBGCC2_DEBUG_CFLAGS) -DIN_LIBGCC2 \
 		 -fbuilding-libgcc -fno-stack-protector \
 		 $(INHIBIT_LIBC_CFLAGS)
 
diff --git a/libgcc/config.host b/libgcc/config.host
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -64,6 +64,7 @@ 
 #			built for the target, not the host.  These files
 #			are relative to $srcdir/config and must not have
 #			the same names as files in $srcdir/../gcc/config.
+#  thread_header	The name of the header file for the thread model used.
 #  unwind_header	The name of the header file declaring the unwind
 #			runtime interface routines.
 
@@ -72,6 +73,7 @@  enable_execute_stack=
 extra_parts=
 tmake_file=
 tm_file=
+thread_header=
 md_unwind_header=no-unwind.h
 unwind_header=unwind-generic.h
 
@@ -283,6 +285,38 @@  i[34567]86-*-mingw* | x86_64-*-mingw*)
   ;;
 esac
 
+# Map from thread model to thread header.
+thread_dir=
+case $target_thread_file in
+    aix)
+	thread_dir=config/rs6000/
+	;;
+    dce)
+	thread_dir=config/pa/
+	;;
+    lynx)
+	thread_dir=config/
+	;;
+    mipssde)
+	thread_dir=config/mips/
+	;;
+    posix | single)
+	;;
+    rtems)
+	thread_dir=config/
+	;;
+    tpf)
+	thread_dir=config/s390/
+	;;
+    vxworks)
+	thread_dir=config/
+	;;
+    win32)
+	thread_dir=config/i386/
+	;;
+esac
+thread_header=${thread_dir}gthr-${target_thread_file}.h
+
 case ${host} in
 alpha*-*-linux*)
 	tmake_file="${tmake_file} alpha/t-alpha alpha/t-ieee t-crtfm alpha/t-linux"
diff --git a/gcc/gthr-lynx.h b/libgcc/config/gthr-lynx.h
rename from gcc/gthr-lynx.h
rename to libgcc/config/gthr-lynx.h
diff --git a/gcc/gthr-rtems.h b/libgcc/config/gthr-rtems.h
rename from gcc/gthr-rtems.h
rename to libgcc/config/gthr-rtems.h
diff --git a/gcc/gthr-vxworks.h b/libgcc/config/gthr-vxworks.h
rename from gcc/gthr-vxworks.h
rename to libgcc/config/gthr-vxworks.h
diff --git a/libgcc/config/i386/gthr-win32.c b/libgcc/config/i386/gthr-win32.c
--- a/libgcc/config/i386/gthr-win32.c
+++ b/libgcc/config/i386/gthr-win32.c
@@ -1,7 +1,8 @@ 
 /* Implementation of W32-specific threads compatibility routines for
    libgcc2.  */
 
-/* Copyright (C) 1999, 2000, 2002, 2004, 2008, 2009 Free Software Foundation, Inc.
+/* Copyright (C) 1999, 2000, 2002, 2004, 2008, 2009, 2011
+   Free Software Foundation, Inc.
    Contributed by Mumit Khan <khan@xraylith.wisc.edu>.
    Modified and moved to separate file by Danny Smith
    <dannysmith@users.sourceforge.net>.
@@ -33,7 +34,7 @@  see the files COPYING3 and COPYING.RUNTI
 #endif
 #undef  __GTHREAD_I486_INLINE_LOCK_PRIMITIVES
 #define __GTHREAD_I486_INLINE_LOCK_PRIMITIVES
-#include <gthr-win32.h>
+#include "gthr-win32.h"
 
 /* Windows32 threads specific definitions. The windows32 threading model
    does not map well into pthread-inspired gcc's threading model, and so 
diff --git a/gcc/gthr-win32.h b/libgcc/config/i386/gthr-win32.h
rename from gcc/gthr-win32.h
rename to libgcc/config/i386/gthr-win32.h
diff --git a/gcc/gthr-mipssde.h b/libgcc/config/mips/gthr-mipssde.h
rename from gcc/gthr-mipssde.h
rename to libgcc/config/mips/gthr-mipssde.h
diff --git a/gcc/gthr-dce.h b/libgcc/config/pa/gthr-dce.h
rename from gcc/gthr-dce.h
rename to libgcc/config/pa/gthr-dce.h
--- a/gcc/gthr-dce.h
+++ b/libgcc/config/pa/gthr-dce.h
@@ -1,6 +1,6 @@ 
 /* Threads compatibility routines for libgcc2 and libobjc.  */
 /* Compile this one with gcc.  */
-/* Copyright (C) 1997, 1999, 2000, 2001, 2004, 2005, 2008, 2009
+/* Copyright (C) 1997, 1999, 2000, 2001, 2004, 2005, 2008, 2009, 2011
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -27,10 +27,10 @@  see the files COPYING3 and COPYING.RUNTI
 #ifndef GCC_GTHR_DCE_H
 #define GCC_GTHR_DCE_H
 
-/* If _DCE_THREADS is not defined, then we're building the single
+/* If _REENTRANT is not defined, then we're building the single
    threaded version of the libraries and do not want to reference
    anything related to pthreads or dce.  */
-#ifndef _DCE_THREADS
+#ifndef _REENTRANT
 #include "gthr-single.h"
 #else
 /* DCE threads interface.
diff --git a/gcc/gthr-aix.h b/libgcc/config/rs6000/gthr-aix.h
rename from gcc/gthr-aix.h
rename to libgcc/config/rs6000/gthr-aix.h
diff --git a/gcc/gthr-tpf.h b/libgcc/config/s390/gthr-tpf.h
rename from gcc/gthr-tpf.h
rename to libgcc/config/s390/gthr-tpf.h
diff --git a/libgcc/configure.ac b/libgcc/configure.ac
--- a/libgcc/configure.ac
+++ b/libgcc/configure.ac
@@ -361,6 +361,7 @@  AC_CONFIG_LINKS([enable-execute-stack.c:
 AC_CONFIG_LINKS([unwind.h:$unwind_header])
 AC_CONFIG_LINKS([md-unwind-support.h:config/$md_unwind_header])
 AC_CONFIG_LINKS([sfp-machine.h:config/$sfp_machine_header])
+AC_CONFIG_LINKS([gthr-default.h:$thread_header])
 
 # We need multilib support.
 AC_CONFIG_FILES([Makefile])
diff --git a/gcc/gthr-posix.h b/libgcc/gthr-posix.h
rename from gcc/gthr-posix.h
rename to libgcc/gthr-posix.h
diff --git a/gcc/gthr-single.h b/libgcc/gthr-single.h
rename from gcc/gthr-single.h
rename to libgcc/gthr-single.h
diff --git a/gcc/gthr.h b/libgcc/gthr.h
rename from gcc/gthr.h
rename to libgcc/gthr.h
--- a/gcc/gthr.h
+++ b/libgcc/gthr.h
@@ -132,23 +132,8 @@  see the files COPYING3 and COPYING.RUNTI
                                              __gthread_recursive_mutex_t *mutex,
                                              const __gthread_time_t *abs_time)
 
-   Currently supported threads packages are
-     TPF threads with -D__tpf__
-     POSIX/Unix98 threads with -D_PTHREADS
-     DCE threads with -D_DCE_THREADS
-
 */
 
-/* Check first for thread specific defines.  */
-#if defined (__tpf__)
-#include "gthr-tpf.h"
-#elif _PTHREADS
-#include "gthr-posix.h"
-#elif _DCE_THREADS
-#include "gthr-dce.h"
-
-/* Include GTHREAD_FILE if one is defined.  */
-#elif defined(HAVE_GTHR_DEFAULT)
 #if SUPPORTS_WEAK
 #ifndef GTHREAD_USE_WEAK
 #define GTHREAD_USE_WEAK 1
@@ -156,11 +141,6 @@  see the files COPYING3 and COPYING.RUNTI
 #endif
 #include "gthr-default.h"
 
-/* Fallback to single thread definitions.  */
-#else
-#include "gthr-single.h"
-#endif
-
 #ifndef HIDE_EXPORTS
 #pragma GCC visibility pop
 #endif
diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am
--- a/libgfortran/Makefile.am
+++ b/libgfortran/Makefile.am
@@ -56,7 +56,9 @@  libcaf_single_la_LINK = $(LINK) $(libcaf
 ## use -iquote
 AM_CPPFLAGS = -iquote$(srcdir)/io -I$(srcdir)/$(MULTISRCTOP)../gcc \
 	      -I$(srcdir)/$(MULTISRCTOP)../gcc/config $(LIBQUADINCLUDE) \
-	      -I$(MULTIBUILDTOP)../../$(host_subdir)/gcc
+	      -I$(MULTIBUILDTOP)../../$(host_subdir)/gcc \
+	      -I$(srcdir)/$(MULTISRCTOP)../libgcc \
+	      -I$(MULTIBUILDTOP)../libgcc
 
 # Fortran rules for complex multiplication and division
 AM_CFLAGS += -fcx-fortran-rules
diff --git a/libgfortran/acinclude.m4 b/libgfortran/acinclude.m4
--- a/libgfortran/acinclude.m4
+++ b/libgfortran/acinclude.m4
@@ -83,17 +83,6 @@  if (foovar > 10) return __sync_add_and_f
 	      [Define to 1 if the target supports __sync_fetch_and_add])
   fi])
 
-dnl Check if threads are supported.
-AC_DEFUN([LIBGFOR_CHECK_GTHR_DEFAULT], [
-  AC_CACHE_CHECK([configured target thread model],
-		 libgfor_cv_target_thread_file, [
-libgfor_cv_target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`])
-
-  if test $libgfor_cv_target_thread_file != single; then
-    AC_DEFINE(HAVE_GTHR_DEFAULT, 1,
-	      [Define if the compiler has a thread header that is non single.])
-  fi])
-
 dnl Check for pragma weak.
 AC_DEFUN([LIBGFOR_GTHREAD_WEAK], [
   AC_CACHE_CHECK([whether pragma weak works],
diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac
--- a/libgfortran/configure.ac
+++ b/libgfortran/configure.ac
@@ -550,9 +550,6 @@  LIBGFOR_CHECK_ATTRIBUTE_ALIAS
 # Check out sync builtins support.
 LIBGFOR_CHECK_SYNC_FETCH_AND_ADD
 
-# Check out thread support.
-LIBGFOR_CHECK_GTHR_DEFAULT
-
 # Check out #pragma weak.
 LIBGFOR_GTHREAD_WEAK
 
diff --git a/libobjc/Makefile.in b/libobjc/Makefile.in
--- a/libobjc/Makefile.in
+++ b/libobjc/Makefile.in
@@ -102,6 +102,7 @@  INCLUDES = -I$(srcdir)/$(MULTISRCTOP)../
   -I$(srcdir)/$(MULTISRCTOP)../gcc/config \
   -I$(MULTIBUILDTOP)../../$(host_subdir)/gcc \
   -I$(srcdir)/$(MULTISRCTOP)../libgcc \
+  -I$(MULTIBUILDTOP)../libgcc \
   -I$(srcdir)/$(MULTISRCTOP)../include \
   $(OBJC_BOEHM_GC_INCLUDES)
 
diff --git a/libobjc/configure.ac b/libobjc/configure.ac
--- a/libobjc/configure.ac
+++ b/libobjc/configure.ac
@@ -217,15 +217,6 @@  AC_CHECK_HEADERS(sched.h)
 # Miscellanea
 # -----------
 
-AC_MSG_CHECKING([for thread model used by GCC])
-target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
-AC_MSG_RESULT([$target_thread_file]) 
-
-if test $target_thread_file != single; then
-  AC_DEFINE(HAVE_GTHR_DEFAULT, 1,
-        [Define if the compiler has a thread header that is non single.])
-fi 
-
 # Check if we have thread-local storage
 GCC_CHECK_TLS
 
diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -35,6 +35,7 @@  dnl  SUBDIRS
 dnl Substs:
 dnl  glibcxx_builddir     (absolute path)
 dnl  glibcxx_srcdir       (absolute path)
+dnl  toplevel_builddir    (absolute path)
 dnl  toplevel_srcdir      (absolute path)
 dnl  with_cross_host
 dnl  with_newlib
@@ -59,9 +60,11 @@  AC_DEFUN([GLIBCXX_CONFIGURE], [
     [\\/$]* | ?:[\\/]*) glibcxx_srcdir=${srcdir} ;;
     *) glibcxx_srcdir=`cd "$srcdir" && ${PWDCMD-pwd} || echo "$srcdir"` ;;
   esac
+  toplevel_builddir=${glibcxx_builddir}/..
   toplevel_srcdir=${glibcxx_srcdir}/..
   AC_SUBST(glibcxx_builddir)
   AC_SUBST(glibcxx_srcdir)
+  AC_SUBST(toplevel_builddir)
   AC_SUBST(toplevel_srcdir)
 
   # We use these options to decide which functions to include.  They are
@@ -3132,34 +3135,10 @@  dnl having to write complex code (the se
 dnl namespace are complex and fragile enough as it is).  We must also
 dnl add a relative path so that -I- is supported properly.
 dnl
-dnl Substs:
-dnl  glibcxx_thread_h
-dnl
-dnl Defines:
-dnl  HAVE_GTHR_DEFAULT
-dnl
 AC_DEFUN([GLIBCXX_ENABLE_THREADS], [
   AC_MSG_CHECKING([for thread model used by GCC])
   target_thread_file=`$CXX -v 2>&1 | sed -n 's/^Thread model: //p'`
   AC_MSG_RESULT([$target_thread_file])
-
-  if test $target_thread_file != single; then
-    AC_DEFINE(HAVE_GTHR_DEFAULT, 1,
-	      [Define if gthr-default.h exists
-	      (meaning that threading support is enabled).])
-  fi
-
-  glibcxx_thread_h=gthr-$target_thread_file.h
-
-  dnl Check for __GTHREADS define.
-  gthread_file=${toplevel_srcdir}/gcc/${glibcxx_thread_h}
-  if grep __GTHREADS $gthread_file >/dev/null 2>&1 ; then
-    enable_thread=yes
-  else
-   enable_thread=no
-  fi
-
-  AC_SUBST(glibcxx_thread_h)
 ])
 
 
@@ -3173,7 +3152,8 @@  AC_DEFUN([GLIBCXX_CHECK_GTHREADS], [
   AC_LANG_CPLUSPLUS
 
   ac_save_CXXFLAGS="$CXXFLAGS"
-  CXXFLAGS="$CXXFLAGS -fno-exceptions -I${toplevel_srcdir}/gcc"
+  CXXFLAGS="$CXXFLAGS -fno-exceptions \
+	-I${toplevel_srcdir}/libgcc -I${toplevel_builddir}/libgcc"
 
   AC_MSG_CHECKING([check whether it can be safely assumed that mutex_timedlock is available])
 
diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -846,7 +846,6 @@  thread_host_headers = \
 	${host_builddir}/gthr.h \
 	${host_builddir}/gthr-single.h \
 	${host_builddir}/gthr-posix.h \
-	${host_builddir}/gthr-tpf.h \
 	${host_builddir}/gthr-default.h
 
 
@@ -1108,43 +1107,35 @@  endif
 # Host includes for threads
 uppercase = [ABCDEFGHIJKLMNOPQRSTUVWXYZ_]
 
-${host_builddir}/gthr.h: ${toplevel_srcdir}/gcc/gthr.h stamp-${host_alias}
+${host_builddir}/gthr.h: ${toplevel_srcdir}/libgcc/gthr.h stamp-${host_alias}
 	sed -e '/^#pragma/b' \
 	    -e '/^#/s/\(${uppercase}${uppercase}*\)/_GLIBCXX_\1/g' \
 	    -e 's/_GLIBCXX_SUPPORTS_WEAK/__GXX_WEAK__/g' \
 	    -e 's,^#include "\(.*\)",#include <bits/\1>,g' \
-	    < ${toplevel_srcdir}/gcc/gthr.h > $@
+	    < $< > $@
 
-${host_builddir}/gthr-single.h: ${toplevel_srcdir}/gcc/gthr-single.h \
+${host_builddir}/gthr-single.h: ${toplevel_srcdir}/libgcc/gthr-single.h \
 				  stamp-${host_alias}
 	sed -e 's/\(UNUSED\)/_GLIBCXX_\1/g' \
 	    -e 's/\(GCC${uppercase}*_H\)/_GLIBCXX_\1/g' \
-	    < ${toplevel_srcdir}/gcc/gthr-single.h > $@
+	    < $< > $@
 
-${host_builddir}/gthr-posix.h: ${toplevel_srcdir}/gcc/gthr-posix.h \
+${host_builddir}/gthr-posix.h: ${toplevel_srcdir}/libgcc/gthr-posix.h \
 				   stamp-${host_alias}
 	sed -e 's/\(UNUSED\)/_GLIBCXX_\1/g' \
 	    -e 's/\(GCC${uppercase}*_H\)/_GLIBCXX_\1/g' \
 	    -e 's/SUPPORTS_WEAK/__GXX_WEAK__/g' \
 	    -e 's/\(${uppercase}*USE_WEAK\)/_GLIBCXX_\1/g' \
-	    < ${toplevel_srcdir}/gcc/gthr-posix.h > $@
+	    < $< > $@
 
-${host_builddir}/gthr-tpf.h: ${toplevel_srcdir}/gcc/gthr-tpf.h \
-				   stamp-${host_alias}
-	sed -e 's/\(UNUSED\)/_GLIBCXX_\1/g' \
-	    -e 's/\(GCC${uppercase}*_H\)/_GLIBCXX_\1/g' \
-	    -e 's/SUPPORTS_WEAK/__GXX_WEAK__/g' \
-	    -e 's/\(${uppercase}*USE_WEAK\)/_GLIBCXX_\1/g' \
-	    < ${toplevel_srcdir}/gcc/gthr-tpf.h > $@
-
-${host_builddir}/gthr-default.h: ${toplevel_srcdir}/gcc/${glibcxx_thread_h} \
+${host_builddir}/gthr-default.h: ${toplevel_builddir}/libgcc/gthr-default.h \
 				   stamp-${host_alias}
 	sed -e 's/\(UNUSED\)/_GLIBCXX_\1/g' \
 	    -e 's/\(GCC${uppercase}*_H\)/_GLIBCXX_\1/g' \
 	    -e 's/SUPPORTS_WEAK/__GXX_WEAK__/g' \
 	    -e 's/\(${uppercase}*USE_WEAK\)/_GLIBCXX_\1/g' \
 	    -e 's,^#include "\(.*\)",#include <bits/\1>,g' \
-	    < ${toplevel_srcdir}/gcc/${glibcxx_thread_h} > $@
+	    < $< > $@
 
 # Build two precompiled C++ includes, stdc++.h.gch/*.gch
 ${pch1a_output}: ${allstamped} ${host_builddir}/c++config.h ${pch1_source}