about summary refs log tree commit diff
path: root/elf/rtld.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2002-10-11 10:52:20 +0000
committerRoland McGrath <roland@gnu.org>2002-10-11 10:52:20 +0000
commitce460d04a5bd10d7353ca37dfa9d34275449fb3b (patch)
treee203d270a348ce6c5d0f4dbc54a430fbd106fd93 /elf/rtld.c
parent28654d2a063d22fda1fd748f392876ed61c36fa0 (diff)
downloadglibc-ce460d04a5bd10d7353ca37dfa9d34275449fb3b.tar.gz
glibc-ce460d04a5bd10d7353ca37dfa9d34275449fb3b.tar.xz
glibc-ce460d04a5bd10d7353ca37dfa9d34275449fb3b.zip
* sysdeps/generic/bits/libc-tsd.h [USE___THREAD]: Conditional
	changed from [USE_TLS && HAVE___THREAD].

	* sysdeps/i386/dl-machine.h (elf_machine_type_class, elf_machine_rel):
	Disable TLS relocs if [RTLD_BOOTSTRAP && !USE___THREAD].
	* sysdeps/x86_64/dl-machine.h
	(elf_machine_type_class, elf_machine_rela): Likewise.
	* sysdeps/sh/dl-machine.h (elf_machine_type_class, elf_machine_rela):
	Likewise.

	* include/link.h (struct link_map): Remove member l_tls_tp_initialized.
	* elf/rtld.c (_dl_start_final, dl_main): Don't use it.
	(_dl_start): Conditionalize PT_TLS check on [USE___THREAD].

	* sysdeps/i386/dl-tls.h (__TLS_GET_ADDR): Use ___tls_get_addr_internal
	instead of ___tls_get_addr.
	(___tls_get_addr_internal): Add attribute_hidden to decl.

	* sysdeps/generic/ldsodefs.h (struct rtld_global): New variable
	_dl_error_catch_tsd.
	* elf/rtld.c (startup_error_tsd): New function.
	(dl_main): Point _dl_error_catch_tsd at that.
	* elf/dl-error.c: Don't use libc-tsd.h for DL_ERROR,
	use new function pointer instead.
	* elf/dl-tsd.c: New file.
	* elf/Makefile (routines): Add it.

