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