diff mbox

[build,doc,libjava,testsuite] Fully support TLS on Solaris 8 and 9

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

Commit Message

Rainer Orth July 15, 2010, 6:08 p.m. UTC
While emutls support was largely broken on mainline, I tried to
bootstrap on Solaris 8 and 9 with --enable-tls.  The results weren't
really pretty:

* All TLS execution tests failed because __tls_get_addr wasn't found.
  It turns out that this function (resp. ___tls_get_addr on Solaris 8/9
  x86) only lives in libthread before Solaris 10 and the introduction of
  the unified process model.  So it is necessary to explicitly link with
  -lthread for TLS runtime support, and I'm adding that to -pthread
  support in LIB_SPEC.

* While TLS support was introduced in Solaris 9 FCS, the initial
  implementation on x86 used a different style than the GNU tools.
  Since their own compilers were late to adopt TLS, they decided to scrap
  that Sun style and replaced it by a GNU-style implementation in
  Solaris 9 4/04, the only one supported by GCC.  The two can be
  distinguished by checking for ___tls_get_addr on 32-bit x86 instead of
  __tls_get_addr.

* TLS was backported to Solaris 8, but only lives in the alternate
  thread library in /usr/lib/lwp, which became the default in Solaris 9.
  Since this implementation is strictly better than the old one, I'm
  always using it on Solaris 8, irrespective of TLS support.  It would
  be quite confusing to use different thread libraries depending on
  whether or not the rest of the toolchain supports TLS.

While I've documented the whole situation in install.texi, I don't want
users to manually check for the necessary prerequisites: you need both
a sufficiently recent libthread patch and the linker patch (both for ld
and ld.so.1).  While I'm documenting the minimal patch revisions, I've
added configure checks for the presence of
__tls_get_addr/___tls_get_addr in libthread or libc to gcc/configure.ac,
and do check linker versions (ld -V output) for linker and
runtime-linker support.  I can do the latter because they are always
delivered/patched together.

So unlike before and as on Solaris 10+, TLS support is always enabled if
those prerequisites are met.

A couple of other changes were needed:

* The libraries that use libpthread should link with -pthread on Solaris
  so they automatically benefit from the alternate thread library.
  Unfortunately, so far gcc -shared -pthread doesn't link with -lpthread
  (PR target/18788).  While this matches Sun cc, a question on the
  OpenSolaris tools-compilers mailing list revealed that there wasn't a
  real reason for this, and having the user to specify the whole dance
  of -lpthread, -lthread and eventually -L/usr/lib/lwp -R/usr/lib/lwp is
  completely unacceptable.  So I've fixed the PR and make use of the new
  behavior of -pthread.