2002-10-07  Roland McGrath  <roland@redhat.com>

	* elf/dl-misc.c (_dl_debug_vdprintf): Use INTERNAL_SYSCALL macro for
	writev if it's available.  Otherwise if [RTLD_PRIVATE_ERRNO] then
	take _dl_load_lock around calling __writev.

	* sysdeps/unix/sysv/linux/i386/sysdep.h (INTERNAL_SYSCALL): New macro.
	(INLINE_SYSCALL): Use that.

	* sysdeps/generic/dl-sysdep.h: New file.
	* sysdeps/mach/hurd/dl-sysdep.h: New file.
	* sysdeps/generic/ldsodefs.h: Include <dl-sysdep.h>.
	* include/errno.h [IS_IN_rtld]: Include <dl-sysdep.h> to define ...
	[RTLD_PRIVATE_ERRNO]: Use a hidden global variable for errno and
	access it directly.
	* elf/dl-minimal.c (__errno_location): Removed.
	* sysdeps/unix/i386/sysdep.S (__syscall_errno) [RTLD_PRIVATE_ERRNO]:
	Use GOTOFF access for errno.
	* sysdeps/unix/sysv/linux/i386/sysdep.h
	[RTLD_PRIVATE_ERRNO] (SYSCALL_ERROR_HANDLER): Likewise.

	* sysdeps/unix/x86_64/sysdep.S (__syscall_errno) [RTLD_PRIVATE_ERRNO]:
	Use PC-relative access for errno.
	* sysdeps/unix/sysv/linux/x86_64/sysdep.h
	[RTLD_PRIVATE_ERRNO] (SYSCALL_ERROR_HANDLER): Likewise.

	* include/tls.h: New file.
	(USE___THREAD): New macro.
	Define to 1 under [USE_TLS && HAVE___THREAD] and only when compiling
	libc or libpthread.
	* sysdeps/unix/sysv/linux/i386/sysdep.h [USE___THREAD]: Conditional
	changed from [USE_TLS && HAVE___THREAD].
	* sysdeps/unix/sysv/linux/x86_64/sysdep.h: Likewise.
	* sysdeps/unix/i386/sysdep.S: Likewise.
	* sysdeps/unix/x86_64/sysdep.S: Likewise.
	* include/errno.h: Likewise.
	* include/netdb.h: Likewise.
	* include/resolv.h: Likewise.

	* sysdeps/generic/errno.c: New file.
	* csu/Makefile (aux): New variable, list errno.
	* sysdeps/unix/sysv/linux/i386/sysdep.S (errno, _errno): Remove defns.
	* sysdeps/unix/sysv/linux/m68k/sysdep.S: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/sysdep.S: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/sysdep.S: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/sysdep.S: Likewise.
	* sysdeps/unix/sysv/linux/arm/sysdep.S: Likewise.
	* sysdeps/unix/sysv/linux/cris/sysdep.S: Likewise.
	* sysdeps/unix/sysv/linux/hppa/sysdep.c: Likewise.
	* sysdeps/unix/sysv/linux/ia64/sysdep.S: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/sysdep.c: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sysdep.S: Likewise.
	* sysdeps/unix/sysv/linux/sh/sysdep.S: Likewise.
	* sysdeps/unix/alpha/sysdep.S: Likewise.
	* sysdeps/generic/start.c: Likewise.
	* sysdeps/unix/start.c: Likewise.
	* sysdeps/unix/arm/start.c: Likewise.
	* sysdeps/unix/bsd/ultrix4/mips/start.S: Likewise.
	* sysdeps/unix/sparc/start.c: Likewise.
	* sysdeps/unix/sysv/irix4/start.c: Likewise.
	* sysdeps/unix/sysv/linux/mips/sysdep.S: File removed.

	* manual/search.texi (Tree Search Function, Hash Search Function):
	Mention search.h clearly.

2002-10-05  Roland McGrath  <roland@redhat.com>

	* elf/dl-fxstat64.c: File removed.
	* elf/dl-xstat64.c: File removed.
	* elf/Makefile (rtld-routines): Remove them.
	* sysdeps/unix/sysv/linux/xstat64.c: Remove RTLD_STAT64 conditionals.
	Instead, use strong_alias instead of versioned_symbol in the
	!SHLIB_COMPAT case.
	* sysdeps/unix/sysv/linux/fxstat64.c: Likewise.
	* sysdeps/unix/sysv/linux/lxstat64.c: Likewise.

	* include/shlib-compat.h
	(SHLIB_COMPAT): Require that IS_IN_##lib be defined nonzero.
	[! NOT_IN_libc] (IS_IN_libc): Define it.
	* cppflags-iterator.mk (CPPFLAGS-$(cpp-src)): Use -Dx=1 not just -Dx.
	* elf/Makefile (CPPFLAGS-.os): Likewise.

	* sunrpc/rpc_main.c (main): Don't declare with noreturn attribute.
	Return the status instead of calling exit.

	* Makeconfig (CFLAGS): Prepend -std=gnu99.
	* Makerules (+make-deps): Use $(CFLAGS) only for .c sources.
	Remove superfluous rm command, whose @ plus make bugs hid
	all these commands from the make output.

	* include/stubs-prologue.h: New file.  Give #error under #ifdef _LIBC.
	* Makefile ($(inst_includedir)/gnu/stubs.h): Depend on it.
	Use that file's contents instead of literal echo's for the prologue.
	* include/features.h: Include <gnu/stubs.h> unconditionally.
	* include/gnu/stubs.h: New file.

