6c0556
commit 55c9f3238080e9aba733bc0902779c46cfa16446
6c0556
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
6c0556
Date:   Thu Feb 11 11:52:24 2021 +0000
6c0556
6c0556
    x86_64: Remove lazy tlsdesc relocation related code
6c0556
    
6c0556
    _dl_tlsdesc_resolve_rela and _dl_tlsdesc_resolve_hold are only used for
6c0556
    lazy tlsdesc relocation processing which is no longer supported.
6c0556
6c0556
diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h
6c0556
index ef5740ba281c7282..b94d3b39ec1dca64 100644
6c0556
--- a/sysdeps/x86_64/dl-machine.h
6c0556
+++ b/sysdeps/x86_64/dl-machine.h
6c0556
@@ -127,10 +127,6 @@ elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
6c0556
 	}
6c0556
     }
6c0556
 
6c0556
-  if (l->l_info[ADDRIDX (DT_TLSDESC_GOT)] && lazy)
6c0556
-    *(ElfW(Addr)*)(D_PTR (l, l_info[ADDRIDX (DT_TLSDESC_GOT)]) + l->l_addr)
6c0556
-      = (ElfW(Addr)) &_dl_tlsdesc_resolve_rela;
6c0556
-
6c0556
   return lazy;
6c0556
 }
6c0556
 
6c0556
diff --git a/sysdeps/x86_64/dl-tlsdesc.S b/sysdeps/x86_64/dl-tlsdesc.S
6c0556
index 80d771cd887dd626..77e78cf0a6d8babc 100644
6c0556
--- a/sysdeps/x86_64/dl-tlsdesc.S
6c0556
+++ b/sysdeps/x86_64/dl-tlsdesc.S
6c0556
@@ -148,107 +148,3 @@ _dl_tlsdesc_dynamic:
6c0556
 	cfi_endproc
6c0556
 	.size	_dl_tlsdesc_dynamic, .-_dl_tlsdesc_dynamic
6c0556
 #endif /* SHARED */
