about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog36
-rw-r--r--Makerules12
-rw-r--r--elf/dl-load.c2
-rw-r--r--elf/dl-minimal.c22
-rw-r--r--elf/rtld.c22
-rw-r--r--libio/oldiopopen.c6
-rw-r--r--sysdeps/generic/ldsodefs.h8
-rw-r--r--sysdeps/generic/libc-tls.c10
8 files changed, 83 insertions, 35 deletions
diff --git a/ChangeLog b/ChangeLog
index 64272308d5..3bd844d17b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,39 @@
+2002-08-04  Roland McGrath  <roland@redhat.com>
+
+	* Makerules (cpp-srcs-left): When setting this to run
+	cppflags-iterator.mk, must append .c to $(tests) and $(xtests)
+	words.  Combine the two loops into one on the concatenated list,
+	including those as well as $(test-srcs).
+
+	* elf/dl-minimal.c (__libc_memalign): Guts of malloc moved here,
+	since we align here with optimally minimal waste anyway.
+	(malloc): Just call that.
+
+	* sysdeps/generic/libc-tls.c (__libc_setup_tls): Set l_tls_offset to
+	the right variable.
+
+	* elf/dl-load.c (_dl_map_object_from_fd): Use p_vaddr, not p_offset,
+	to compute memory location for l_tls_initimage.
+	* elf/rtld.c (_dl_start): Likewise.
+	* sysdeps/generic/libc-tls.c (__libc_setup_tls): Likewise.
+
+	* libio/oldiopopen.c: Move #include's before #if SHLIB_COMPAT,
+	because the .d file is generated in the non-shared case and
+	so fails to catch them otherwise.
+
+	* sysdeps/generic/dl-tls.c (_dl_allocate_tls_storage): New function,
+	split out of _dl_allocate_tls.
+	(_dl_allocate_tls_init): Likewise.
+	(_dl_allocate_tls): Call those.
+	* sysdeps/generic/ldsodefs.h: Declare them with attribute_hidden.
+	* elf/rtld.c (dl_main): Call them separately instead of calling
+	_dl_allocate_tls.  Delay _dl_allocate_tls_init until after relocation
+	is finished, so that the initializer data has been relocated before we
+	copy it into the main thread's TLS block.
+
+	* sysdeps/generic/dl-tls.c (_dl_allocate_tls): Fix off-by-one error in
+	loop conditions, prevented the last used module from being initialized.
+
 2002-08-04  Jakub Jelinek  <jakub@redhat.com>
 
 	* sysdeps/generic/glob.c (glob, globfree): Only use libc_hidden_def
diff --git a/Makerules b/Makerules
index 400d7d9ef5..6d05287b0d 100644
--- a/Makerules
+++ b/Makerules
@@ -1040,15 +1040,11 @@ check: tests
 .PHONY: xcheck
 xcheck: xtests
 
-ifneq (,$(tests))
-cpp-srcs-left = $(tests)
+all-tests = $(strip $(tests) $(xtests) $(test-srcs))
+ifneq (,$(all-tests))
+cpp-srcs-left = $(all-tests:=.c)
 lib := tests
