PR32387 ppc64 TLS optimization bug with -fno-plt code

Message ID Z0WomuR2URSo9m_N@squeak.grove.modra.org
State New
Headers
Series PR32387 ppc64 TLS optimization bug with -fno-plt code |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

Alan Modra Nov. 26, 2024, 10:53 a.m. UTC
  The inline plt code emitted by gcc is incompatible with the
linker/ld.so --tls-get-addr-optimize scheme.  This is the runtime
optimisation where the first call to __tls_get_addr results in
__tls_get_addr updating the tls_index pair, then the special linker
stub using that to short-circuit second and subsequent calls for a
given tls symbol.  Enabled by default when the linker sees
__tls_get_addr_opt is preseent, and enabled in ld.so when DT_PPC64_OPT
has PPC64_OPT_TLS set.  Note that this is distinct from link-time tls
optimisation.

	PR 32387
	* elf64-ppc.c (ppc64_elf_check_relocs): Disable tls_get_addr_opt
	on detecting inline plt calls to __tls_get_addr.
  

Comments

Peter Bergner Nov. 26, 2024, 2:19 p.m. UTC | #1
On 11/26/24 4:53 AM, Alan Modra wrote:
> The inline plt code emitted by gcc is incompatible with the
> linker/ld.so --tls-get-addr-optimize scheme.  This is the runtime
> optimisation where the first call to __tls_get_addr results in
> __tls_get_addr updating the tls_index pair, then the special linker
> stub using that to short-circuit second and subsequent calls for a
> given tls symbol.  Enabled by default when the linker sees
> __tls_get_addr_opt is preseent, and enabled in ld.so when DT_PPC64_OPT
> has PPC64_OPT_TLS set.  Note that this is distinct from link-time tls
> optimisation.
> 
> 	PR 32387
> 	* elf64-ppc.c (ppc64_elf_check_relocs): Disable tls_get_addr_opt
> 	on detecting inline plt calls to __tls_get_addr.

Thanks for the fix Alan!

Is this something we want back ported to one or more of the release branches?
I can do the backports if you just let me know how far back you want the
fix to go.

Peter
  

Patch

diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
index 9674fcdd6be..f7debc1edbc 100644
--- a/bfd/elf64-ppc.c
+++ b/bfd/elf64-ppc.c
@@ -4915,6 +4915,15 @@  ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
       tls_type = 0;
       switch (r_type)
 	{
+	case R_PPC64_PLTSEQ:
+	case R_PPC64_PLTSEQ_NOTOC:
+	  /* Inline plt call code emitted by gcc doesn't support
+	     modifying the tls_index words to short-circuit
+	     __tls_get_addr calls.  See PR32387.  */
+	  if (h != NULL && (h == tga || h == dottga))
+	    htab->params->tls_get_addr_opt = 0;
+	  break;
+
 	case R_PPC64_TLSGD:
 	case R_PPC64_TLSLD:
 	  /* These special tls relocs tie a call to __tls_get_addr with