* Unfortunately, this doesn't work for libjava: libtool links with
  -nostdlib for C++ support (for whatever reason; it seems completely
  nonsensical to try and second-guess the compiler driver here), so
  LIB_SPEC, where -pthread is interpreted, isn't used ;-(  libtool gets
  even further in my way: I cannot pass -R/usr/lib/lwp through it, nor
  does -rpath /usr/lib/lwp work, so I'm forced to use -Wl,-R
  -Wl,/usr/lib/lwp instead.  That mess seems to be more of a hindrance
  most of the time ;-(

* libgomp.so must be linked with -pthread (and thus -lthread on Solaris
  8/9), otherwise it contains an unresolved reference to __tls_get_addr
  and libgomp tests with -fno-openmp fail.  Since this is a C library
  and -Wc,-pthread is passed already, this happens out of the box with
  the fix for PR target/18788.

* The TLS tests in libobjc failed because they weren't linked with
  -pthread.  I've implemented and used dg-add-options tls to handle
  this.  Only gcc.dg/lto/20090210_0.c needs an explict
  dg-extra-ld-options "-pthread" since dg-lto-do tests don't work with
  dg-add-options.

Bootstrapped without regressions on i386-pc-solaris2.8,
i386-pc-solaris2.9, i386-pc-solaris2.10, i386-pc-solaris2.11,
sparc-sun-solaris2.8, sparc-sun-solaris2.9, sparc-sun-solaris2.10 and
sparc-sun-solaris2.11 with Sun as and GNU as each.

Ok for mainline?  I think I only need approval for the testsuite changes
(which are close to obvious); anything else should fall under the
Solaris maintenance.

I'm thinking about a backport of a slightly different version of the
patch to the 4.5 branch since --enable-tls is so completely broken
there.  My plan is not to do the automatic enabling, but instead to
require users to configure with --enable-tls, just as things are now.
Objections?

	Rainer


2010-05-24  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	libjava:
	* configure.ac (*-*-solaris2.8): Use alternate thread library.
	Add libthread.
	(*-*-solaris2.9): Use libthread.
	* configure: Regenerate.

	libgomp:
	* configure.tgt (*-*-solaris2.[56]*): Removed.

	gcc:
	* configure.ac: Don't disable TLS on Solaris 8/9 by default
	Set tga_func for Solaris 2/x86 resp. SPARC.
	Remove duplicate parts of sparc*-sun-solaris2.* TLS check.
	(LIB_THREAD_LDFLAGS_SPEC): Define.
	(LIB_TLS_SPEC): Define.
	Check for required Sun ld version.
	* configure: Regenerate.
	* config.in: Regenerate.
	* config/sol2.h (LIB_SPEC): Use LIB_THREAD_LDFLAGS_SPEC with
	-pthread, -threads, LIB_TLS_SPEC with -pthread.
	* doc/install.texi (Specific, *-*-solaris2*): Document use of
	alternate thread libraries on Solaris 8.
	Document TLS patch requirements.
	* doc/sourcebuild.texi (Add Options): Sort alphabetically.
	Document tls.

	gcc:
	PR target/18788
	* config/sol2.h (LIB_SPEC): Link with thread libraries even with
	-shared.

	gcc/testsuite:
	* lib/target-supports.exp (add_options_for_tls): New proc.
	* g++.dg/tls/static-1.C: Use dg-add-options tls.
	* g++.dg/tls/static-1a.cc: Likewise.
	* gcc.dg/tls/emutls-1.c: Likewise.
	* gcc.dg/tls/opt-11.c: Likewise.
	* gcc.dg/tls/opt-12.c: Likewise.
	* gcc.dg/tls/pr24428-2.c: Likewise.
	* gcc.dg/tls/pr24428.c: Likewise.
	* obj-c++.dg/tls/static-1.mm: Likewise.
	* obj-c++.dg/torture/tls/thr-init-1.mm: Likewise.
	* obj-c++.dg/torture/tls/thr-init-2.mm: Likewise.
	* obj-c++.dg/torture/tls/thr-init-3.mm: Likewise.
	* objc.dg/torture/tls/thr-init-2.m: Likewise.
	* objc.dg/torture/tls/thr-init-3.m: Likewise.
	* objc.dg/torture/tls/thr-init.m: Likewise.
	* gcc.dg/lto/20090210_0.c: Add -pthread for *-*-solaris2.[89].

Comments

Andrew Haley July 16, 2010, 8:38 a.m. UTC | #1
On 07/15/2010 07:08 PM, Rainer Orth wrote:

> * Unfortunately, this doesn't work for libjava: libtool links with
>   -nostdlib for C++ support (for whatever reason; it seems completely
>   nonsensical to try and second-guess the compiler driver here), so
>   LIB_SPEC, where -pthread is interpreted, isn't used ;-(  libtool gets
>   even further in my way: I cannot pass -R/usr/lib/lwp through it, nor
>   does -rpath /usr/lib/lwp work, so I'm forced to use -Wl,-R
>   -Wl,/usr/lib/lwp instead.  That mess seems to be more of a hindrance
>   most of the time ;-(

libjava doesn't depend on libstdc++.  And yes, libtool is more of a
hindrance most of the time.

Andrew.
Rainer Orth July 16, 2010, 8:45 a.m. UTC | #2
Andrew Haley <aph@redhat.com> writes:

> On 07/15/2010 07:08 PM, Rainer Orth wrote:
>
>> * Unfortunately, this doesn't work for libjava: libtool links with
>>   -nostdlib for C++ support (for whatever reason; it seems completely
>>   nonsensical to try and second-guess the compiler driver here), so
>>   LIB_SPEC, where -pthread is interpreted, isn't used ;-(  libtool gets
>>   even further in my way: I cannot pass -R/usr/lib/lwp through it, nor
>>   does -rpath /usr/lib/lwp work, so I'm forced to use -Wl,-R
>>   -Wl,/usr/lib/lwp instead.  That mess seems to be more of a hindrance
>>   most of the time ;-(
>
> libjava doesn't depend on libstdc++.  And yes, libtool is more of a
> hindrance most of the time.

Right, but the native code is C++, which triggers libtool's use of
-nostdlib ;-(  No idea why they think this is useful/necessary.

Anyway, what about the libjava bits?  Ok for mainline (and 4.5 if I
decide to backport)?

	Rainer
Andrew Haley July 16, 2010, 8:48 a.m. UTC | #3
On 07/16/2010 09:45 AM, Rainer Orth wrote:
> Andrew Haley <aph@redhat.com> writes:
> 
>> On 07/15/2010 07:08 PM, Rainer Orth wrote:
>>
>>> * Unfortunately, this doesn't work for libjava: libtool links with
>>>   -nostdlib for C++ support (for whatever reason; it seems completely
>>>   nonsensical to try and second-guess the compiler driver here), so
>>>   LIB_SPEC, where -pthread is interpreted, isn't used ;-(  libtool gets
>>>   even further in my way: I cannot pass -R/usr/lib/lwp through it, nor
>>>   does -rpath /usr/lib/lwp work, so I'm forced to use -Wl,-R
>>>   -Wl,/usr/lib/lwp instead.  That mess seems to be more of a hindrance
>>>   most of the time ;-(
>>
>> libjava doesn't depend on libstdc++.  And yes, libtool is more of a
>> hindrance most of the time.
> 
> Right, but the native code is C++, which triggers libtool's use of
> -nostdlib ;-(  No idea why they think this is useful/necessary.
> 
> Anyway, what about the libjava bits?  Ok for mainline (and 4.5 if I
> decide to backport)?

Sure: as you say, this is all part of a Solaris maintainer's job.  And
what I know about Solaris can be written on the back of a postage stamp.
;-)

Andrew.
Dave Korn Sept. 12, 2010, 11:40 p.m. UTC | #4
On 15/07/2010 19:08, Rainer Orth wrote:

> * The TLS tests in libobjc failed because they weren't linked with
>   -pthread.  I've implemented and used dg-add-options tls to handle
>   this.  Only gcc.dg/lto/20090210_0.c needs an explict
>   dg-extra-ld-options "-pthread" since dg-lto-do tests don't work with
>   dg-add-options.

> 	gcc/testsuite:
> 	* gcc.dg/lto/20090210_0.c: Add -pthread for *-*-solaris2.[89].

    Hi Rainer,

  I have a problem on i686-pc-cygwin caused by this part of your patch:

> diff -r c7b371acdb35 gcc/testsuite/gcc.dg/lto/20090210_0.c
> --- a/gcc/testsuite/gcc.dg/lto/20090210_0.c	Mon Jul 12 16:03:30 2010 +0200
> +++ b/gcc/testsuite/gcc.dg/lto/20090210_0.c	Thu Jul 15 18:27:58 2010 +0200
> @@ -1,5 +1,7 @@
>  /* { dg-lto-do run }  */
>  /* { dg-suppress-ld-options {-fPIC} }  */
> +/* { dg-require-effective-target tls } */
> +/* { dg-extra-ld-options "-pthread" { target *-*-solaris2.[89] } } */
>  int foo (int x)
>  {
>    return x;

  As far as I can tell, dg-extra-ld-options doesn't take a target modifier in
the way you've used there, so that "-pthread" is in effect on all targets and
breaks the testcase on targets which don't support that option.  See proc
lto-get-options-main in gcc/testsuite/lto.exp.  Perhaps you could extend it to
work with a target selector?  Or maybe there's some other way you could get
the -pthread flag passed on Solaris (only)?

    cheers,
      DaveK
Rainer Orth Sept. 13, 2010, 6:21 p.m. UTC | #5
Hi Dave,

>   As far as I can tell, dg-extra-ld-options doesn't take a target modifier in
> the way you've used there, so that "-pthread" is in effect on all targets and
> breaks the testcase on targets which don't support that option.  See proc
> lto-get-options-main in gcc/testsuite/lto.exp.  Perhaps you could extend it to
> work with a target selector?  Or maybe there's some other way you could get
> the -pthread flag passed on Solaris (only)?

sorry for the breakage.  I hadn't realized that dg-extra-ld-options was
LTO-only and special in this respect.  As mentioned in the patch
submission, dg-add-options unfortunately doesn't work for LTO, so I had
to use the dg-extra-ld-options solution.  I think I'll go for supporting
a target selector as you suggest.

I'm unsure if I'll get around to it this week, though, and will be on
vacation the next, so please file a PR and assign it to me so the issue
isn't forgotten.

	Rainer
Dave Korn Oct. 1, 2010, 1:55 a.m. UTC | #6
On 13/09/2010 19:21, Rainer Orth wrote:

> vacation the next, so please file a PR and assign it to me so the issue
> isn't forgotten.
> 
> 	Rainer

FTR: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45851

    cheers,
      DaveK
diff mbox

Patch

diff -r c7b371acdb35 gcc/config/sol2.h
--- a/gcc/config/sol2.h	Mon Jul 12 16:03:30 2010 +0200
+++ b/gcc/config/sol2.h	Thu Jul 15 18:27:58 2010 +0200
@@ -124,11 +124,12 @@ 
 #undef LIB_SPEC
 #define LIB_SPEC \
   "%{compat-bsd:-lucb -lsocket -lnsl -lelf -laio} \
-   %{!shared:\
-     %{!symbolic:\
-       %{pthreads|pthread:-lpthread} \
-       %{!pthreads:%{!pthread:%{threads:-lthread}}} \
-       %{p|pg:-ldl} -lc}}"
+   %{!symbolic:\
+     %{pthreads|pthread:" \
+        LIB_THREAD_LDFLAGS_SPEC " -lpthread " LIB_TLS_SPEC "} \
+     %{!pthreads:%{!pthread:%{threads:" \
+	LIB_THREAD_LDFLAGS_SPEC " -lthread}}} \
+     %{p|pg:-ldl} -lc}"
 
 #undef  ENDFILE_SPEC
 #define ENDFILE_SPEC "crtend.o%s crtn.o%s"
diff -r c7b371acdb35 gcc/configure.ac
--- a/gcc/configure.ac	Mon Jul 12 16:03:30 2010 +0200
+++ b/gcc/configure.ac	Thu Jul 15 18:27:58 2010 +0200
@@ -2687,17 +2687,9 @@ 
 	;;
   i[34567]86-*-*)
     case "$target" in
-      i[34567]86-*-solaris2.[89]*)
-	# TLS was introduced in the Solaris 9 4/04 release but
-	# we do not enable it by default on Solaris 9 either.
-	if test "x$enable_tls" = xyes ; then
-	  on_solaris=yes
-	else
-	  enable_tls=no;
-	fi
-	;;
       i[34567]86-*-solaris2.*)
 	on_solaris=yes
+	tga_func=___tls_get_addr
 	;;
       *)
 	on_solaris=no
@@ -2913,17 +2905,9 @@ 
 	;;
   sparc*-*-*)
     case "$target" in
-      sparc*-sun-solaris2.[89]*)
-	# TLS was introduced in the Solaris 9 4/04 release but
-	# we do not enable it by default on Solaris 9 either.
-	if test "x$enable_tls" = xyes ; then
-	  on_solaris=yes
-	else
-	  enable_tls=no;
-	fi
-	;;
       sparc*-sun-solaris2.*)
 	on_solaris=yes
