Call tls_get_addr via GOT for GNU TLS if possible
authorH.J. Lu <hjl@gcc.gnu.org>
Fri, 24 Jun 2016 17:32:52 +0000 (10:32 -0700)
committerH.J. Lu <hjl@gcc.gnu.org>
Fri, 24 Jun 2016 17:32:52 +0000 (10:32 -0700)
commitde86ff8f97fa7352f4be371b053f7c3dcd4290c0
treeaee674d43127c835322300b182f3d315b08bbe59
parenta7898180189f1aee3fba9d99b458c9800fadec61
Call tls_get_addr via GOT for GNU TLS if possible

There are extensions to x86-64 psABI:

https://groups.google.com/forum/#!topic/x86-64-abi/de5_KnLHxtI

and i386 psABI:

https://groups.google.com/forum/#!topic/ia32-abi/awsRSvJOJfs

to call tls_get_addr via GOT.  X86 assembler and linker in binutils 2.27
implemented

call *__tls_get_addr@GOTPCREL(%rip)

in 64-bit and

call *___tls_get_addr@GOT(%reg)

in 32-bit to access global and local thread loal variables in shared
library.  We check if 32-bit x86 assembler and linker work with

call *___tls_get_addr@GOT(%reg)

as 32-bit and 64-bit assembler and linker are enabled togther.

In 32-bit, since any integer register except EAX, which is used to pass
parameter to ___tls_get_addr, and ESP, can be used as GOT base, a new
register class, TLS_GOTBASE_REGS, along with a new constraint, Yb, are
added.  They are used to improve register allocation for 32-bit dynamic
TLS patterns.

gcc/

* configure.ac (calling ___tls_get_addr via GOT): New
assembler/linker check.
(HAVE_AS_IX86_TLS_GET_ADDR_GOT): New.  Defined to 1 if 32-bit
assembler and linker supports calling ___tls_get_addr via GOT.
Otherise, defined to 0.
* config.in: Regenerated.
* configure: Likewise.
* config/i386/constraints.md (Yb): New constraint.
* config/i386/i386.h (reg_class): Add TLS_GOTBASE_REGS.
(REG_CLASS_NAMES): Likewise.
(REG_CLASS_CONTENTS): Likewise.
* config/i386/i386.md (*tls_global_dynamic_32_gnu): Replace
the b constraint with the Yb constraint.  Call ___tls_get_addr
via GOT for GNU TLS with -fno-plt if HAVE_AS_IX86_TLS_GET_ADDR_GOT
is 1.
(*tls_local_dynamic_base_32_gnu): Likewise.
(*tls_global_dynamic_64_<mode>): Call _tls_get_addr via GOT for
GNU TLS with -fno-plt if HAVE_AS_IX86_TLS_GET_ADDR_GOT is 1.
(*tls_local_dynamic_base_64_<mode>): Likewise.

gcc/testsuite/

* gcc.target/i386/noplt-gd-1.c: New test.
* gcc.target/i386/noplt-gd-2.c: Likewise.
* gcc.target/i386/noplt-gd-3.c: Likewise.
* gcc.target/i386/noplt-ld-1.c: Likewise.
* gcc.target/i386/noplt-ld-2.c: Likewise.
* gcc.target/i386/noplt-ld-3.c: Likewise.
* lib/target-supports.exp
(check_effective_target_tls_get_addr_via_got): New.

From-SVN: r237765
13 files changed:
gcc/config.in
gcc/config/i386/constraints.md
gcc/config/i386/i386.h
gcc/config/i386/i386.md
gcc/configure
gcc/configure.ac
gcc/testsuite/gcc.target/i386/noplt-gd-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/noplt-gd-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/noplt-gd-3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/noplt-ld-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/noplt-ld-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/noplt-ld-3.c [new file with mode: 0644]
gcc/testsuite/lib/target-supports.exp