179894
commit a75a02a696f9f869d77b17b99964823aa8833a8b
179894
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
179894
Date:   Thu Feb 11 11:58:20 2021 +0000
179894
179894
    i386: Remove lazy tlsdesc relocation related code
179894
    
179894
    Like in commit e75711ebfa976d5468ec292282566a18b07e4d67 for x86_64,
179894
    remove unused lazy tlsdesc relocation processing code:
179894
    
179894
      _dl_tlsdesc_resolve_abs_plus_addend
179894
      _dl_tlsdesc_resolve_rel
179894
      _dl_tlsdesc_resolve_rela
179894
      _dl_tlsdesc_resolve_hold
179894
179894
diff --git a/sysdeps/i386/dl-tlsdesc.S b/sysdeps/i386/dl-tlsdesc.S
179894
index 128f0af3188f46bb..22ecb2c6adc6cc6e 100644
179894
--- a/sysdeps/i386/dl-tlsdesc.S
179894
+++ b/sysdeps/i386/dl-tlsdesc.S
179894
@@ -138,159 +138,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
-	REL relocations that reference the *ABS* segment in their own
179894
-	link maps.  %ebx points to the caller's GOT.  %eax points to a
179894
-	TLS descriptor, such that 0(%eax) holds the address of the
179894
-	resolver wrapper itself (unless some other thread beat us to
179894
-	it) and 4(%eax) holds the addend in 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_abs_plus_addend
179894
-	.global	_dl_tlsdesc_resolve_abs_plus_addend
179894
-	.type	_dl_tlsdesc_resolve_abs_plus_addend,@function
179894
-	cfi_startproc
179894
-	.align 16
179894
-_dl_tlsdesc_resolve_abs_plus_addend:
179894
-0:
179894
-	_CET_ENDBR
179894
-	pushl	%eax
179894
-	cfi_adjust_cfa_offset (4)
179894
-	pushl	%ecx
179894
-	cfi_adjust_cfa_offset (4)
179894
-	pushl	%edx
179894
-	cfi_adjust_cfa_offset (4)
179894
-	movl	$1f - 0b, %ecx
179894
-	movl	4(%ebx), %edx
179894
-	call	_dl_tlsdesc_resolve_abs_plus_addend_fixup
179894
-1:
179894
-	popl	%edx
179894
-	cfi_adjust_cfa_offset (-4)
179894
-	popl	%ecx
179894
-	cfi_adjust_cfa_offset (-4)
179894
-	popl	%eax
179894
-	cfi_adjust_cfa_offset (-4)
179894
-	jmp	*(%eax)
179894
-	cfi_endproc
179894
-	.size	_dl_tlsdesc_resolve_abs_plus_addend, .-_dl_tlsdesc_resolve_abs_plus_addend
179894
-
179894
-     /* This function is a wrapper for a lazy resolver for TLS_DESC
179894
-	REL relocations that had zero addends.  %ebx points to the
179894
-	caller's GOT.  %eax points to a TLS descriptor, such that
179894
-	0(%eax) holds the address of the resolver wrapper itself
179894
-	(unless some other thread beat us to it) and 4(%eax) 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_rel
179894
-	.global	_dl_tlsdesc_resolve_rel
179894
-	.type	_dl_tlsdesc_resolve_rel,@function
179894
-	cfi_startproc
179894
-	.align 16
179894
-_dl_tlsdesc_resolve_rel:
179894
-0:
179894
-	_CET_ENDBR
179894
-	pushl	%eax
179894
-	cfi_adjust_cfa_offset (4)
179894
-	pushl	%ecx
179894
-	cfi_adjust_cfa_offset (4)
179894
-	pushl	%edx
179894
-	cfi_adjust_cfa_offset (4)
179894
-	movl	$1f - 0b, %ecx
179894
-	movl	4(%ebx), %edx
179894
-	call	_dl_tlsdesc_resolve_rel_fixup
179894
-1:
179894
-	popl	%edx
179894
-	cfi_adjust_cfa_offset (-4)
179894
-	popl	%ecx
179894
-	cfi_adjust_cfa_offset (-4)
179894
-	popl	%eax
179894
-	cfi_adjust_cfa_offset (-4)
179894
-	jmp	*(%eax)
179894
-	cfi_endproc
179894
-	.size	_dl_tlsdesc_resolve_rel, .-_dl_tlsdesc_resolve_rel
179894
-
179894
-     /* This function is a wrapper for a lazy resolver for TLS_DESC
179894
-	RELA relocations.  %ebx points to the caller's GOT.  %eax
179894
-	points to a TLS descriptor, such that 0(%eax) holds the
179894
-	address of the resolver wrapper itself (unless some other
179894
-	thread beat us to it) and 4(%eax) holds a pointer to the
179894
-	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
-_dl_tlsdesc_resolve_rela:
179894
-0:
179894
-	_CET_ENDBR
179894
-	pushl	%eax
179894
-	cfi_adjust_cfa_offset (4)
179894
-	pushl	%ecx
179894
-	cfi_adjust_cfa_offset (4)
179894
-	pushl	%edx
179894
-	cfi_adjust_cfa_offset (4)
179894
-	movl	$1f - 0b, %ecx
179894
-	movl	4(%ebx), %edx
179894
-	call	_dl_tlsdesc_resolve_rela_fixup
179894
-1:
179894
-	popl	%edx
179894
-	cfi_adjust_cfa_offset (-4)
179894
-	popl	%ecx
179894
-	cfi_adjust_cfa_offset (-4)
179894
-	popl	%eax
179894
-	cfi_adjust_cfa_offset (-4)
179894
-	jmp	*(%eax)
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
-	pushl	%eax
179894
-	cfi_adjust_cfa_offset (4)
179894
-	pushl	%ecx
179894
-	cfi_adjust_cfa_offset (4)
179894
-	pushl	%edx
179894
-	cfi_adjust_cfa_offset (4)
179894
-	movl	$1f - 0b, %ecx
179894
-	movl	4(%ebx), %edx
179894
-	call	_dl_tlsdesc_resolve_hold_fixup
179894
-1:
179894
-	popl	%edx
179894
-	cfi_adjust_cfa_offset (-4)
179894
-	popl	%ecx
179894
-	cfi_adjust_cfa_offset (-4)
179894
-	popl	%eax
179894
-	cfi_adjust_cfa_offset (-4)
179894
-	jmp	*(%eax)
179894
-	cfi_endproc
179894
-	.size	_dl_tlsdesc_resolve_hold, .-_dl_tlsdesc_resolve_hold
179894
diff --git a/sysdeps/i386/dl-tlsdesc.h b/sysdeps/i386/dl-tlsdesc.h
179894
index c8a1e056150dc418..1a1a22c303baf85b 100644
179894
--- a/sysdeps/i386/dl-tlsdesc.h
179894
+++ b/sysdeps/i386/dl-tlsdesc.h
179894
@@ -43,11 +43,7 @@ struct tlsdesc_dynamic_arg
179894
 
179894
 extern ptrdiff_t attribute_hidden __attribute__ ((regparm (1)))
179894
   _dl_tlsdesc_return (struct tlsdesc *),
179894
-  _dl_tlsdesc_undefweak (struct tlsdesc *),
179894
-  _dl_tlsdesc_resolve_abs_plus_addend (struct tlsdesc *),
179894
-  _dl_tlsdesc_resolve_rel (struct tlsdesc *),
179894
-  _dl_tlsdesc_resolve_rela (struct tlsdesc *),
179894
-  _dl_tlsdesc_resolve_hold (struct tlsdesc *);
179894
+  _dl_tlsdesc_undefweak (struct tlsdesc *);
179894
 
179894
 # ifdef SHARED
179894
 extern void *_dl_make_tlsdesc_dynamic (struct link_map *map,
179894
diff --git a/sysdeps/i386/tlsdesc.c b/sysdeps/i386/tlsdesc.c
179894
index 82fa8a1d35fd1912..1b4227c8381e1b3d 100644
179894
--- a/sysdeps/i386/tlsdesc.c
179894
+++ b/sysdeps/i386/tlsdesc.c
179894
@@ -16,242 +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 4 functions take an entry_check_offset argument.
179894
-   It's computed by the caller as an offset between its entry point
179894
-   and the call site, such that by adding the built-in return address
179894
-   that is implicitly passed to the function with this offset, we can
179894
-   easily obtain the caller's entry point to compare with the entry
179894
-   point given in the TLS descriptor.  If it's changed, we want to
179894
-   return immediately.  */
179894
-
179894
-/* This function is used to lazily resolve TLS_DESC REL relocations
179894
-   that reference the *ABS* segment in their own link maps.  The
179894
-   argument is the addend originally stored there.  */
179894
-
179894
-void
179894
-__attribute__ ((regparm (3))) attribute_hidden
179894
-_dl_tlsdesc_resolve_abs_plus_addend_fixup (struct tlsdesc volatile *td,
179894
-					   struct link_map *l,
179894
-					   ptrdiff_t entry_check_offset)
179894
-{
179894
-  ptrdiff_t addend = (ptrdiff_t) td->arg;
179894
-
179894
-  if (_dl_tlsdesc_resolve_early_return_p (td, __builtin_return_address (0)
179894
-					  - entry_check_offset))
179894
-    return;
179894
-
179894
-#ifndef SHARED
179894
-  CHECK_STATIC_TLS (l, l);
179894
-#else
179894
-  if (!TRY_STATIC_TLS (l, l))
179894
-    {
179894
-      td->arg = _dl_make_tlsdesc_dynamic (l, addend);
179894
-      td->entry = _dl_tlsdesc_dynamic;
179894
-    }
179894
-  else
179894
-#endif
179894
-    {
179894
-      td->arg = (void*) (addend - l->l_tls_offset);
179894
-      td->entry = _dl_tlsdesc_return;
179894
-    }
179894
-
179894
-  _dl_tlsdesc_wake_up_held_fixups ();
179894
-}
179894
-
179894
-/* This function is used to lazily resolve TLS_DESC REL relocations
179894
-   that originally had zero addends.  The argument location, that
179894
-   originally held the addend, is used to hold a pointer to the
179894
-   relocation, but it has to be restored before we call the function
179894
-   that applies relocations.  */
179894
-
179894
-void
179894
-__attribute__ ((regparm (3))) attribute_hidden
179894
-_dl_tlsdesc_resolve_rel_fixup (struct tlsdesc volatile *td,
179894
-			       struct link_map *l,
179894
-			       ptrdiff_t entry_check_offset)
179894
-{
179894
-  const ElfW(Rel) *reloc = td->arg;
179894
-
179894
-  if (_dl_tlsdesc_resolve_early_return_p (td, __builtin_return_address (0)
179894
-					  - entry_check_offset))
179894
-    return;
179894
-
179894
-  /* The code below was borrowed from _dl_fixup(),
179894
-     except for checking for STB_LOCAL.  */
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 = 0;
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
-	  td->entry = _dl_tlsdesc_dynamic;
179894
-	}
179894
-      else
179894
-#  endif
179894
-	{
179894
-	  td->arg = (void*)(sym->st_value - result->l_tls_offset);
179894
-	  td->entry = _dl_tlsdesc_return;
179894
-	}
179894
-    }
179894
-
179894
-  _dl_tlsdesc_wake_up_held_fixups ();
179894
-}
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__ ((regparm (3))) attribute_hidden
179894
-_dl_tlsdesc_resolve_rela_fixup (struct tlsdesc volatile *td,
179894
-				struct link_map *l,
179894
-				ptrdiff_t entry_check_offset)
179894
-{
179894
-  const ElfW(Rela) *reloc = td->arg;
179894
-
179894
-  if (_dl_tlsdesc_resolve_early_return_p (td, __builtin_return_address (0)
179894
-					  - entry_check_offset))
179894
-    return;
179894
-
179894
-  /* The code below was borrowed from _dl_fixup(),
179894
-     except for checking for STB_LOCAL.  */
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__ ((regparm (3))) attribute_hidden
179894
-_dl_tlsdesc_resolve_hold_fixup (struct tlsdesc volatile *td,
179894
-				struct link_map *l __attribute__((__unused__)),
179894
-				ptrdiff_t entry_check_offset)
179894
-{
179894
-  /* Maybe we're lucky and can return early.  */
179894
-  if (__builtin_return_address (0) - entry_check_offset != 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
-
179894
 /* Unmap the dynamic object, but also release its TLS descriptor table
179894
    if there is one.  */
179894