+	tga_func=__tls_get_addr
 	;;
       *)
 	on_solaris=no
@@ -2931,7 +2915,17 @@ 
     esac
     if test x$on_solaris = xyes && test x$gas_flag = xno; then
       conftest_s='
-	.section ".tdata",#alloc,#write,#tls
+	.section ".tdata",#alloc,#write,#tls'
+	tls_first_major=0
+	tls_first_minor=0
+    else
+      conftest_s='
+	.section ".tdata","awT",@progbits'
+	tls_first_major=2
+	tls_first_minor=14
+	tls_as_opt="-32 --fatal-warnings"
+    fi
+    conftest_s="$conftest_s
 foo:	.long	25
 	.text
 	sethi	%tgd_hi22(foo), %o0
@@ -2951,36 +2945,7 @@ 
 	add	%g7, %o2, %o4, %tie_add(foo)
 	sethi	%tle_hix22(foo), %l1
 	xor	%l1, %tle_lox10(foo), %o5
-	ld	[%g7 + %o5], %o1'
-	tls_first_major=0
-	tls_first_minor=0
-    else
-      conftest_s='
-	.section ".tdata","awT",@progbits
-foo:	.long	25
-	.text
-	sethi	%tgd_hi22(foo), %o0
-	add	%o0, %tgd_lo10(foo), %o1
-	add	%l7, %o1, %o0, %tgd_add(foo)
-	call	__tls_get_addr, %tgd_call(foo)
-	sethi	%tldm_hi22(foo), %l1
-	add	%l1, %tldm_lo10(foo), %l2
-	add	%l7, %l2, %o0, %tldm_add(foo)
-	call	__tls_get_addr, %tldm_call(foo)
-	sethi	%tldo_hix22(foo), %l3
-	xor	%l3, %tldo_lox10(foo), %l4
-	add	%o0, %l4, %l5, %tldo_add(foo)
-	sethi	%tie_hi22(foo), %o3
-	add	%o3, %tie_lo10(foo), %o3
-	ld	[%l7 + %o3], %o2, %tie_ld(foo)
-	add	%g7, %o2, %o4, %tie_add(foo)
-	sethi	%tle_hix22(foo), %l1
-	xor	%l1, %tle_lox10(foo), %o5
-	ld	[%g7 + %o5], %o1'
-	tls_first_major=2
-	tls_first_minor=14
-	tls_as_opt="-32 --fatal-warnings"
-      fi
+	ld	[%g7 + %o5], %o1"
 	;;
   xtensa*-*-*)
     conftest_s='
