about summary refs log tree commit diff
path: root/elf
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2007-05-19 07:08:23 +0000
committerUlrich Drepper <drepper@redhat.com>2007-05-19 07:08:23 +0000
commitdf94b6412e0628cd577da0ce5626358a3967ee44 (patch)
tree3b969d3e4175fe3a72f824c482d8c9f9a3b3bf3e /elf
parent2acd01acb10d0c0113f87bf7e787e0854498269d (diff)
downloadglibc-df94b6412e0628cd577da0ce5626358a3967ee44.tar.gz
glibc-df94b6412e0628cd577da0ce5626358a3967ee44.tar.xz
glibc-df94b6412e0628cd577da0ce5626358a3967ee44.zip
* elf/dl-close.c (_dl_close_worker): When removing object from
	global scope, wait for all lookups to finish afterwards.
	* elf/dl-open.c (add_to_global): When global scope array must
	grow, allocate a new one and free old array only after all
	lookups finish.
	* elf/dl-runtime.c (_dl_fixup): Protect using global scope.
	(_dl_lookup_symbol_x): Likewise.
	* elf/dl-support.c: Define _dl_wait_lookup_done.
	* sysdeps/generic/ldsodefs.h (struct rtld_global): Add
	_dl_wait_lookup_done.
Diffstat (limited to 'elf')
-rw-r--r--elf/dl-close.c4
-rw-r--r--elf/dl-open.c19
-rw-r--r--elf/dl-runtime.c32
-rw-r--r--elf/dl-support.c5
4 files changed, 49 insertions, 11 deletions
diff --git a/elf/dl-close.c b/elf/dl-close.c
index e0fe26ad02..8e5c9fc033 100644
--- a/elf/dl-close.c
+++ b/elf/dl-close.c
@@ -31,6 +31,7 @@
 #include <sys/types.h>
 #include <sys/mman.h>
 #include <sysdep-cancel.h>
+#include <tls.h>
 
 
 /* Type of the constructor functions.  */
@@ -487,6 +488,9 @@ _dl_close_worker (struct link_map *map)
 		ns_msl->r_list[cnt - 1] = ns_msl->r_list[cnt];
 
 	      --ns_msl->r_nlist;
+
+	      if (!RTLD_SINGLE_THREAD_P)
+		THREAD_GSCOPE_WAIT ();
 	    }
 
 	  /* Remove the object from the dtv slotinfo array if it uses TLS.  */
diff --git a/elf/dl-open.c b/elf/dl-open.c
index 583878781e..a043cf61b6 100644
--- a/elf/dl-open.c
+++ b/elf/dl-open.c
@@ -32,6 +32,7 @@
 #include <bp-sym.h>
 #include <caller.h>
 #include <sysdep-cancel.h>
+#include <tls.h>
 
 #include <dl-dst.h>
 
@@ -125,15 +126,25 @@ add_to_global (struct link_map *new)
     {
       /* We have to extend the existing array of link maps in the
 	 main map.  */
+      struct link_map **old_global
+	= GL(dl_ns)[new->l_ns]._ns_main_searchlist->r_list;
+      size_t new_nalloc = ((ns->_ns_global_scope_alloc + to_add) * 2);
+
       new_global = (struct link_map **)
-	realloc (ns->_ns_main_searchlist->r_list,
-		 ((ns->_ns_global_scope_alloc + to_add + 8)
-		  * sizeof (struct link_map *)));
+	malloc (new_nalloc * sizeof (struct link_map *));
       if (new_global == NULL)
 	goto nomem;
 
-      ns->_ns_global_scope_alloc += to_add + 8;
+      memcpy (new_global, old_global,
+	      ns->_ns_global_scope_alloc * sizeof (struct link_map *));
+
+      ns->_ns_global_scope_alloc = new_nalloc;
       ns->_ns_main_searchlist->r_list = new_global;
+
+      if (!RTLD_SINGLE_THREAD_P)
+	THREAD_GSCOPE_WAIT ();
+
+      free (old_global);
     }
 
   /* Now add the new entries.  */