2002-09-30  Roland McGrath  <roland@redhat.com>

	* elf/rtld-Rules: New file.
	* elf/Makefile ($(objpfx)librtld.map, $(objpfx)librtld.mk,
	$(objpfx)rtld-libc.a): New targets.
	(generated): Add them.
	(reloc-link): Remove -o $@ from the variable.
	($(objpfx)dl-allobjs.os): Add -o $@ after $(reloc-link).
	(distribute): Add rtld-Rules.
	(CPPFLAGS-.os): Define this instead of CFLAGS-.os.
	* Makerules ($(+sysdir_pfx)sysd-rules): Emit rules for rtld-% targets.
	(common-mostlyclean, common-clean): Clean up rtld-* files.
	* sysdeps/unix/make-syscalls.sh: Add rtld-*.os target name to rules.
Diffstat (limited to 'elf/rtld.c')
-rw-r--r--elf/rtld.c83
1 files changed, 36 insertions, 47 deletions
diff --git a/elf/rtld.c b/elf/rtld.c
index 19600644fb..3a64ca74f7 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -221,21 +221,18 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
   GL(dl_rtld_map).l_map_end = (ElfW(Addr)) _end;
   /* Copy the TLS related data if necessary.  */
 #if USE_TLS && !defined DONT_USE_BOOTSTRAP_MAP
-# ifdef HAVE___THREAD
+# if USE___THREAD
   assert (info->l.l_tls_modid != 0);
+  GL(dl_rtld_map).l_tls_blocksize = info->l.l_tls_blocksize;
+  GL(dl_rtld_map).l_tls_align = info->l.l_tls_align;
+  GL(dl_rtld_map).l_tls_initimage_size = info->l.l_tls_initimage_size;
+  GL(dl_rtld_map).l_tls_initimage = info->l.l_tls_initimage;
+  GL(dl_rtld_map).l_tls_offset = info->l.l_tls_offset;
+  GL(dl_rtld_map).l_tls_modid = 1;
 # else
-  if (info->l.l_tls_modid != 0)
+  assert (info->l.l_tls_modid == 0);
 # endif
-    {
-      GL(dl_rtld_map).l_tls_blocksize = info->l.l_tls_blocksize;
-      GL(dl_rtld_map).l_tls_align = info->l.l_tls_align;
-      GL(dl_rtld_map).l_tls_initimage_size = info->l.l_tls_initimage_size;
-      GL(dl_rtld_map).l_tls_initimage = info->l.l_tls_initimage;
-      GL(dl_rtld_map).l_tls_offset = info->l.l_tls_offset;
-      GL(dl_rtld_map).l_tls_modid = 1;
-      GL(dl_rtld_map).l_tls_tp_initialized
-	= info->l.l_tls_tp_initialized;
-    }
+
 #endif
 
 #if HP_TIMING_AVAIL
@@ -276,14 +273,6 @@ _dl_start (void *arg)
   struct dl_start_final_info info;
 # define bootstrap_map info.l
 #endif
-#if USE_TLS || (!DONT_USE_BOOTSTRAP_MAP && !HAVE_BUILTIN_MEMSET)
-  size_t cnt;
-#endif
-#ifdef USE_TLS
-  ElfW(Ehdr) *ehdr;
-  ElfW(Phdr) *phdr;
-  dtv_t initdtv[3];
-#endif
 
   /* This #define produces dynamic linking inline functions for
      bootstrap relocation instead of general-purpose relocation.  */
@@ -311,7 +300,7 @@ _dl_start (void *arg)
 # ifdef HAVE_BUILTIN_MEMSET
   __builtin_memset (bootstrap_map.l_info, '\0', sizeof (bootstrap_map.l_info));
 # else