@@ -3007,9 +2972,95 @@ 
   [$tls_first_major,$tls_first_minor,0], [$tls_as_opt], [$conftest_s],,
   [set_have_as_tls=yes])
 fi
+case "$target" in
+  # TLS was introduced in the Solaris 9 FCS release and backported to
+  # Solaris 8 patches.  Support for GNU-style TLS on x86 was only
+  # introduced in Solaris 9 4/04, replacing the earlier Sun style that Sun
+  # ld and GCC don't support any longer.
+  *-*-solaris2.*)
+    AC_MSG_CHECKING(linker and ld.so.1 TLS support)
+    ld_tls_support=no
+    # Check ld and ld.so.1 TLS support.
+    if echo "$ld_ver" | grep GNU > /dev/null; then
+      # Assume all interesting versions of GNU ld have TLS support.
+      # FIXME: still need ld.so.1 support, i.e. ld version checks below.
+      ld_tls_support=yes
+    else
+      case "$target" in
+        # Solaris 8/x86 ld has GNU style TLS support since version 1.280.
+        i?86-*-solaris2.8)
+          min_tls_ld_vers_minor=280
+          ;;
+        # Solaris 8/SPARC ld has TLS support since version 1.272.
+        sparc*-*-solaris2.8)
+          min_tls_ld_vers_minor=272
+          ;;
+	# Solaris 9/x86 ld has GNU style TLS support since version 1.374.
+        i?86-*-solaris2.9)
+          min_tls_ld_vers_minor=374
+          ;;
+	# Solaris 9/SPARC and Solaris 10+ ld have TLS support since FCS.
+        sparc*-*-solaris2.9 | *-*-solaris2.1[[0-9]]*)
+	  min_tls_ld_vers_minor=343
+          ;;
+      esac
+      if test "$ls_vers_major" -gt 1 || \
+        test "$ld_vers_minor" -ge "$min_tls_ld_vers_minor"; then
+ 	ld_tls_support=yes
+      else
+        set_have_as_tls=no
+      fi
+    fi
+    AC_MSG_RESULT($ld_tls_support)
+
+    save_LIBS="$LIBS"
+    save_LDFLAGS="$LDFLAGS"
+    LIBS=
+    LDFLAGS=
+
+    AC_MSG_CHECKING(alternate thread library)
+    case "$target" in
+      # TLS support was backported to Solaris 8 patches, but only lives in
+      # the alternate thread library which became the default in Solaris 9. 
+      # We want to always use that, irrespective of TLS support.
+      *-*-solaris2.8)
+        # Take multilib subdir into account.  There's no spec to handle
+	# this.  The 64 symlink exists since Solaris 8.
+        lwp_dir=/usr/lib/lwp
+	lwp_spec="-L$lwp_dir%{m64:/64} -R$lwp_dir%{m64:/64}"
+        LDFLAGS="-L$lwp_dir -R$lwp_dir"
+        ;;
+      *-*-solaris2*)
+        lwp_dir="none"
+	lwp_spec=""
+	;;
+    esac    
+    # Always define LIB_THREAD_LDFLAGS_SPEC, even without TLS support.
+    AC_DEFINE_UNQUOTED(LIB_THREAD_LDFLAGS_SPEC, "$lwp_spec",
+        [Define to the linker flags to use for -pthread.])
+    AC_MSG_RESULT($lwp_dir)
+
+    AC_MSG_CHECKING(library containing $tga_func)
+    # Before Solaris 10, __tls_get_addr (SPARC/x64) resp. ___tls_get_addr
+    # (32-bit x86) only lived in libthread, so check for that.  Keep
+    # set_have_as_tls if found, disable if not.
+    AC_SEARCH_LIBS([$tga_func], [thread],, [set_have_as_tls=no])
+    # Clear LIBS if we cannot support TLS.
+    if test $set_have_as_tls = no; then
+      LIBS=
+    fi
+    # Always define LIB_TLS_SPEC, even without TLS support.
+    AC_DEFINE_UNQUOTED(LIB_TLS_SPEC, "$LIBS",
+        [Define to the library containing __tls_get_addr/___tls_get_addr.])
+    AC_MSG_RESULT($LIBS)
+
+    LIBS="$save_LIBS"
+    LDFLAGS="$save_LDFLAGS"
+    ;;
+esac
 if test $set_have_as_tls = yes ; then
   AC_DEFINE(HAVE_AS_TLS, 1,
-	    [Define if your assembler supports thread-local storage.])
+	    [Define if your assembler and linker support thread-local storage.])
 fi
 
 # Target-specific assembler checks.
