25845f
Recreation of this upstream commit:
25845f
25845f
commit 3d8c8bff798a15b6dc0ee94d24fc877db9706589
25845f
Author: Andreas Schwab <schwab@suse.de>
25845f
Date:   Tue Mar 25 11:55:52 2014 +0100
25845f
25845f
    Remove last use of USE___THREAD
25845f
25845f
This was done using unifdef -m -UUSE___THREAD elf/rtld.c, followed by a
25845f
manual reindent.
25845f
25845f
diff --git a/elf/rtld.c b/elf/rtld.c
25845f
index b5a859ecff740705..e934ad38db39d343 100644
25845f
--- a/elf/rtld.c
25845f
+++ b/elf/rtld.c
25845f
@@ -382,19 +382,8 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
25845f
   GL(dl_rtld_map).l_text_end = (ElfW(Addr)) _etext;
25845f
   /* Copy the TLS related data if necessary.  */
25845f
 #ifndef DONT_USE_BOOTSTRAP_MAP
25845f
-# if USE___THREAD
25845f
-  assert (info->l.l_tls_modid != 0);
25845f
-  GL(dl_rtld_map).l_tls_blocksize = info->l.l_tls_blocksize;
25845f
-  GL(dl_rtld_map).l_tls_align = info->l.l_tls_align;
25845f
-  GL(dl_rtld_map).l_tls_firstbyte_offset = info->l.l_tls_firstbyte_offset;
25845f
-  GL(dl_rtld_map).l_tls_initimage_size = info->l.l_tls_initimage_size;
25845f
-  GL(dl_rtld_map).l_tls_initimage = info->l.l_tls_initimage;
25845f
-  GL(dl_rtld_map).l_tls_offset = info->l.l_tls_offset;
25845f
-  GL(dl_rtld_map).l_tls_modid = 1;
25845f
-# else
25845f
-#  if NO_TLS_OFFSET != 0
25845f
+# if NO_TLS_OFFSET != 0
25845f
   GL(dl_rtld_map).l_tls_offset = NO_TLS_OFFSET;
25845f
-#  endif
25845f
 # endif
25845f
 
25845f
 #endif
25845f
@@ -476,9 +465,6 @@ _dl_start (void *arg)
25845f
        ++cnt)
25845f
     bootstrap_map.l_info[cnt] = 0;
25845f
 # endif
25845f
-# if USE___THREAD
25845f
-  bootstrap_map.l_tls_modid = 0;
25845f
-# endif
25845f
 #endif
25845f
 
25845f
   /* Figure out the run-time load address of the dynamic linker itself.  */
25845f
@@ -497,117 +483,6 @@ _dl_start (void *arg)
25845f
      to it.  When we have something like GOTOFF relocs, we can use a plain
25845f
      reference to find the runtime address.  Without that, we have to rely
