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