diff -r c7b371acdb35 gcc/doc/install.texi
--- a/gcc/doc/install.texi	Mon Jul 12 16:03:30 2010 +0200
+++ b/gcc/doc/install.texi	Thu Jul 15 18:27:58 2010 +0200
@@ -4165,6 +4165,29 @@ 
 117351-12 or newer for Intel) and Solaris 9 (117171-11 or newer for
 SPARC, 117172-11 or newer for Intel) that address this problem.
 
+Solaris~8 provides an alternate implementation of the thread libraries,
+@samp{libpthread} and @samp{libthread}.  They are required for TLS
+support and have been made the default in Solaris~9, so they are always
+used on Solaris~8.
+
+Thread-local storage (TLS) is supported in Solaris~8 and 9, but requires
+some patches.  The @samp{libthread} patches provide the
+@code{__tls_get_addr} (SPARC, 64-bit x86) resp.@ @code{___tls_get_addr}
+(32-bit x86) functions.  On Solaris~8, you need 108993-26 or newer on
+SPARC, 108994-26 or newer on Intel.  On Solaris~9, the necessary support
+on SPARC is present since FCS, while 114432-05 or newer is reqired on
+Intel.  Additionally, on Solaris~8, patch 109147-14 or newer on SPARC or
+109148-22 or newer on Intel are required for the Sun @command{ld} and
+runtime linker (@command{ld.so.1}) support.  Again, Solaris~9/SPARC
+works since FCS, while 113986-02 is required on Intel.  The linker
+patches must be installed even if GNU @command{ld} is used. Sun
+@command{as} in Solaris~8 and 9 doesn't support the necessary
+relocations, so GNU @command{as} must be used.  The @command{configure}
+script checks for those prerequisites and automatically enables TLS
+support if they are met.  Although those minimal patch versions should
+work, it is recommended to use the latest patch versions which include
+additional bug fixes.
+
 @html
 <hr />
 @end html
diff -r c7b371acdb35 gcc/doc/sourcebuild.texi
--- a/gcc/doc/sourcebuild.texi	Mon Jul 12 16:03:30 2010 +0200
+++ b/gcc/doc/sourcebuild.texi	Thu Jul 15 18:27:58 2010 +0200
@@ -1879,6 +1879,16 @@ 
 are:
 
 @table @code