6c0556
-
6c0556
-     /* This function is a wrapper for a lazy resolver for TLS_DESC
6c0556
-	RELA relocations.  The incoming 0(%rsp) points to the caller's
6c0556
-	link map, pushed by the dynamic object's internal lazy TLS
6c0556
-	resolver front-end before tail-calling us.  We need to pop it
6c0556
-	ourselves.  %rax points to a TLS descriptor, such that 0(%rax)
6c0556
-	holds the address of the internal resolver front-end (unless
6c0556
-	some other thread beat us to resolving it) and 8(%rax) holds a
6c0556
-	pointer to the relocation.
6c0556
-
6c0556
-	When the actual resolver returns, it will have adjusted the
6c0556
-	TLS descriptor such that we can tail-call it for it to return
6c0556
-	the TP offset of the symbol.  */
6c0556
-
6c0556
-	.hidden _dl_tlsdesc_resolve_rela
6c0556
-	.global	_dl_tlsdesc_resolve_rela
6c0556
-	.type	_dl_tlsdesc_resolve_rela,@function
6c0556
-	cfi_startproc
6c0556
-	.align 16
6c0556
-	/* The PLT entry will have pushed the link_map pointer.  */
6c0556
-_dl_tlsdesc_resolve_rela:
6c0556
-	_CET_ENDBR
6c0556
-	cfi_adjust_cfa_offset (8)
6c0556
-	/* Save all call-clobbered registers.  Add 8 bytes for push in
6c0556
-	   the PLT entry to align the stack.  */
6c0556
-	subq	$80, %rsp
6c0556
-	cfi_adjust_cfa_offset (80)
6c0556
-	movq	%rax, (%rsp)
6c0556
-	movq	%rdi, 8(%rsp)
6c0556
-	movq	%rax, %rdi	/* Pass tlsdesc* in %rdi.  */
6c0556
-	movq	%rsi, 16(%rsp)
6c0556
-	movq	80(%rsp), %rsi	/* Pass link_map* in %rsi.  */
6c0556
-	movq	%r8, 24(%rsp)
6c0556
-	movq	%r9, 32(%rsp)
6c0556
-	movq	%r10, 40(%rsp)
6c0556
-	movq	%r11, 48(%rsp)
6c0556
-	movq	%rdx, 56(%rsp)
6c0556
-	movq	%rcx, 64(%rsp)
6c0556
-	call	_dl_tlsdesc_resolve_rela_fixup
6c0556
-	movq	(%rsp), %rax
6c0556
-	movq	8(%rsp), %rdi
6c0556
-	movq	16(%rsp), %rsi
6c0556
-	movq	24(%rsp), %r8
6c0556
-	movq	32(%rsp), %r9
6c0556
-	movq	40(%rsp), %r10
6c0556
-	movq	48(%rsp), %r11
6c0556
-	movq	56(%rsp), %rdx
6c0556
-	movq	64(%rsp), %rcx
6c0556
-	addq	$88, %rsp
6c0556
-	cfi_adjust_cfa_offset (-88)
6c0556
-	jmp	*(%rax)
6c0556
-	cfi_endproc
6c0556
-	.size	_dl_tlsdesc_resolve_rela, .-_dl_tlsdesc_resolve_rela
6c0556
-
6c0556
-     /* This function is a placeholder for lazy resolving of TLS
6c0556
-	relocations.  Once some thread starts resolving a TLS
6c0556
-	relocation, it sets up the TLS descriptor to use this
6c0556
-	resolver, such that other threads that would attempt to
6c0556
-	resolve it concurrently may skip the call to the original lazy
6c0556
-	resolver and go straight to a condition wait.
6c0556
-
6c0556
-	When the actual resolver returns, it will have adjusted the
6c0556
-	TLS descriptor such that we can tail-call it for it to return
6c0556
-	the TP offset of the symbol.  */
6c0556
-
6c0556
-	.hidden _dl_tlsdesc_resolve_hold
6c0556
-	.global	_dl_tlsdesc_resolve_hold
6c0556
-	.type	_dl_tlsdesc_resolve_hold,@function
6c0556
-	cfi_startproc
6c0556
-	.align 16
6c0556
-_dl_tlsdesc_resolve_hold:
6c0556
-0:
6c0556
-	_CET_ENDBR
6c0556
-	/* Save all call-clobbered registers.  */
6c0556
-	subq	$72, %rsp
6c0556
-	cfi_adjust_cfa_offset (72)
6c0556
-	movq	%rax, (%rsp)
6c0556
-	movq	%rdi, 8(%rsp)
6c0556
-	movq	%rax, %rdi	/* Pass tlsdesc* in %rdi.  */
6c0556
-	movq	%rsi, 16(%rsp)
6c0556
-	/* Pass _dl_tlsdesc_resolve_hold's address in %rsi.  */
6c0556
-	leaq	. - _dl_tlsdesc_resolve_hold(%rip), %rsi
6c0556
-	movq	%r8, 24(%rsp)
6c0556
-	movq	%r9, 32(%rsp)
6c0556
-	movq	%r10, 40(%rsp)
6c0556
-	movq	%r11, 48(%rsp)
6c0556
-	movq	%rdx, 56(%rsp)
6c0556
-	movq	%rcx, 64(%rsp)
6c0556
-	call	_dl_tlsdesc_resolve_hold_fixup
6c0556
-1:
6c0556
-	movq	(%rsp), %rax
6c0556
-	movq	8(%rsp), %rdi
6c0556
-	movq	16(%rsp), %rsi
6c0556
-	movq	24(%rsp), %r8
6c0556
-	movq	32(%rsp), %r9
6c0556
-	movq	40(%rsp), %r10
6c0556
-	movq	48(%rsp), %r11
6c0556
-	movq	56(%rsp), %rdx
6c0556
-	movq	64(%rsp), %rcx
6c0556
-	addq	$72, %rsp
6c0556
-	cfi_adjust_cfa_offset (-72)
6c0556
-	jmp	*(%rax)
6c0556
-	cfi_endproc
6c0556
-	.size	_dl_tlsdesc_resolve_hold, .-_dl_tlsdesc_resolve_hold
6c0556
diff --git a/sysdeps/x86_64/dl-tlsdesc.h b/sysdeps/x86_64/dl-tlsdesc.h
6c0556
index 66e659bb5c7ede74..1cde1ee9664f4908 100644
6c0556
--- a/sysdeps/x86_64/dl-tlsdesc.h
6c0556
+++ b/sysdeps/x86_64/dl-tlsdesc.h
6c0556
@@ -55,9 +55,7 @@ struct tlsdesc_dynamic_arg
6c0556
 