-  for (cnt = 0;
+  for (size_t cnt = 0;
        cnt < sizeof (bootstrap_map.l_info) / sizeof (bootstrap_map.l_info[0]);
        ++cnt)
     bootstrap_map.l_info[cnt] = 0;
@@ -325,24 +314,21 @@ _dl_start (void *arg)
   bootstrap_map.l_ld = (void *) bootstrap_map.l_addr + elf_machine_dynamic ();
   elf_get_dynamic_info (&bootstrap_map);
 
-#if USE_TLS
-# if !defined HAVE___THREAD && !defined DONT_USE_BOOTSTRAP_MAP
-  /* Signal that we have not found TLS data so far.  */
-  bootstrap_map.l_tls_modid = 0;
-# endif
-
+#if USE___THREAD
   /* Get the dynamic linker's own program header.  First we need the ELF
      file header.  The `_begin' symbol created by the linker script points
      to it.  When we have something like GOTOFF relocs, we can use a plain
      reference to find the runtime address.  Without that, we have to rely
      on the `l_addr' value, which is not the value we want when prelinked.  */
-#ifdef DONT_USE_BOOTSTRAP_MAP
-  ehdr = (ElfW(Ehdr) *) &_begin;
-#else
-  ehdr = (ElfW(Ehdr) *) bootstrap_map.l_addr;
-#endif
-  phdr = (ElfW(Phdr) *) ((ElfW(Addr)) ehdr + ehdr->e_phoff);
-  for (cnt = 0; cnt < ehdr->e_phnum; ++cnt)
+  ElfW(Ehdr) *ehdr
+# ifdef DONT_USE_BOOTSTRAP_MAP
+    = (ElfW(Ehdr) *) &_begin;
+# else
+    = (ElfW(Ehdr) *) bootstrap_map.l_addr;
+# endif
+  ElfW(Phdr) *phdr = (ElfW(Phdr) *) ((void *) ehdr + ehdr->e_phoff);
+  size_t cnt = ehdr->e_phnum;	/* PT_TLS is usually the last phdr.  */
+  while (cnt-- > 0)
     if (phdr[cnt].p_type == PT_TLS)
       {
 	void *tlsblock;
@@ -431,13 +417,11 @@ _dl_start (void *arg)
 
 	/* So far this is module number one.  */
 	bootstrap_map.l_tls_modid = 1;
-	/* The TP got initialized.  */
-	bootstrap_map.l_tls_tp_initialized = 1;
 
 	/* There can only be one PT_TLS entry.  */
 	break;
       }
-#endif	/* use TLS */
+#endif	/* USE___THREAD */
 
 #ifdef ELF_MACHINE_BEFORE_RTLD_RELOC
   ELF_MACHINE_BEFORE_RTLD_RELOC (bootstrap_map.l_info);
@@ -576,6 +560,15 @@ match_version (const char *string, struct link_map *map)
   return 0;
 }
 
+/* _dl_error_catch_tsd points to this for the single-threaded case.
+   It's reset by the thread library for multithreaded programs.  */
+static void ** __attribute__ ((const))
+startup_error_tsd (void)
+{
+  static void *data;
+  return &data;
+}
+
 static const char *library_path;	/* The library search path.  */
 static const char *preloadlist;		/* The list preloaded objects.  */
 static int version_info;		/* Nonzero if information about
@@ -605,6 +598,9 @@ dl_main (const ElfW(Phdr) *phdr,
   void *tcbp;
 #endif
 
+  /* Explicit initialization since the reloc would just be more work.  */
+  GL(dl_error_catch_tsd) = &startup_error_tsd;
+
   /* Process the environment variable which control the behaviour.  */
   process_envvars (&mode);
 
@@ -1564,16 +1560,9 @@ cannot allocate TLS data structures for initial thread");
 	 into the main thread's TLS area, which we allocated above.  */
       _dl_allocate_tls_init (tcbp);
 
-      /* And finally install it for the main thread.  */
-# ifndef HAVE___THREAD
-      TLS_INIT_TP (tcbp, GL(dl_rtld_map).l_tls_tp_initialized);
-# else
-      /* If the compiler supports the __thread keyword we know that
-	 at least ld.so itself uses TLS and therefore the thread
-	 pointer was initialized earlier.  */
-      assert (GL(dl_rtld_map).l_tls_tp_initialized != 0);
-      TLS_INIT_TP (tcbp, 1);
-# endif
+      /* And finally install it for the main thread.  If ld.so itself uses
+	 TLS we know the thread pointer was initialized earlier.  */
+      TLS_INIT_TP (tcbp, USE___THREAD);
     }
 #endif