+@item arm_neon
+NEON support.  Only ARM targets support this feature, and only then
+in certain modes; see the @ref{arm_neon_ok,,arm_neon_ok effective target
+keyword}.
+
+@item arm_neon_fp16
+NEON and half-precision floating point support.  Only ARM targets
+support this feature, and only then in certain modes; see
+the @ref{arm_neon_ok,,arm_neon_fp16_ok effective target keyword}.
+
 @item bind_pic_locally
 Add the target-specific flags needed to enable functions to bind
 locally when using pic/PIC passes in the testsuite.
@@ -1894,15 +1904,8 @@ 
 @code{mips16} function attributes.
 Only MIPS targets support this feature, and only then in certain modes.
 
-@item arm_neon
-NEON support.  Only ARM targets support this feature, and only then
-in certain modes; see the @ref{arm_neon_ok,,arm_neon_ok effective target
-keyword}.
-
-@item arm_neon_fp16
-NEON and half-precision floating point support.  Only ARM targets
-support this feature, and only then in certain modes; see
-the @ref{arm_neon_ok,,arm_neon_fp16_ok effective target keyword}.
+@item tls
+Add the target-specific flags needed to use thread-local storage.
 @end table
 
 @node Require Support
diff -r c7b371acdb35 gcc/testsuite/g++.dg/tls/static-1.C
--- a/gcc/testsuite/g++.dg/tls/static-1.C	Mon Jul 12 16:03:30 2010 +0200
+++ b/gcc/testsuite/g++.dg/tls/static-1.C	Thu Jul 15 18:27:58 2010 +0200
@@ -1,6 +1,7 @@ 
 // { dg-do run }
 // { dg-options "-O2" }
 // { dg-require-effective-target tls_runtime }
+// { dg-add-options tls }
 // { dg-additional-sources "static-1a.cc" }
 
 extern "C" void abort ();
diff -r c7b371acdb35 gcc/testsuite/g++.dg/tls/static-1a.cc
--- a/gcc/testsuite/g++.dg/tls/static-1a.cc	Mon Jul 12 16:03:30 2010 +0200
+++ b/gcc/testsuite/g++.dg/tls/static-1a.cc	Thu Jul 15 18:27:58 2010 +0200
@@ -1,6 +1,7 @@ 
 // { dg-do run }
 // { dg-options "-O2" }
 // { dg-require-effective-target tls_runtime }
+// { dg-add-options tls }
 // { dg-additional-sources "static-1a.cc" }
 
 struct A
diff -r c7b371acdb35 gcc/testsuite/gcc.dg/lto/20090210_0.c
--- a/gcc/testsuite/gcc.dg/lto/20090210_0.c	Mon Jul 12 16:03:30 2010 +0200
+++ b/gcc/testsuite/gcc.dg/lto/20090210_0.c	Thu Jul 15 18:27:58 2010 +0200
@@ -1,5 +1,7 @@ 
 /* { dg-lto-do run }  */
 /* { dg-suppress-ld-options {-fPIC} }  */