-include $(patsubst %,$(..)cppflags-iterator.mk,$(tests))
-endif
-ifneq (,$(xtests))
-cpp-srcs-left = $(xtests)
-lib := tests
-include $(patsubst %,$(..)cppflags-iterator.mk,$(xtests))
+include $(patsubst %,$(..)cppflags-iterator.mk,$(all-tests))
 endif
 
 .PHONY: TAGS
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 2955bc5173..aabbf21128 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -949,7 +949,7 @@ _dl_map_object_from_fd (const char *name, int fd, struct filebuf *fbp,
 	      l->l_tls_initimage_size = ph->p_filesz;
 	      /* Since we don't know the load address yet only store the
 		 offset.  We will adjust it later.  */
-	      l->l_tls_initimage = (void *) ph->p_offset;
+	      l->l_tls_initimage = (void *) ph->p_vaddr;
 
 	      /* Assign the next available module ID.  */
 	      l->l_tls_modid = _dl_next_tls_modid ();
diff --git a/elf/dl-minimal.c b/elf/dl-minimal.c
index 2e45fc0a65..893a3b1f2e 100644
--- a/elf/dl-minimal.c
+++ b/elf/dl-minimal.c
@@ -46,8 +46,9 @@ extern unsigned long int weak_function strtoul (const char *nptr,
 						char **endptr, int base);
 
 
+/* Allocate an aligned memory block.  */
 void * weak_function
-malloc (size_t n)
+__libc_memalign (size_t align, size_t n)
 {
 #ifdef MAP_ANON
 #define	_dl_zerofd (-1)
@@ -70,8 +71,8 @@ malloc (size_t n)
     }
 
   /* Make sure the allocation pointer is ideally aligned.  */
-  alloc_ptr = (void *) 0 + (((alloc_ptr - (void *) 0) + sizeof (double) - 1)
-			    & ~(sizeof (double) - 1));
+  alloc_ptr = (void *) 0 + (((alloc_ptr - (void *) 0) + align - 1)
+			    & ~(align - 1));
 
   if (alloc_ptr + n >= alloc_end)
     {
@@ -91,6 +92,12 @@ malloc (size_t n)
   return alloc_last_block;
 }
 
+void * weak_function
+malloc (size_t n)
+{
+  return __libc_memalign (sizeof (double), n);
+}
+
 /* We use this function occasionally since the real implementation may
    be optimized when it can assume the memory it returns already is
    set to NUL.  */
@@ -124,15 +131,6 @@ realloc (void *ptr, size_t n)
   assert (new == ptr);
   return new;
 }
-
-/* Return alligned memory block.  */
-void * weak_function
-__libc_memalign (size_t align, size_t n)
-{
-  void *newp = malloc (n + align - 1);
-
-  return (void *) roundup ((uintptr_t) newp, align);
-}
 
 /* Avoid signal frobnication in setjmp/longjmp.  Keeps things smaller.  */
 
diff --git a/elf/rtld.c b/elf/rtld.c
index 82fe809f70..1472c18235 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -191,7 +191,7 @@ _dl_start (void *arg)
 	assert (bootstrap_map.l_tls_blocksize != 0);
 	bootstrap_map.l_tls_initimage_size = phdr[cnt].p_filesz;
 	bootstrap_map.l_tls_initimage = (void *) (bootstrap_map.l_addr
-						  + phdr[cnt].p_offset);
+						  + phdr[cnt].p_vaddr);
 
 	/* We can now allocate the initial TLS block.  This can happen
 	   on the stack.  We'll get the final memory later when we
@@ -1087,13 +1087,10 @@ of this helper program; chances are you did not intend to run this program.\n\
 	 for the thread descriptor.  The memory for the TLS block will
 	 never be freed.  It should be allocated accordingly.  The dtv
 	 array can be changed if dynamic loading requires it.  */
-      tcbp = INTUSE(_dl_allocate_tls) ();
+      tcbp = _dl_allocate_tls_storage ();
       if (tcbp == NULL)
 	_dl_fatal_printf ("\
 cannot allocate TLS data structures for initial thread");
-
-      /* And finally install it for the main thread.  */
-      TLS_INIT_TP (tcbp);
     }
 #endif
 
@@ -1445,6 +1442,21 @@ cannot allocate TLS data structures for initial thread");
      we need it in the memory handling later.  */
   GL(dl_initial_searchlist) = *GL(dl_main_searchlist);
 