6c0556
 extern ptrdiff_t attribute_hidden
6c0556
   _dl_tlsdesc_return(struct tlsdesc *on_rax),
6c0556
-  _dl_tlsdesc_undefweak(struct tlsdesc *on_rax),
6c0556
-  _dl_tlsdesc_resolve_rela(struct tlsdesc *on_rax),
6c0556
-  _dl_tlsdesc_resolve_hold(struct tlsdesc *on_rax);
6c0556
+  _dl_tlsdesc_undefweak(struct tlsdesc *on_rax);
6c0556
 
6c0556
 # ifdef SHARED
6c0556
 extern void *_dl_make_tlsdesc_dynamic (struct link_map *map,
6c0556
diff --git a/sysdeps/x86_64/tlsdesc.c b/sysdeps/x86_64/tlsdesc.c
6c0556
index 302d097dbb0c4f1e..61a19ae26944c84f 100644
6c0556
--- a/sysdeps/x86_64/tlsdesc.c
6c0556
+++ b/sysdeps/x86_64/tlsdesc.c
6c0556
@@ -16,120 +16,13 @@
6c0556
    License along with the GNU C Library; if not, see
6c0556
    <http://www.gnu.org/licenses/>.  */
6c0556
 
6c0556
-#include <link.h>
6c0556
 #include <ldsodefs.h>
6c0556
-#include <elf/dynamic-link.h>
6c0556
 #include <tls.h>
6c0556
 #include <dl-tlsdesc.h>
6c0556
 #include <dl-unmap-segments.h>
6c0556
+#define _dl_tlsdesc_resolve_hold 0
6c0556
 #include <tlsdeschtab.h>
6c0556
 
6c0556
-/* The following 2 functions take a caller argument, that contains the
6c0556
-   address expected to be in the TLS descriptor.  If it's changed, we
6c0556
-   want to return immediately.  */
6c0556
-
6c0556
-/* This function is used to lazily resolve TLS_DESC RELA relocations.
6c0556
-   The argument location is used to hold a pointer to the relocation.  */
6c0556
-
6c0556
-void
6c0556
-attribute_hidden
6c0556
-_dl_tlsdesc_resolve_rela_fixup (struct tlsdesc volatile *td,
6c0556
-				struct link_map *l)
6c0556
-{
6c0556
-  const ElfW(Rela) *reloc = td->arg;
6c0556
-
6c0556
-  if (_dl_tlsdesc_resolve_early_return_p
6c0556
-      (td, (void*)(D_PTR (l, l_info[ADDRIDX (DT_TLSDESC_PLT)]) + l->l_addr)))
6c0556
-    return;
6c0556
-
6c0556
-  /* The code below was borrowed from _dl_fixup().  */
6c0556
-  const ElfW(Sym) *const symtab
6c0556
-    = (const void *) D_PTR (l, l_info[DT_SYMTAB]);
6c0556
-  const char *strtab = (const void *) D_PTR (l, l_info[DT_STRTAB]);
6c0556
-  const ElfW(Sym) *sym = &symtab[ELFW(R_SYM) (reloc->r_info)];
6c0556
-  lookup_t result;
6c0556
-
6c0556
-   /* Look up the target symbol.  If the normal lookup rules are not
6c0556
-      used don't look in the global scope.  */
6c0556
-  if (ELFW(ST_BIND) (sym->st_info) != STB_LOCAL
6c0556
-      && __builtin_expect (ELFW(ST_VISIBILITY) (sym->st_other), 0) == 0)
6c0556
-    {
6c0556
-      const struct r_found_version *version = NULL;
6c0556
-
6c0556
-      if (l->l_info[VERSYMIDX (DT_VERSYM)] != NULL)
6c0556
-	{
6c0556
-	  const ElfW(Half) *vernum =
6c0556
-	    (const void *) D_PTR (l, l_info[VERSYMIDX (DT_VERSYM)]);
6c0556
-	  ElfW(Half) ndx = vernum[ELFW(R_SYM) (reloc->r_info)] & 0x7fff;
6c0556
-	  version = &l->l_versions[ndx];
6c0556
-	  if (version->hash == 0)
6c0556
-	    version = NULL;
6c0556
-	}
6c0556
-
6c0556
-      result = _dl_lookup_symbol_x (strtab + sym->st_name, l, &sym,
6c0556
-				    l->l_scope, version, ELF_RTYPE_CLASS_PLT,
6c0556
-				    DL_LOOKUP_ADD_DEPENDENCY, NULL);
6c0556
-    }
6c0556
-  else
6c0556
-    {
6c0556
-      /* We already found the symbol.  The module (and therefore its load
6c0556
-	 address) is also known.  */
6c0556
-      result = l;
6c0556
-    }
6c0556
-
6c0556
-  if (! sym)
6c0556
-    {
6c0556
-      td->arg = (void*)reloc->r_addend;
6c0556
-      td->entry = _dl_tlsdesc_undefweak;
6c0556
-    }
6c0556
-  else
6c0556
-    {
6c0556
-#  ifndef SHARED
6c0556
-      CHECK_STATIC_TLS (l, result);
6c0556
-#  else
6c0556
-      if (!TRY_STATIC_TLS (l, result))
6c0556
-	{
6c0556
-	  td->arg = _dl_make_tlsdesc_dynamic (result, sym->st_value
6c0556
-					      + reloc->r_addend);
6c0556
-	  td->entry = _dl_tlsdesc_dynamic;
6c0556
-	}
6c0556
-      else
6c0556
-#  endif
6c0556
-	{
6c0556
-	  td->arg = (void*)(sym->st_value - result->l_tls_offset
6c0556
-			    + reloc->r_addend);
6c0556
-	  td->entry = _dl_tlsdesc_return;
6c0556
-	}
6c0556
-    }
6c0556
-
6c0556
-  _dl_tlsdesc_wake_up_held_fixups ();
6c0556
-}
6c0556
-
6c0556
-/* This function is used to avoid busy waiting for other threads to
6c0556
-   complete the lazy relocation.  Once another thread wins the race to
6c0556
-   relocate a TLS descriptor, it sets the descriptor up such that this
6c0556
-   function is called to wait until the resolver releases the
6c0556
-   lock.  */
6c0556
-
6c0556
-void
6c0556
-attribute_hidden
6c0556
-_dl_tlsdesc_resolve_hold_fixup (struct tlsdesc volatile *td,
6c0556
-				void *caller)
6c0556
-{
6c0556
-  /* Maybe we're lucky and can return early.  */
6c0556
-  if (caller != td->entry)
6c0556
-    return;
6c0556
-
6c0556
-  /* Locking here will stop execution until the running resolver runs
6c0556
-     _dl_tlsdesc_wake_up_held_fixups(), releasing the lock.
6c0556
-
6c0556
-     FIXME: We'd be better off waiting on a condition variable, such
6c0556
-     that we didn't have to hold the lock throughout the relocation
6c0556
-     processing.  */
6c0556
-  __rtld_lock_lock_recursive (GL(dl_load_lock));
6c0556
-  __rtld_lock_unlock_recursive (GL(dl_load_lock));
6c0556
-}
6c0556
-
6c0556
 /* Unmap the dynamic object, but also release its TLS descriptor table
6c0556
    if there is one.  */
6c0556