+/* { dg-require-effective-target tls } */
+/* { dg-extra-ld-options "-pthread" { target *-*-solaris2.[89] } } */
 int foo (int x)
 {
   return x;
diff -r c7b371acdb35 gcc/testsuite/gcc.dg/tls/emutls-1.c
--- a/gcc/testsuite/gcc.dg/tls/emutls-1.c	Mon Jul 12 16:03:30 2010 +0200
+++ b/gcc/testsuite/gcc.dg/tls/emutls-1.c	Thu Jul 15 18:27:58 2010 +0200
@@ -1,5 +1,6 @@ 
 /* { dg-do run { target *-wrs-vxworks } } */
 /* { dg-require-effective-target tls } */
+/* { dg-add-options tls } */
 
 /* vxworks' TLS model requires no extra padding on the tls proxy
    objects.  */
diff -r c7b371acdb35 gcc/testsuite/gcc.dg/tls/opt-11.c
--- a/gcc/testsuite/gcc.dg/tls/opt-11.c	Mon Jul 12 16:03:30 2010 +0200
+++ b/gcc/testsuite/gcc.dg/tls/opt-11.c	Thu Jul 15 18:27:58 2010 +0200
@@ -1,5 +1,6 @@ 
 /* { dg-do run } */
 /* { dg-require-effective-target tls_runtime } */
+/* { dg-add-options tls } */
 
 extern void abort (void);
 extern void *memset (void *, int, __SIZE_TYPE__);
diff -r c7b371acdb35 gcc/testsuite/gcc.dg/tls/opt-12.c
--- a/gcc/testsuite/gcc.dg/tls/opt-12.c	Mon Jul 12 16:03:30 2010 +0200
+++ b/gcc/testsuite/gcc.dg/tls/opt-12.c	Thu Jul 15 18:27:58 2010 +0200
@@ -2,6 +2,7 @@ 
 /* { dg-do run } */
 /* { dg-options "-O2 -fpic" } */
 /* { dg-require-effective-target tls_runtime } */
+/* { dg-add-options tls } */
 /* { dg-require-effective-target fpic } */
 
 extern void abort (void);
diff -r c7b371acdb35 gcc/testsuite/gcc.dg/tls/pr24428-2.c
--- a/gcc/testsuite/gcc.dg/tls/pr24428-2.c	Mon Jul 12 16:03:30 2010 +0200
+++ b/gcc/testsuite/gcc.dg/tls/pr24428-2.c	Thu Jul 15 18:27:58 2010 +0200
@@ -1,6 +1,7 @@ 
 /* { dg-do run } */
 /* { dg-options "-O2" } */
 /* { dg-require-effective-target tls_runtime } */
+/* { dg-add-options tls } */
 
 __thread double thrtest[81];
 int main ()
diff -r c7b371acdb35 gcc/testsuite/gcc.dg/tls/pr24428.c
--- a/gcc/testsuite/gcc.dg/tls/pr24428.c	Mon Jul 12 16:03:30 2010 +0200
+++ b/gcc/testsuite/gcc.dg/tls/pr24428.c	Thu Jul 15 18:27:58 2010 +0200
@@ -1,6 +1,7 @@ 
 /* { dg-do run } */
 /* { dg-options "-O2" } */
 /* { dg-require-effective-target tls_runtime } */
+/* { dg-add-options tls } */
 
 __thread double thrtest[81];
 int main ()
diff -r c7b371acdb35 gcc/testsuite/gcc.dg/tls/run-1.c
--- a/gcc/testsuite/gcc.dg/tls/run-1.c	Mon Jul 12 16:03:30 2010 +0200
+++ b/gcc/testsuite/gcc.dg/tls/run-1.c	Thu Jul 15 18:27:58 2010 +0200
@@ -1,6 +1,7 @@ 
 /* { dg-do run } */
 /* { dg-options "-O2" } */
 /* { dg-require-effective-target tls_runtime } */
+/* { dg-add-options tls } */
 
 extern void abort (void);
 
diff -r c7b371acdb35 gcc/testsuite/lib/target-supports.exp
--- a/gcc/testsuite/lib/target-supports.exp	Mon Jul 12 16:03:30 2010 +0200
+++ b/gcc/testsuite/lib/target-supports.exp	Thu Jul 15 18:27:58 2010 +0200
@@ -569,6 +569,24 @@ 
     }]
 }
 
