diff mbox

[libgomp] Link libgomp with -lpthread on FreeBSD

Message ID alpine.LNX.2.00.1101020042000.4999@gerinyyl.fvgr
State New
Headers show

Commit Message

Gerald Pfeifer Jan. 1, 2011, 11:46 p.m. UTC
On Tue, 30 Nov 2010, Rainer Orth wrote:
> Four libgomp testcases are currently failing on mips-sgi-irix6.5:
> 
> FAIL: libgomp.fortran/condinc2.f  -O  execution test
> FAIL: libgomp.fortran/condinc4.f90  -O  execution test
> FAIL: libgomp.fortran/omp_cond2.f  -O  execution test
> FAIL: libgomp.fortran/omp_cond4.F90  -O  execution test
> 
> The failure is like this:
> 
> 342447:./condinc2.exe: rld: Error: unresolvable symbol in /var/gcc/regression/trunk/6.5-gcc/build/mips-sgi-irix6.5/./libgomp/.libs/libgomp.so.2: pthread_setspecific

This sounded familiar, and indeed the very same four failures have
been there on FreeBSD.

> While IRIX 6 has many pthread functions in libc, some are missing and
> one needs to link with -lpthread to get them.  This is exactly what the
> following patch does.
> 
> Tested by rebuilding libgomp and running make check for both multilibs.  

What I don't understand is why you cannot just add -pthread to XLDFLAGS.
I tried, on FreeBSD, and indeed it does not work, whereas -lpthread does.

In any case, the patch below fixes the issue on FreeBSD as my tests show
  http://gcc.gnu.org/ml/gcc-testresults/2011-01/msg00048.html (before)
  http://gcc.gnu.org/ml/gcc-testresults/2011-01/msg00076.html (after)
and I'd like to apply this to mainline and GCC 4.5 (possibly 4.4, though
I don't think that's too important).

Gerald

Comments

Rainer Orth Jan. 7, 2011, 7:22 p.m. UTC | #1
Gerald Pfeifer <gerald@pfeifer.com> writes:

>> While IRIX 6 has many pthread functions in libc, some are missing and
>> one needs to link with -lpthread to get them.  This is exactly what the
>> following patch does.
>> 
>> Tested by rebuilding libgomp and running make check for both multilibs.  
>
> What I don't understand is why you cannot just add -pthread to XLDFLAGS.
> I tried, on FreeBSD, and indeed it does not work, whereas -lpthread does.

I've wondered that myself for some time, at first blaming libtool
(always an easy target :-), but the answer is simple: many specs (like
FBSD_LIB_SPEC in config/freebsd-spec.h) have

#define FBSD_LIB_SPEC "                                                 \
  %{!shared:                                                            \
    %{!pg: %{pthread:-lpthread} -lc}                                    \
    %{pg:  %{pthread:-lpthread_p} -lc_p}                                \
  }"

No idea why, and I strongly believe this is far more trouble than it's
worth.  Consider the complicated contortions you have to go through to
get working TLS support on Solaris 8 and 9.  I consider it insane that
this would only for when creating an executable, but to have to
duplicate it manually when building a shared object.

	Rainer
Gerald Pfeifer Jan. 15, 2011, 9:28 p.m. UTC | #2
Ping.  Can anyone please approve this so that GCC 4.6.0 and the
next release of GCC 4.5 at least will see this fixed?

Thanks,
Gerald

On Sun, 2 Jan 2011, Gerald Pfeifer wrote:
> On Tue, 30 Nov 2010, Rainer Orth wrote:
>> Four libgomp testcases are currently failing on mips-sgi-irix6.5:
>> 
>> FAIL: libgomp.fortran/condinc2.f  -O  execution test
>> FAIL: libgomp.fortran/condinc4.f90  -O  execution test
>> FAIL: libgomp.fortran/omp_cond2.f  -O  execution test
>> FAIL: libgomp.fortran/omp_cond4.F90  -O  execution test
>> 
>> The failure is like this:
>> 
>> 342447:./condinc2.exe: rld: Error: unresolvable symbol in /var/gcc/regression/trunk/6.5-gcc/build/mips-sgi-irix6.5/./libgomp/.libs/libgomp.so.2: pthread_setspecific
> This sounded familiar, and indeed the very same four failures have
> been there on FreeBSD.
> 
>> While IRIX 6 has many pthread functions in libc, some are missing and
>> one needs to link with -lpthread to get them.  This is exactly what the
>> following patch does.
[...] 
> In any case, the patch below fixes the issue on FreeBSD as my tests show
>   http://gcc.gnu.org/ml/gcc-testresults/2011-01/msg00048.html (before)
>   http://gcc.gnu.org/ml/gcc-testresults/2011-01/msg00076.html (after)
> and I'd like to apply this to mainline and GCC 4.5 (possibly 4.4, though
> I don't think that's too important).
> 
> Gerald
> 
> Index: configure.tgt
> ===================================================================
> --- configure.tgt	(revision 168391)
> +++ configure.tgt	(working copy)
> @@ -124,6 +124,12 @@
>  	config_path="bsd posix"
>  	;;
>  
> +  *-*-freebsd*)
> +	# Need to link with -lpthread so libgomp.so is self-contained.
> +	XLDFLAGS="${XLDFLAGS} -lpthread"
> +	;;
> +
>    mips-sgi-irix6*)
>  	# Need to link with -lpthread so libgomp.so is self-contained.
>  	XLDFLAGS="${XLDFLAGS} -lpthread"
Jakub Jelinek Jan. 16, 2011, 10:43 a.m. UTC | #3
On Sat, Jan 15, 2011 at 10:28:51PM +0100, Gerald Pfeifer wrote:
> Ping.  Can anyone please approve this so that GCC 4.6.0 and the
> next release of GCC 4.5 at least will see this fixed?

