about summary refs log tree commit diff
path: root/sysdeps/generic
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/generic')
-rw-r--r--sysdeps/generic/libc-start.c9
-rw-r--r--sysdeps/generic/libc-tls.c10
2 files changed, 11 insertions, 8 deletions
diff --git a/sysdeps/generic/libc-start.c b/sysdeps/generic/libc-start.c
index 600136dae5..8d523e6836 100644
--- a/sysdeps/generic/libc-start.c
+++ b/sysdeps/generic/libc-start.c
@@ -30,7 +30,12 @@ extern int __libc_multiple_libcs;
 extern void *__libc_stack_end;
 
 #ifndef SHARED
-extern void __pthread_initialize_minimal (void) __attribute__ ((weak));
+# include <tls.h>
+extern void __pthread_initialize_minimal (void)
+# if !(USE_TLS - 0)
+     __attribute__ ((weak))
+# endif
+     ;
 #endif
 
 
@@ -91,7 +96,7 @@ BP_SYM (__libc_start_main) (int (*main) (int, char **, char **),
      we need to setup errno.  If there is no thread library and we
      handle TLS the function is defined in the libc to initialized the
      TLS handling.  */
-# ifndef TLS
+# if !(USE_TLS - 0)
   if (__pthread_initialize_minimal)
 # endif
     __pthread_initialize_minimal ();
diff --git a/sysdeps/generic/libc-tls.c b/sysdeps/generic/libc-tls.c
index 6b9a746dd8..6c01f417c5 100644
--- a/sysdeps/generic/libc-tls.c
+++ b/sysdeps/generic/libc-tls.c
@@ -57,14 +57,12 @@ __libc_setup_tls (size_t tcbsize, size_t tcbalign)
   size_t max_align = tcbalign;
   size_t loadaddr = ~0ul;
   size_t tcb_offset;
+  ElfW(Phdr) *phdr;
 
   /* Look through the TLS segment if there is any.  */
   if (_dl_phdr != NULL)
-    {
-      ElfW(Phdr) *phdr = _dl_phdr;
-      size_t phnum = _dl_phnum;
-
-      while (phnum-- > 0)
+    for (phdr = _dl_phdr; phdr < &_dl_phdr[_dl_phnum]; ++phdr)
+      {
 	if (phdr->p_type == PT_TLS)
 	  {
 	    /* Remember the values we need.  */
@@ -80,7 +78,7 @@ __libc_setup_tls (size_t tcbsize, size_t tcbalign)
 	    /* We have to find the load address which is not easy.
 	       Look for the load segment with the lowest address.  */
 	    if (phdr->p_vaddr < loadaddr)
-	      loadaddr = phdr->p_type;
+	      loadaddr = phdr->p_vaddr;
 	  }
     }