+# Add to FLAGS all the target-specific flags needed to use thread-local storage.
+
+proc add_options_for_tls { flags } {
+    # On Solaris 8 and 9, __tls_get_addr/___tls_get_addr only lives in
+    # libthread, so always pass -pthread for native TLS.
+    # Need to duplicate native TLS check from
+    # check_effective_target_tls_native to avoid recursion.
+    if { [istarget *-*-solaris2.\[89\]*] &&
+	 [check_no_messages_and_pattern tls_native "!emutls" assembly {
+	     __thread int i;
+	     int f (void) { return i; }
+	     void g (int j) { i = j; }
+	 }] } {
+	return "$flags -pthread"
+    }
+    return $flags
+}
+
 # Return 1 if thread local storage (TLS) is supported, 0 otherwise.
 
 proc check_effective_target_tls {} {
diff -r c7b371acdb35 gcc/testsuite/obj-c++.dg/tls/static-1.mm
--- a/gcc/testsuite/obj-c++.dg/tls/static-1.mm	Mon Jul 12 16:03:30 2010 +0200
+++ b/gcc/testsuite/obj-c++.dg/tls/static-1.mm	Thu Jul 15 18:27:58 2010 +0200
@@ -1,5 +1,6 @@ 
 // { dg-do run }
 // { dg-require-effective-target tls }
+// { dg-add-options tls }
 // { dg-additional-sources "static-1a.mm" }
 
 extern "C" {
diff -r c7b371acdb35 gcc/testsuite/obj-c++.dg/torture/tls/thr-init-1.mm
--- a/gcc/testsuite/obj-c++.dg/torture/tls/thr-init-1.mm	Mon Jul 12 16:03:30 2010 +0200
+++ b/gcc/testsuite/obj-c++.dg/torture/tls/thr-init-1.mm	Thu Jul 15 18:27:58 2010 +0200
@@ -1,5 +1,6 @@ 
 // { dg-do run }
 // { dg-require-effective-target tls }
+// { dg-add-options tls }
 /* { dg-skip-if "PR44140" { *-*-* } { "-flto" "-fwhopr" } { "" } } */
 extern "C" {
 extern void abort ();
diff -r c7b371acdb35 gcc/testsuite/obj-c++.dg/torture/tls/thr-init-2.mm
--- a/gcc/testsuite/obj-c++.dg/torture/tls/thr-init-2.mm	Mon Jul 12 16:03:30 2010 +0200
+++ b/gcc/testsuite/obj-c++.dg/torture/tls/thr-init-2.mm	Thu Jul 15 18:27:58 2010 +0200
@@ -1,5 +1,6 @@ 
 // { dg-do run }
 // { dg-require-effective-target tls }
+// { dg-add-options tls }
 /* { dg-skip-if "PR44140" { *-*-* } { "-flto" "-fwhopr" } { "" } } */
 
 extern "C" {
@@ -42,4 +43,4 @@ 
     abort () ;
   
   return 0;
-}
\ No newline at end of file
+}
diff -r c7b371acdb35 gcc/testsuite/obj-c++.dg/torture/tls/thr-init-3.mm
--- a/gcc/testsuite/obj-c++.dg/torture/tls/thr-init-3.mm	Mon Jul 12 16:03:30 2010 +0200
+++ b/gcc/testsuite/obj-c++.dg/torture/tls/thr-init-3.mm	Thu Jul 15 18:27:58 2010 +0200
@@ -1,5 +1,6 @@ 
 /* { dg-do run } */
 /* { dg-require-effective-target tls } */
+/* { dg-add-options tls } */
 /* { dg-skip-if "PR44140" { *-*-* } { "-flto" "-fwhopr" } { "" } } */
 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
 /* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.mm" } */
diff -r c7b371acdb35 gcc/testsuite/objc.dg/torture/tls/thr-init-2.m
--- a/gcc/testsuite/objc.dg/torture/tls/thr-init-2.m	Mon Jul 12 16:03:30 2010 +0200
+++ b/gcc/testsuite/objc.dg/torture/tls/thr-init-2.m	Thu Jul 15 18:27:58 2010 +0200
@@ -1,5 +1,6 @@ 
 // { dg-do run }
 // { dg-require-effective-target tls }
+// { dg-add-options tls }
 /* { dg-skip-if "PR44140" { *-*-* } { "-flto" "-fwhopr" } { "" } } */
 
 extern void _exit(int);
diff -r c7b371acdb35 gcc/testsuite/objc.dg/torture/tls/thr-init-3.m
--- a/gcc/testsuite/objc.dg/torture/tls/thr-init-3.m	Mon Jul 12 16:03:30 2010 +0200
+++ b/gcc/testsuite/objc.dg/torture/tls/thr-init-3.m	Thu Jul 15 18:27:58 2010 +0200
@@ -1,5 +1,6 @@ 
 /* { dg-do run } */
 /* { dg-require-effective-target tls } */
+/* { dg-add-options tls } */
 /* { dg-skip-if "PR44140" { *-*-* } { "-flto" "-fwhopr" } { "" } } */
 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
 /* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.m" } */
diff -r c7b371acdb35 gcc/testsuite/objc.dg/torture/tls/thr-init.m
--- a/gcc/testsuite/objc.dg/torture/tls/thr-init.m	Mon Jul 12 16:03:30 2010 +0200
+++ b/gcc/testsuite/objc.dg/torture/tls/thr-init.m	Thu Jul 15 18:27:58 2010 +0200
@@ -1,5 +1,6 @@ 
 /* { dg-do run } */
 /* { dg-require-effective-target tls } */
+/* { dg-add-options tls } */
 /* { dg-skip-if "PR44140" { *-*-* } { "-flto" "-fwhopr" } { "" } } */
 
 extern void _exit(int);
diff -r c7b371acdb35 libgomp/configure.tgt
--- a/libgomp/configure.tgt	Mon Jul 12 16:03:30 2010 +0200
+++ b/libgomp/configure.tgt	Thu Jul 15 18:27:58 2010 +0200
@@ -116,11 +116,6 @@ 
 	config_path="mingw32 posix"
 	;;
 
-  *-*-solaris2.[56]*)
-	config_path="posix95 posix"
-	XLDFLAGS="${XLDFLAGS} -lposix4"
-	;;
-
   *-*-darwin*)
 	config_path="bsd posix"
 	;;
diff -r c7b371acdb35 libjava/configure.ac
--- a/libjava/configure.ac	Mon Jul 12 16:03:30 2010 +0200
+++ b/libjava/configure.ac	Thu Jul 15 18:27:58 2010 +0200
@@ -1064,6 +1064,19 @@ 
 	THREADLIBS='-lpthread -lrt'
 	THREADSPEC='-lpthread -lrt'
 	;;
+     *-*-solaris2.8)
+	# Always use alternate thread library on Solaris 8.  Need libthread
+	# for TLS support.
+	# Need -Wl,-R to get it through libtool ...
+	THREADLIBS='-L/usr/lib/lwp$(MULTISUBDIR) -Wl,-R -Wl,/usr/lib/lwp$(MULTISUBDIR) -lpthread -lthread'
+	# ... while ld only accepts -R.
+	THREADSPEC='-L/usr/lib/lwp%{m64:/64} -R/usr/lib/lwp%{m64:/64} -lpthread -lthread'
+        ;;
+     *-*-solaris2.9)
+	# As on Solaris 8, need libthread for TLS support.
+	THREADLIBS='-lpthread -lthread'
+	THREADSPEC='-lpthread -lthread'
+	;;
      *)
 	THREADLIBS=-lpthread
 	THREADSPEC=-lpthread