Ok with proper ChangeLog entry.

> > Index: configure.tgt
> > ===================================================================
> > --- configure.tgt	(revision 168391)
> > +++ configure.tgt	(working copy)
> > @@ -124,6 +124,12 @@
> >  	config_path="bsd posix"
> >  	;;
> >  
> > +  *-*-freebsd*)
> > +	# Need to link with -lpthread so libgomp.so is self-contained.
> > +	XLDFLAGS="${XLDFLAGS} -lpthread"
> > +	;;
> > +
> >    mips-sgi-irix6*)
> >  	# Need to link with -lpthread so libgomp.so is self-contained.
> >  	XLDFLAGS="${XLDFLAGS} -lpthread"

	Jakub
Gerald Pfeifer Jan. 16, 2011, 6:20 p.m. UTC | #4
On Fri, 7 Jan 2011, Rainer Orth wrote:
>> What I don't understand is why you cannot just add -pthread to XLDFLAGS.
>> I tried, on FreeBSD, and indeed it does not work, whereas -lpthread does.
> I've wondered that myself for some time, at first blaming libtool
> (always an easy target :-), but the answer is simple: many specs (like
> FBSD_LIB_SPEC in config/freebsd-spec.h) have
> 
> #define FBSD_LIB_SPEC "                                                 \
>   %{!shared:                                                            \
>     %{!pg: %{pthread:-lpthread} -lc}                                    \
>     %{pg:  %{pthread:-lpthread_p} -lc_p}                                \
>   }"
> 
> No idea why, and I strongly believe this is far more trouble than it's
> worth.  Consider the complicated contortions you have to go through to
> get working TLS support on Solaris 8 and 9.  I consider it insane that
> this would only for when creating an executable, but to have to
> duplicate it manually when building a shared object.

Good diagnosis, Rainer!  Are you planning to change this for your
ports?  I see a similar construct in config/mips/iris6.h, and if
I understand you correctly also Solaris still is like that?

Should we give this a try for FreeBSD?  (Loren?  Others?)

Gerald
Rainer Orth Jan. 17, 2011, 1:11 p.m. UTC | #5
Gerald Pfeifer <gerald@pfeifer.com> writes:

> On Fri, 7 Jan 2011, Rainer Orth wrote:
>>> What I don't understand is why you cannot just add -pthread to XLDFLAGS.
>>> I tried, on FreeBSD, and indeed it does not work, whereas -lpthread does.
>> I've wondered that myself for some time, at first blaming libtool
>> (always an easy target :-), but the answer is simple: many specs (like
>> FBSD_LIB_SPEC in config/freebsd-spec.h) have
>> 
>> #define FBSD_LIB_SPEC "                                                 \
>>   %{!shared:                                                            \
>>     %{!pg: %{pthread:-lpthread} -lc}                                    \
>>     %{pg:  %{pthread:-lpthread_p} -lc_p}                                \
>>   }"
>> 
>> No idea why, and I strongly believe this is far more trouble than it's
>> worth.  Consider the complicated contortions you have to go through to
>> get working TLS support on Solaris 8 and 9.  I consider it insane that
>> this would only for when creating an executable, but to have to
>> duplicate it manually when building a shared object.
>
> Good diagnosis, Rainer!  Are you planning to change this for your
> ports?  I see a similar construct in config/mips/iris6.h, and if
> I understand you correctly also Solaris still is like that?

I've changed Solaris to support -pthread with -shared when fixing TLS
support for Solaris 8 and 9.  Forcing users to manually pass all the
necessary flags just wasn't an option.

I may well do the same for Tru64 UNIX and IRIX, if only for
consistencies sake.

If anyone has an idea why this is disabled almost everywhere, I'd be
grateful.

	Rainer
diff mbox

Patch

Index: configure.tgt
===================================================================
--- configure.tgt	(revision 168391)
+++ configure.tgt	(working copy)
@@ -124,6 +124,12 @@ 
 	config_path="bsd posix"
 	;;
 
+  *-*-freebsd*)
+	# Need to link with -lpthread so libgomp.so is self-contained.
+	XLDFLAGS="${XLDFLAGS} -lpthread"
+	;;
+
   mips-sgi-irix6*)
 	# Need to link with -lpthread so libgomp.so is self-contained.
 	XLDFLAGS="${XLDFLAGS} -lpthread"