25845f
      on the `l_addr' value, which is not the value we want when prelinked.  */
25845f
-#if USE___THREAD
25845f
-  dtv_t initdtv[3];
25845f
-  ElfW(Ehdr) *ehdr
25845f
-# ifdef DONT_USE_BOOTSTRAP_MAP
25845f
-    = (ElfW(Ehdr) *) &_begin;
25845f
-# else
25845f
-#  error This will not work with prelink.
25845f
-    = (ElfW(Ehdr) *) bootstrap_map.l_addr;
25845f
-# endif
25845f
-  ElfW(Phdr) *phdr = (ElfW(Phdr) *) ((void *) ehdr + ehdr->e_phoff);
25845f
-  size_t cnt = ehdr->e_phnum;	/* PT_TLS is usually the last phdr.  */
25845f
-  while (cnt-- > 0)
25845f
-    if (phdr[cnt].p_type == PT_TLS)
25845f
-      {
25845f
-	void *tlsblock;
25845f
-	size_t max_align = MAX (TLS_INIT_TCB_ALIGN, phdr[cnt].p_align);
25845f
-	char *p;
25845f
-
25845f
-	bootstrap_map.l_tls_blocksize = phdr[cnt].p_memsz;
25845f
-	bootstrap_map.l_tls_align = phdr[cnt].p_align;
25845f
-	if (phdr[cnt].p_align == 0)
25845f
-	  bootstrap_map.l_tls_firstbyte_offset = 0;
25845f
-	else
25845f
-	  bootstrap_map.l_tls_firstbyte_offset = (phdr[cnt].p_vaddr
25845f
-						  & (phdr[cnt].p_align - 1));
25845f
-	assert (bootstrap_map.l_tls_blocksize != 0);
25845f
-	bootstrap_map.l_tls_initimage_size = phdr[cnt].p_filesz;
25845f
-	bootstrap_map.l_tls_initimage = (void *) (bootstrap_map.l_addr
25845f
-						  + phdr[cnt].p_vaddr);
25845f
-
25845f
-	/* We can now allocate the initial TLS block.  This can happen
25845f
-	   on the stack.  We'll get the final memory later when we
25845f
-	   know all about the various objects loaded at startup
25845f
-	   time.  */
25845f
-# if TLS_TCB_AT_TP
25845f
-	tlsblock = alloca (roundup (bootstrap_map.l_tls_blocksize,
25845f
-				    TLS_INIT_TCB_ALIGN)
25845f
-			   + TLS_INIT_TCB_SIZE
25845f
-			   + max_align);
25845f
-# elif TLS_DTV_AT_TP
25845f
-	tlsblock = alloca (roundup (TLS_INIT_TCB_SIZE,
25845f
-				    bootstrap_map.l_tls_align)
25845f
-			   + bootstrap_map.l_tls_blocksize
25845f
-			   + max_align);
25845f
-# else
25845f
-	/* In case a model with a different layout for the TCB and DTV
25845f
-	   is defined add another #elif here and in the following #ifs.  */
25845f
-#  error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
25845f
-# endif
25845f
-	/* Align the TLS block.  */
25845f
-	tlsblock = (void *) (((uintptr_t) tlsblock + max_align - 1)
25845f
-			     & ~(max_align - 1));
25845f
-
25845f
-	/* Initialize the dtv.  [0] is the length, [1] the generation
25845f
-	   counter.  */
25845f
-	initdtv[0].counter = 1;
25845f
-	initdtv[1].counter = 0;
25845f
-
25845f
-	/* Initialize the TLS block.  */
25845f
-# if TLS_TCB_AT_TP
25845f
-	initdtv[2].pointer = tlsblock;
25845f
-# elif TLS_DTV_AT_TP
25845f
-	bootstrap_map.l_tls_offset = roundup (TLS_INIT_TCB_SIZE,
25845f
-					      bootstrap_map.l_tls_align);
25845f
-	initdtv[2].pointer = (char *) tlsblock + bootstrap_map.l_tls_offset;
25845f
-# else
25845f
-#  error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
25845f
-# endif
25845f
-	p = __mempcpy (initdtv[2].pointer, bootstrap_map.l_tls_initimage,
25845f
-		       bootstrap_map.l_tls_initimage_size);
25845f
-# ifdef HAVE_BUILTIN_MEMSET
25845f
-	__builtin_memset (p, '\0', (bootstrap_map.l_tls_blocksize
25845f
-				    - bootstrap_map.l_tls_initimage_size));
25845f
-# else
25845f
-	{
25845f
-	  size_t remaining = (bootstrap_map.l_tls_blocksize
25845f
-			      - bootstrap_map.l_tls_initimage_size);
25845f
-	  while (remaining-- > 0)
25845f
-	    *p++ = '\0';
25845f
-	}
25845f
-# endif
25845f
-
25845f
-	/* Install the pointer to the dtv.  */
25845f
-
25845f
-	/* Initialize the thread pointer.  */
25845f
-# if TLS_TCB_AT_TP
25845f
-	bootstrap_map.l_tls_offset
25845f
-	  = roundup (bootstrap_map.l_tls_blocksize, TLS_INIT_TCB_ALIGN);
25845f
-
25845f
-	INSTALL_DTV ((char *) tlsblock + bootstrap_map.l_tls_offset,
25845f
-		     initdtv);
25845f
-
25845f
-	const char *lossage = TLS_INIT_TP ((char *) tlsblock
25845f
-					   + bootstrap_map.l_tls_offset, 0);
25845f
-# elif TLS_DTV_AT_TP
25845f
-	INSTALL_DTV (tlsblock, initdtv);
25845f
-	const char *lossage = TLS_INIT_TP (tlsblock, 0);
25845f
-# else
25845f
-#  error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
25845f
-# endif
25845f
-	if (__builtin_expect (lossage != NULL, 0))
25845f
-	  _dl_fatal_printf ("cannot set up thread-local storage: %s\n",
25845f
-			    lossage);
25845f
-
25845f
-	/* So far this is module number one.  */
25845f
-	bootstrap_map.l_tls_modid = 1;
25845f
-
25845f
-	/* There can only be one PT_TLS entry.  */
25845f
-	break;
25845f
-      }
25845f
-#endif	/* USE___THREAD */
25845f
 
25845f
 #ifdef ELF_MACHINE_BEFORE_RTLD_RELOC
25845f
   ELF_MACHINE_BEFORE_RTLD_RELOC (bootstrap_map.l_info);
25845f
@@ -853,12 +728,7 @@ cannot allocate TLS data structures for initial thread");
25845f
 
25845f
   /* And finally install it for the main thread.  If ld.so itself uses
25845f
      TLS we know the thread pointer was initialized earlier.  */
25845f
-  const char *lossage
25845f
-#ifdef USE___THREAD
25845f
-    = TLS_INIT_TP (tcbp, USE___THREAD);
25845f
-#else
25845f
-    = TLS_INIT_TP (tcbp, 0);
25845f
-#endif
25845f
+  const char *lossage = TLS_INIT_TP (tcbp, 0);
25845f
   if (__builtin_expect (lossage != NULL, 0))
25845f
     _dl_fatal_printf ("cannot set up thread-local storage: %s\n", lossage);
25845f
   tls_init_tp_called = true;
25845f
@@ -2344,11 +2214,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
25845f
   if (! tls_init_tp_called)
25845f
     {
25845f
       const char *lossage
25845f
-#ifdef USE___THREAD
25845f
-	= TLS_INIT_TP (tcbp, USE___THREAD);
25845f
-#else
25845f
 	= TLS_INIT_TP (tcbp, 0);
25845f
-#endif
25845f
       if (__builtin_expect (lossage != NULL, 0))
25845f
 	_dl_fatal_printf ("cannot set up thread-local storage: %s\n",
25845f
 			  lossage);