+#ifdef USE_TLS
+# ifndef SHARED
+  if (GL(dl_tls_max_dtv_idx) > 0)
+# endif
+    {
+      /* Now that we have completed relocation, the initializer data
+	 for the TLS blocks has its final values and we can copy them
+	 into the main thread's TLS area, which we allocated above.  */
+      _dl_allocate_tls_init (tcbp);
+
+      /* And finally install it for the main thread.  */
+      TLS_INIT_TP (tcbp);
+    }
+#endif
+
   {
     /* Initialize _r_debug.  */
     struct r_debug *r = _dl_debug_initialize (GL(dl_rtld_map).l_addr);
diff --git a/libio/oldiopopen.c b/libio/oldiopopen.c
index 878fdc0fcb..d57ec02e2c 100644
--- a/libio/oldiopopen.c
+++ b/libio/oldiopopen.c
@@ -26,9 +26,6 @@
    This exception applies to code released by its copyright holders
    in files containing the exception.  */
 
-#include <shlib-compat.h>
-#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
-
 #define _IO_USE_OLD_IO_FILE
 #ifndef _POSIX_SOURCE
 # define _POSIX_SOURCE
@@ -46,6 +43,9 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
+#include <shlib-compat.h>
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
+
 #ifndef _IO_fork
 #ifdef _LIBC
 #define _IO_fork __vfork
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 5f586f2e3c..2269950045 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -726,7 +726,13 @@ extern void _dl_determine_tlsoffset (void) internal_function;
 
 /* Allocate memory for static TLS block and dtv.  */
 extern void *_dl_allocate_tls (void) internal_function;
-extern void *_dl_allocate_tls_internal (void) internal_function;
+
+/* These are internal entry points to the two halves of _dl_allocate_tls,
+   only used within rtld.c itself at startup time.  */
+extern void *_dl_allocate_tls_storage (void)
+  internal_function attribute_hidden;
+extern void *_dl_allocate_tls_init (void *)
+  internal_function attribute_hidden;
 
 /* Deallocate memory allocated with _dl_allocate_tls.  */
 extern void _dl_deallocate_tls (void *tcb) internal_function;
diff --git a/sysdeps/generic/libc-tls.c b/sysdeps/generic/libc-tls.c
index 8c82040b19..6b9a746dd8 100644
--- a/sysdeps/generic/libc-tls.c
+++ b/sysdeps/generic/libc-tls.c
@@ -52,7 +52,7 @@ __libc_setup_tls (size_t tcbsize, size_t tcbalign)
   void *tlsblock;
   size_t memsz = 0;
   size_t filesz = 0;
-  off_t offset = 0;
+  size_t initimage = 0;
   size_t align = 0;
   size_t max_align = tcbalign;
   size_t loadaddr = ~0ul;
@@ -70,7 +70,7 @@ __libc_setup_tls (size_t tcbsize, size_t tcbalign)
 	    /* Remember the values we need.  */
 	    memsz = phdr->p_memsz;
 	    filesz = phdr->p_filesz;
-	    offset = phdr->p_offset;
+	    initimage = phdr->p_vaddr;
 	    align = phdr->p_align;
 	    if (phdr->p_align > max_align)
 	      max_align = phdr->p_align;
@@ -120,7 +120,7 @@ __libc_setup_tls (size_t tcbsize, size_t tcbalign)
 # else
 #  error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
 # endif
-  memset (__mempcpy (static_dtv[2].pointer, (char *) loadaddr + offset,
+  memset (__mempcpy (static_dtv[2].pointer, (char *) loadaddr + initimage,
 		     filesz),
 	  '\0', memsz - filesz);
 
@@ -141,12 +141,12 @@ __libc_setup_tls (size_t tcbsize, size_t tcbalign)
 # endif
 
   /* We have to create a fake link map which normally would be created
-     by the dynamic linker.  It just has to have enough informatino to
+     by the dynamic linker.  It just has to have enough information to
      make the TLS routines happy.  */
   static_map.l_tls_align = align;
   static_map.l_tls_blocksize = memsz;
   static_map.l_tls_initimage_size = filesz;
-  static_map.l_tls_offset = offset;
+  static_map.l_tls_offset = tcb_offset;
   static_map.l_type = lt_executable;
   static_map.l_tls_modid = 1;