[build, i386] Disable local dynamic TLS model on Solaris/x86 if as/ld cannot handle it

Uros Bizjak ubizjak@gmail.com
Wed Mar 5 17:22:00 GMT 2014


On Wed, Mar 5, 2014 at 4:53 PM, Rainer Orth <ro@cebitec.uni-bielefeld.de> wrote:
> When using GNU as with Solaris ld, the TLS local dynamic tests
> (gcc.dg/torture/tls/run-ld.c etc.) FAIL to execute before Solaris 11:
> the programs crash with an illegal instruction: e.g. in the
> gcc.dg/lto/20090210 test, we have
>
> 0x8050ce0 <main+48>: mov    %gs:0x0,%eax
> 0x8050ce6 <main+54>: call   0x8050ce7 <main+55>
> 0x8050ce7 <main+55>: cld
> 0x8050ce8 <main+56>: (bad)
>
> The reason is that Solaris ld before Solaris 11 requires the use of the
> @tlsldmplt relocation documented in the Solaris 10 Linker and Libraries
> Guide:
>
> http://docs.oracle.com/cd/E26505_01/html/E26506/chapter8-20.html#gentextid-23600
>
> Unfortunately, gas doesn't support that relocation.  While adding the
> gas side was easy, I completely failed for gld and didn't propose the
> incomplete patch to binutils since it would (rightly) have been
> rejected.
>
> Old versions of ld mishandle the TLS LD code sequence emitted by gcc
> when @tlsldmplt isn't available, causing the crashes observed.  So ld
> cannot handle what gas emits and gas cannot emit what ld requires.  The
> only solution seems to fall back to the GD model in that case, which is
> ugly but certainly better than having perfectly valid programs crash.
>
> The following patch does just that.  It carefully restricts its actions
> to Solaris.  I'm falling back to using dis when objdump isn't available
> to avoid enabling this fallback unnecessarily.
>
> Bootstraps on i386-pc-solaris2.{9,10,11} (as/ld, gas/ld, gas/gld,
> as/gld), amd64-pc-solaris2.{10,11} (as/ld, gas/ld),
> x86_64-unknown-linux-gnu, and i686-unknown-linux-gnu either completed
> successfully or still running.
>
> Ok for mainline if those pass?
>
> Thanks.
>         Rainer
>
>
> 2014-03-04  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
>
>         * configure.ac (TLS_SECTION_ASM_FLAG): Save as tls_section_flag.
>         (LIB_TLS_SPEC): Save as ld_tls_libs.
>         (HAVE_AS_IX86_TLSLDMPLT): Define as 1/0.
>         (HAVE_AS_IX86_TLSLDM): New test.
>         * configure, config.in: Regenerate.
>         * config/i386/i386.c (legitimize_tls_address): Fall back to
>         TLS_MODEL_GLOBAL_DYNAMIC on 32-bit Solaris/x86 if tool chain
>         cannot support TLS_MODEL_LOCAL_DYNAMIC.
>         * config/i386/i386.md (*tls_local_dynamic_base_32_gnu): Use if
>         instead of #ifdef in HAVE_AS_IX86_TLSLDMPLT test.

OK for mainline on x86 part (and the configure check approach). The
patch still needs build maintainer approval as the added code in
config.in does not look that trivial to me.

Thanks,
Uros.



More information about the Gcc-patches mailing list