diff --git a/elf/dl-runtime.c b/elf/dl-runtime.c
index 9ecf62b436..6add5e4fff 100644
--- a/elf/dl-runtime.c
+++ b/elf/dl-runtime.c
@@ -26,6 +26,8 @@
 #include <ldsodefs.h>
 #include <sysdep-cancel.h>
 #include "dynamic-link.h"
+#include <tls.h>
+
 
 #if (!defined ELF_MACHINE_NO_RELA && !defined ELF_MACHINE_PLT_REL) \
     || ELF_MACHINE_NO_REL
@@ -97,10 +99,15 @@ _dl_fixup (
 	 not necessary for objects which cannot be unloaded or when
 	 we are not using any threads (yet).  */
       int flags = DL_LOOKUP_ADD_DEPENDENCY;
-      if (l->l_type == lt_loaded && !RTLD_SINGLE_THREAD_P)
+      if (!RTLD_SINGLE_THREAD_P)
 	{
-	  __rtld_mrlock_lock (l->l_scope_lock);
-	  flags |= DL_LOOKUP_SCOPE_LOCK;
+	  THREAD_GSCOPE_SET_FLAG ();
+
+	  if (l->l_type == lt_loaded)
+	    {
+	      __rtld_mrlock_lock (l->l_scope_lock);
+	      flags |= DL_LOOKUP_SCOPE_LOCK;
+	    }
 	}
 
       result = _dl_lookup_symbol_x (strtab + sym->st_name, l, &sym, l->l_scope,
@@ -109,6 +116,10 @@ _dl_fixup (
       if ((flags & DL_LOOKUP_SCOPE_LOCK) != 0)
 	__rtld_mrlock_unlock (l->l_scope_lock);
 
+      /* We are done with the global scope.  */
+      if (!RTLD_SINGLE_THREAD_P)
+	THREAD_GSCOPE_RESET_FLAG ();
+
       /* Currently result contains the base load address (or link map)
 	 of the object that defines sym.  Now add in the symbol
 	 offset.  */
@@ -191,10 +202,15 @@ _dl_profile_fixup (
 	     not necessary for objects which cannot be unloaded or when
 	     we are not using any threads (yet).  */
 	  int flags = DL_LOOKUP_ADD_DEPENDENCY;
-	  if (l->l_type == lt_loaded && !RTLD_SINGLE_THREAD_P)
+	  if (!RTLD_SINGLE_THREAD_P)
 	    {
-	      __rtld_mrlock_lock (l->l_scope_lock);
-	      flags |= DL_LOOKUP_SCOPE_LOCK;
+	      THREAD_GSCOPE_SET_FLAG ();
+
+	      if (l->l_type == lt_loaded)
+		{
+		  __rtld_mrlock_lock (l->l_scope_lock);
+		  flags |= DL_LOOKUP_SCOPE_LOCK;
+		}
 	    }
 
 	  result = _dl_lookup_symbol_x (strtab + refsym->st_name, l,
@@ -204,6 +220,10 @@ _dl_profile_fixup (
 	  if ((flags & DL_LOOKUP_SCOPE_LOCK) != 0)
 	    __rtld_mrlock_unlock (l->l_scope_lock);
 
+	  /* We are done with the global scope.  */
+	  if (!RTLD_SINGLE_THREAD_P)
+	    THREAD_GSCOPE_RESET_FLAG ();
+
 	  /* Currently result contains the base load address (or link map)
 	     of the object that defines sym.  Now add in the symbol
 	     offset.  */
diff --git a/elf/dl-support.c b/elf/dl-support.c
index c7479dc639..cecb603ae6 100644
--- a/elf/dl-support.c
+++ b/elf/dl-support.c
@@ -1,5 +1,5 @@
 /* Support for dynamic linking code in static libc.
-   Copyright (C) 1996-2005, 2006 Free Software Foundation, Inc.
+   Copyright (C) 1996-2005, 2006, 2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -132,6 +132,9 @@ int (*_dl_make_stack_executable_hook) (void **) internal_function
   = _dl_make_stack_executable;
 
 
+/* Function in libpthread to wait for termination of lookups.  */
+void (*_dl_wait_lookup_done) (void);
+
 #ifdef NEED_DL_SYSINFO
 /* Needed for improved syscall handling on at least x86/Linux.  */
 uintptr_t _dl_sysinfo = DL_SYSINFO_DEFAULT;