[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[commits] r2569 - in /fsf/trunk/libc: ./ dlfcn/ elf/ include/ nptl/ nptl/sysdeps/unix/sysv/linux/ sysdeps/generic/



Author: eglibc
Date: Wed Jun 20 00:03:11 2007
New Revision: 2569

Log:
Import glibc-mainline for 2007-06-20

Modified:
    fsf/trunk/libc/ChangeLog
    fsf/trunk/libc/dlfcn/dlinfo.c
    fsf/trunk/libc/elf/dl-addr.c
    fsf/trunk/libc/elf/dl-close.c
    fsf/trunk/libc/elf/dl-iteratephdr.c
    fsf/trunk/libc/elf/dl-load.c
    fsf/trunk/libc/elf/dl-lookup.c
    fsf/trunk/libc/elf/dl-object.c
    fsf/trunk/libc/elf/dl-open.c
    fsf/trunk/libc/elf/dl-runtime.c
    fsf/trunk/libc/elf/dl-support.c
    fsf/trunk/libc/elf/dl-sym.c
    fsf/trunk/libc/include/link.h
    fsf/trunk/libc/nptl/ChangeLog
    fsf/trunk/libc/nptl/sysdeps/unix/sysv/linux/rtld-lowlevel.h
    fsf/trunk/libc/sysdeps/generic/ldsodefs.h

Modified: fsf/trunk/libc/ChangeLog
==============================================================================
--- fsf/trunk/libc/ChangeLog (original)
+++ fsf/trunk/libc/ChangeLog Wed Jun 20 00:03:11 2007
@@ -1,3 +1,57 @@
+2007-06-19  Ulrich Drepper  <drepper@xxxxxxxxxx>
+
+	* elf/dl-close.c (free_mem): Free _dl_scope_free_list.
+
+2007-06-13  Jakub Jelinek  <jakub@xxxxxxxxxx>
+
+	* include/link.h: Don't include rtld-lowlevel.h.
+	(struct link_map): Remove l_scope_lock.
+	* sysdeps/generic/ldsodefs.h: Don't include rtld-lowlevel.h.
+	(_dl_scope_free_list): New field (variable) in _rtld_global.
+	(DL_LOOKUP_SCOPE_LOCK): Remove.
+	(_dl_scope_free): New prototype.
+	* elf/dl-runtime.c (_dl_fixup): Don't use __rtld_mrlock_*lock.
+	Don't pass DL_LOOKUP_SCOPE_LOCK to _dl_lookup_symbol_x.
+	(_dl_profile_fixup): Likewise.
+	* elf/dl-sym.c (do_sym): Likewise.  Use wrapped _dl_lookup_symbol_x
+	whenever !RTLD_SINGLE_THREAD_P, use THREAD_GSCOPE_SET_FLAG and
+	THREAD_GSCOPE_RESET_FLAG around it.
+	* elf/dl-close.c (_dl_close_worker): Don't use
+	__rtld_mrlock_{change,done}.  Call _dl_scope_free on the old
+	scope.  Make sure THREAD_GSCOPE_WAIT () happens if any old
+	scopes were queued or if l_scope_mem has been abandoned.
+	* elf/dl-open.c (_dl_scope_free): New function.
+	(dl_open_worker): Use it.  Don't use __rtld_mrlock_{change,done}.
+	* elf/dl-support.c (_dl_scope_free_list): New variable.
+	* elf/dl-lookup.c (add_dependency): Remove flags argument.
+	Remove DL_LOOKUP_SCOPE_LOCK handling.
+	(_dl_lookup_symbol_x): Adjust caller.  Remove DL_LOOKUP_SCOPE_LOCK
+	handling.
+	* elf/dl-object.c (_dl_new_object): Don't use
+	__rtld_mrlock_initialize.
+
+2007-06-19  Ulrich Drepper  <drepper@xxxxxxxxxx>
+
+	* sysdeps/generic/ldsodefs.h (rtld_global): Reorder some elements
+	to fill in holes
+	(rtld_global_ro): Likewise.
+
+2007-06-18  Jakub Jelinek  <jakub@xxxxxxxxxx>
+
+	* elf/dl-addr.c (_dl_addr): Skip PT_LOAD checking if l_contiguous.
+	Move PT_LOAD checking to...
+	(_dl_addr_inside_object): ... here, new function.
+	* elf/dl-sym.c (do_sym): If not l_contiguous,
+	call _dl_addr_inside_object.
+	* elf/dl-iteratephdr.c (__dl_iterate_phdr): Likewise.
+	* dlfcn/dlinfo.c (dlinfo_doit): Likewise.
+	* elf/dl-open.c (dl_open_worker): Likewise.
+	(_dl_addr_inside_object): New function if IS_IN_rtld.
+	* elf/dl-load.c (_dl_map_object_from_fd): Set l_contiguous if no
+	holes are present or are PROT_NONE protected.
+	* include/link.h (struct link_map): Add l_contiguous field.
+	* sysdeps/generic/ldsodefs.h (_dl_addr_inside_object): New prototype.
+
 2007-06-18  Jakub Jelinek  <jakub@xxxxxxxxxx>
             Tomas Janousek  <tjanouse@xxxxxxxxxx>
             Ulrich Drepper  <drepper@xxxxxxxxxx>

Modified: fsf/trunk/libc/dlfcn/dlinfo.c
==============================================================================
--- fsf/trunk/libc/dlfcn/dlinfo.c (original)
+++ fsf/trunk/libc/dlfcn/dlinfo.c Wed Jun 20 00:03:11 2007
@@ -1,5 +1,5 @@
 /* dlinfo -- Get information from the dynamic linker.
-   Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2004, 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
@@ -56,9 +56,8 @@
       /* Find the highest-addressed object that CALLER is not below.  */
       for (nsid = 0; nsid < DL_NNS; ++nsid)
 	for (l = GL(dl_ns)[nsid]._ns_loaded; l != NULL; l = l->l_next)
-	  if (caller >= l->l_map_start && caller < l->l_map_end)
-	    /* There must be exactly one DSO for the range of the virtual
-	       memory.  Otherwise something is really broken.  */
+	  if (caller >= l->l_map_start && caller < l->l_map_end
+	      && (l->l_contiguous || _dl_addr_inside_object (l, caller)))
 	    break;
 
       if (l == NULL)

Modified: fsf/trunk/libc/elf/dl-addr.c
==============================================================================
--- fsf/trunk/libc/elf/dl-addr.c (original)
+++ fsf/trunk/libc/elf/dl-addr.c Wed Jun 20 00:03:11 2007
@@ -134,22 +134,12 @@
   /* Find the highest-addressed object that ADDRESS is not below.  */
   for (Lmid_t ns = 0; ns < DL_NNS; ++ns)
     for (struct link_map *l = GL(dl_ns)[ns]._ns_loaded; l; l = l->l_next)
-      if (addr >= l->l_map_start && addr < l->l_map_end)
+      if (addr >= l->l_map_start && addr < l->l_map_end
+	  && (l->l_contiguous || _dl_addr_inside_object (l, addr)))
 	{
-	  /* Make sure it lies within one of L's segments.  */
-	  int n = l->l_phnum;
-	  const ElfW(Addr) reladdr = addr - l->l_addr;
-	  while (--n >= 0)
-	    if (l->l_phdr[n].p_type == PT_LOAD)
-	      {
-		if (reladdr - l->l_phdr[n].p_vaddr >= 0
-		    && reladdr - l->l_phdr[n].p_vaddr < l->l_phdr[n].p_memsz)
-		  {
-		    determine_info (addr, l, info, mapp, symbolp);
-		    result = 1;
-		    goto out;
-		  }
-	      }
+	  determine_info (addr, l, info, mapp, symbolp);
+	  result = 1;
+	  goto out;
 	}
 
  out:
@@ -158,3 +148,19 @@
   return result;
 }
 libc_hidden_def (_dl_addr)
+
+/* Return non-zero if ADDR lies within one of L's segments.  */
+int
+internal_function
+_dl_addr_inside_object (struct link_map *l, const ElfW(Addr) addr)
+{
+  int n = l->l_phnum;
+  const ElfW(Addr) reladdr = addr - l->l_addr;
+
+  while (--n >= 0)
+    if (l->l_phdr[n].p_type == PT_LOAD
+	&& reladdr - l->l_phdr[n].p_vaddr >= 0
+	&& reladdr - l->l_phdr[n].p_vaddr < l->l_phdr[n].p_memsz)
+      return 1;
+  return 0;
+}

Modified: fsf/trunk/libc/elf/dl-close.c
==============================================================================
--- fsf/trunk/libc/elf/dl-close.c (original)
+++ fsf/trunk/libc/elf/dl-close.c Wed Jun 20 00:03:11 2007
@@ -229,6 +229,7 @@
   bool do_audit = GLRO(dl_naudit) > 0 && !ns->_ns_loaded->l_auditing;
 #endif
   bool unload_any = false;
+  bool scope_mem_left = false;
   unsigned int unload_global = 0;
   unsigned int first_loaded = ~0;
   for (unsigned int i = 0; i < nloaded; ++i)
@@ -405,18 +406,18 @@
 
 	      struct r_scope_elem **old = imap->l_scope;
 
-	      if (RTLD_SINGLE_THREAD_P)
-		imap->l_scope = newp;
-	      else
-		{
-		  __rtld_mrlock_change (imap->l_scope_lock);
-		  imap->l_scope = newp;
-		  __rtld_mrlock_done (imap->l_scope_lock);
-		}
+	      imap->l_scope = newp;
 
 	      /* No user anymore, we can free it now.  */
 	      if (old != imap->l_scope_mem)
-		free (old);
+		{
+		  if (_dl_scope_free (old))
+		    /* If _dl_scope_free used THREAD_GSCOPE_WAIT (),
+		       no need to repeat it.  */
+		    scope_mem_left = false;
+		}
+	      else
+		scope_mem_left = true;
 
 	      imap->l_scope_max = new_size;
 	    }
@@ -485,9 +486,21 @@
 	      j++;
 	    }
       ns_msl->r_nlist = j;
-
-      if (!RTLD_SINGLE_THREAD_P)
-	THREAD_GSCOPE_WAIT ();
+    }
+
+  if (!RTLD_SINGLE_THREAD_P
+      && (unload_global
+	  || scope_mem_left
+	  || (GL(dl_scope_free_list) != NULL
+	      && GL(dl_scope_free_list)->count)))
+    {
+      THREAD_GSCOPE_WAIT ();
+
+      /* Now we can free any queued old scopes.  */
+      struct dl_scope_free_list *fsl  = GL(dl_scope_free_list);
+      if (fsl != NULL)
+	while (fsl->count > 0)
+	  free (fsl->list[--fsl->count]);
     }
 
   size_t tls_free_start;
@@ -786,4 +799,8 @@
 	   malloc), and in the static library it's in .bss space.  */
 	free_slotinfo (&GL(dl_tls_dtv_slotinfo_list)->next);
     }
+
+  void *scope_free_list = GL(dl_scope_free_list);
+  GL(dl_scope_free_list) = NULL;
+  free (scope_free_list);
 }

Modified: fsf/trunk/libc/elf/dl-iteratephdr.c
==============================================================================
--- fsf/trunk/libc/elf/dl-iteratephdr.c (original)
+++ fsf/trunk/libc/elf/dl-iteratephdr.c Wed Jun 20 00:03:11 2007
@@ -1,5 +1,5 @@
 /* Get loaded objects program headers.
-   Copyright (C) 2001,2002,2003,2004,2006 Free Software Foundation, Inc.
+   Copyright (C) 2001,2002,2003,2004,2006,2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Jakub Jelinek <jakub@xxxxxxxxxx>, 2001.
 
@@ -54,9 +54,9 @@
 	nloaded += GL(dl_ns)[cnt]._ns_nloaded;
 
 	if (caller >= (const void *) l->l_map_start
-	    && caller < (const void *) l->l_map_end)
-	  /* There must be exactly one DSO for the range of the virtual
-	     memory.  Otherwise something is really broken.  */
+	    && caller < (const void *) l->l_map_end
+	    && (l->l_contiguous
+		|| _dl_addr_inside_object (l, (ElfW(Addr)) caller)))
 	  ns = cnt;
       }
 

Modified: fsf/trunk/libc/elf/dl-load.c
==============================================================================
--- fsf/trunk/libc/elf/dl-load.c (original)
+++ fsf/trunk/libc/elf/dl-load.c Wed Jun 20 00:03:11 2007
@@ -1,5 +1,5 @@
 /* Map in a shared object's segments from the file.
-   Copyright (C) 1995-2005, 2006  Free Software Foundation, Inc.
+   Copyright (C) 1995-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
@@ -1223,6 +1223,8 @@
 		      loadcmds[nloadcmds - 1].mapstart - c->mapend,
 		      PROT_NONE);
 
+	l->l_contiguous = 1;
+
 	goto postmap;
       }
 
@@ -1242,6 +1244,7 @@
     /* Remember which part of the address space this object uses.  */
     l->l_map_start = c->mapstart + l->l_addr;
     l->l_map_end = l->l_map_start + maplength;
+    l->l_contiguous = !has_holes;
 
     while (c < &loadcmds[nloadcmds])
       {

Modified: fsf/trunk/libc/elf/dl-lookup.c
==============================================================================
--- fsf/trunk/libc/elf/dl-lookup.c (original)
+++ fsf/trunk/libc/elf/dl-lookup.c Wed Jun 20 00:03:11 2007
@@ -86,7 +86,7 @@
 /* Add extra dependency on MAP to UNDEF_MAP.  */
 static int
 internal_function
-add_dependency (struct link_map *undef_map, struct link_map *map, int flags)
+add_dependency (struct link_map *undef_map, struct link_map *map)
 {
   struct link_map **list;
   struct link_map *runp;
@@ -99,18 +99,8 @@
   if (undef_map == map)
     return 0;
 
-  /* Make sure nobody can unload the object while we are at it.
-     If we hold a scope lock drop it now to avoid ABBA locking problems.  */
-  if ((flags & DL_LOOKUP_SCOPE_LOCK) != 0 && !RTLD_SINGLE_THREAD_P)
-    {
-      __rtld_mrlock_unlock (undef_map->l_scope_lock);
-
-      __rtld_lock_lock_recursive (GL(dl_load_lock));
-
-      __rtld_mrlock_lock (undef_map->l_scope_lock);
-    }
-  else
-    __rtld_lock_lock_recursive (GL(dl_load_lock));
+  /* Make sure nobody can unload the object while we are at it.  */
+  __rtld_lock_lock_recursive (GL(dl_load_lock));
 
   /* Avoid references to objects which cannot be unloaded anyway.  */
   if (map->l_type != lt_loaded
@@ -237,10 +227,9 @@
 
   bump_num_relocations ();
 
-  /* No other flag than DL_LOOKUP_ADD_DEPENDENCY and DL_LOOKUP_SCOPE_LOCK
-     is allowed if we look up a versioned symbol.  */
-  assert (version == NULL || (flags & ~(DL_LOOKUP_ADD_DEPENDENCY
-					| DL_LOOKUP_SCOPE_LOCK)) == 0);
+  /* No other flag than DL_LOOKUP_ADD_DEPENDENCY is allowed if we look
+     up a versioned symbol.  */
+  assert (version == NULL || (flags & ~(DL_LOOKUP_ADD_DEPENDENCY)) == 0);
 
   size_t i = 0;
   if (__builtin_expect (skip_map != NULL, 0))
@@ -346,13 +335,11 @@
 	 runtime lookups.  */
       && (flags & DL_LOOKUP_ADD_DEPENDENCY) != 0
       /* Add UNDEF_MAP to the dependencies.  */
-      && add_dependency (undef_map, current_value.m, flags) < 0)
+      && add_dependency (undef_map, current_value.m) < 0)
       /* Something went wrong.  Perhaps the object we tried to reference
 	 was just removed.  Try finding another definition.  */
-      return _dl_lookup_symbol_x (undef_name, undef_map, ref,
-				  (flags & DL_LOOKUP_SCOPE_LOCK) == 0
-				  ? symbol_scope : undef_map->l_scope, version,
-				  type_class, flags, skip_map);
+      return _dl_lookup_symbol_x (undef_name, undef_map, ref, symbol_scope,
+				  version, type_class, flags, skip_map);
 
   /* The object is used.  */
   current_value.m->l_used = 1;

Modified: fsf/trunk/libc/elf/dl-object.c
==============================================================================
--- fsf/trunk/libc/elf/dl-object.c (original)
+++ fsf/trunk/libc/elf/dl-object.c Wed Jun 20 00:03:11 2007
@@ -1,5 +1,5 @@
 /* Storage management for the chain of loaded shared objects.
-   Copyright (C) 1995-2002, 2004, 2006 Free Software Foundation, Inc.
+   Copyright (C) 1995-2002, 2004, 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
@@ -85,11 +85,6 @@
   new->l_scope = new->l_scope_mem;
   new->l_scope_max = sizeof (new->l_scope_mem) / sizeof (new->l_scope_mem[0]);
 
-  /* No need to initialize the scope lock if the initializer is zero.  */
-#if _RTLD_MRLOCK_INITIALIZER != 0
-  __rtld_mrlock_initialize (new->l_scope_lock);
-#endif
-
   /* Counter for the scopes we have to handle.  */
   idx = 0;
 

Modified: fsf/trunk/libc/elf/dl-open.c
==============================================================================
--- fsf/trunk/libc/elf/dl-open.c (original)
+++ fsf/trunk/libc/elf/dl-open.c Wed Jun 20 00:03:11 2007
@@ -165,6 +165,40 @@
   return 0;
 }
 
+int
+_dl_scope_free (struct r_scope_elem **old)
+{
+  struct dl_scope_free_list *fsl;
+#define DL_SCOPE_FREE_LIST_SIZE (sizeof (fsl->list) / sizeof (fsl->list[0]))
+
+  if (RTLD_SINGLE_THREAD_P)
+    free (old);
+  else if ((fsl = GL(dl_scope_free_list)) == NULL)
+    {
+      GL(dl_scope_free_list) = fsl = malloc (sizeof (*fsl));
+      if (fsl == NULL)
+	{
+	  THREAD_GSCOPE_WAIT ();
+	  free (old);
+	  return 1;
+	}
+      else
+	{
+	  fsl->list[0] = old;
+	  fsl->count = 1;
+	}
+    }
+  else if (fsl->count < DL_SCOPE_FREE_LIST_SIZE)
+    fsl->list[fsl->count++] = old;
+  else
+    {
+      THREAD_GSCOPE_WAIT ();
+      while (fsl->count > 0)
+	free (fsl->list[--fsl->count]);
+      return 1;
+    }
+  return 0;
+}
 
 static void
 dl_open_worker (void *a)
@@ -201,10 +235,10 @@
       for (Lmid_t ns = 0; ns < DL_NNS; ++ns)
 	for (l = GL(dl_ns)[ns]._ns_loaded; l != NULL; l = l->l_next)
 	  if (caller_dlopen >= (const void *) l->l_map_start
-	      && caller_dlopen < (const void *) l->l_map_end)
+	      && caller_dlopen < (const void *) l->l_map_end
+	      && (l->l_contiguous
+		  || _dl_addr_inside_object (l, (ElfW(Addr)) caller_dlopen)))
 	    {
-	      /* There must be exactly one DSO for the range of the virtual
-		 memory.  Otherwise something is really broken.  */
 	      assert (ns == l->l_ns);
 	      call_map = l;
 	      goto found_caller;
@@ -429,17 +463,10 @@
 	      memcpy (newp, imap->l_scope, cnt * sizeof (imap->l_scope[0]));
 	      struct r_scope_elem **old = imap->l_scope;
 
-	      if (RTLD_SINGLE_THREAD_P)
-		imap->l_scope = newp;
-	      else
-		{
-		  __rtld_mrlock_change (imap->l_scope_lock);
-		  imap->l_scope = newp;
-		  __rtld_mrlock_done (imap->l_scope_lock);
-		}
+	      imap->l_scope = newp;
 
 	      if (old != imap->l_scope_mem)
-		free (old);
+		_dl_scope_free (old);
 
 	      imap->l_scope_max = new_size;
 	    }
@@ -662,3 +689,21 @@
     }
 }
 #endif
+
+#ifdef IS_IN_rtld
+/* Return non-zero if ADDR lies within one of L's segments.  */
+int
+internal_function
+_dl_addr_inside_object (struct link_map *l, const ElfW(Addr) addr)
+{
+  int n = l->l_phnum;
+  const ElfW(Addr) reladdr = addr - l->l_addr;
+
+  while (--n >= 0)
+    if (l->l_phdr[n].p_type == PT_LOAD
+	&& reladdr - l->l_phdr[n].p_vaddr >= 0
+	&& reladdr - l->l_phdr[n].p_vaddr < l->l_phdr[n].p_memsz)
+      return 1;
+  return 0;
+}
+#endif

Modified: fsf/trunk/libc/elf/dl-runtime.c
==============================================================================
--- fsf/trunk/libc/elf/dl-runtime.c (original)
+++ fsf/trunk/libc/elf/dl-runtime.c Wed Jun 20 00:03:11 2007
@@ -100,21 +100,10 @@
 	 we are not using any threads (yet).  */
       int flags = DL_LOOKUP_ADD_DEPENDENCY;
       if (!RTLD_SINGLE_THREAD_P)
-	{
-	  THREAD_GSCOPE_SET_FLAG ();
-
-	  if (l->l_type == lt_loaded)
-	    {
-	      __rtld_mrlock_lock (l->l_scope_lock);
-	      flags |= DL_LOOKUP_SCOPE_LOCK;
-	    }
-	}
+	THREAD_GSCOPE_SET_FLAG ();
 
       result = _dl_lookup_symbol_x (strtab + sym->st_name, l, &sym, l->l_scope,
 				    version, ELF_RTYPE_CLASS_PLT, flags, NULL);
-
-      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)
@@ -203,22 +192,11 @@
 	     we are not using any threads (yet).  */
 	  int flags = DL_LOOKUP_ADD_DEPENDENCY;
 	  if (!RTLD_SINGLE_THREAD_P)
-	    {
-	      THREAD_GSCOPE_SET_FLAG ();
-
-	      if (l->l_type == lt_loaded)
-		{
-		  __rtld_mrlock_lock (l->l_scope_lock);
-		  flags |= DL_LOOKUP_SCOPE_LOCK;
-		}
-	    }
+	    THREAD_GSCOPE_SET_FLAG ();
 
 	  result = _dl_lookup_symbol_x (strtab + refsym->st_name, l,
 					&defsym, l->l_scope, version,
 					ELF_RTYPE_CLASS_PLT, flags, NULL);
-
-	  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)

Modified: fsf/trunk/libc/elf/dl-support.c
==============================================================================
--- fsf/trunk/libc/elf/dl-support.c (original)
+++ fsf/trunk/libc/elf/dl-support.c Wed Jun 20 00:03:11 2007
@@ -135,6 +135,8 @@
 /* Function in libpthread to wait for termination of lookups.  */
 void (*_dl_wait_lookup_done) (void);
 
+struct dl_scope_free_list *_dl_scope_free_list;
+
 #ifdef NEED_DL_SYSINFO
 /* Needed for improved syscall handling on at least x86/Linux.  */
 uintptr_t _dl_sysinfo = DL_SYSINFO_DEFAULT;

Modified: fsf/trunk/libc/elf/dl-sym.c
==============================================================================
--- fsf/trunk/libc/elf/dl-sym.c (original)
+++ fsf/trunk/libc/elf/dl-sym.c Wed Jun 20 00:03:11 2007
@@ -98,10 +98,9 @@
   for (Lmid_t ns = 0; ns < DL_NNS; ++ns)
     for (struct link_map *l = GL(dl_ns)[ns]._ns_loaded; l != NULL;
 	 l = l->l_next)
-      if (caller >= l->l_map_start && caller < l->l_map_end)
-	{
-	  /* There must be exactly one DSO for the range of the virtual
-	     memory.  Otherwise something is really broken.  */
+      if (caller >= l->l_map_start && caller < l->l_map_end
+	  && (l->l_contiguous || _dl_addr_inside_object (l, caller)))
+	{
 	  match = l;
 	  break;
 	}
@@ -113,21 +112,21 @@
 	 the initial binary.  And then the more complex part
 	 where the object is dynamically loaded and the scope
 	 array can change.  */
-      if (match->l_type != lt_loaded || RTLD_SINGLE_THREAD_P)
+      if (RTLD_SINGLE_THREAD_P)
 	result = GLRO(dl_lookup_symbol_x) (name, match, &ref,
 					   match->l_scope, vers, 0,
 					   flags | DL_LOOKUP_ADD_DEPENDENCY,
 					   NULL);
       else
 	{
-	  __rtld_mrlock_lock (match->l_scope_lock);
-
 	  struct call_dl_lookup_args args;
 	  args.name = name;
 	  args.map = match;
 	  args.vers = vers;
-	  args.flags = flags | DL_LOOKUP_ADD_DEPENDENCY | DL_LOOKUP_SCOPE_LOCK;
+	  args.flags = flags | DL_LOOKUP_ADD_DEPENDENCY;
 	  args.refp = &ref;
+
+	  THREAD_GSCOPE_SET_FLAG ();
 
 	  const char *objname;
 	  const char *errstring = NULL;
@@ -135,7 +134,7 @@
 	  int err = GLRO(dl_catch_error) (&objname, &errstring, &malloced,
 					  call_dl_lookup, &args);
 
-	  __rtld_mrlock_unlock (match->l_scope_lock);
+	  THREAD_GSCOPE_RESET_FLAG ();
 
 	  if (__builtin_expect (errstring != NULL, 0))
 	    {

Modified: fsf/trunk/libc/include/link.h
==============================================================================
--- fsf/trunk/libc/include/link.h (original)
+++ fsf/trunk/libc/include/link.h Wed Jun 20 00:03:11 2007
@@ -44,7 +44,6 @@
 #include <dl-lookupcfg.h>
 #include <tls.h>
 #include <bits/libc-lock.h>
-#include <rtld-lowlevel.h>
 
 
 /* Some internal data structures of the dynamic linker used in the
@@ -187,6 +186,9 @@
 				       is interested in the PLT interception.*/
     unsigned int l_removed:1;	/* Nozero if the object cannot be used anymore
 				   since it is removed.  */
+    unsigned int l_contiguous:1; /* Nonzero if inter-segment holes are
+				    mprotected or if no holes are present at
+				    all.  */
 
     /* Collected information about own RPATH directories.  */
     struct r_search_path_struct l_rpath_dirs;
@@ -220,8 +222,6 @@
     /* This is an array defining the lookup scope for this link map.
        There are initially at most three different scope lists.  */
     struct r_scope_elem **l_scope;
-    /* We need to protect using the SCOPEREC.  */
-    __rtld_mrlock_define (, l_scope_lock)
 
     /* A similar array, this time only with the local scope.  This is
        used occasionally.  */

Modified: fsf/trunk/libc/nptl/ChangeLog
==============================================================================
--- fsf/trunk/libc/nptl/ChangeLog (original)
+++ fsf/trunk/libc/nptl/ChangeLog Wed Jun 20 00:03:11 2007
@@ -1,3 +1,8 @@
+2007-06-19  Ulrich Drepper  <drepper@xxxxxxxxxx>
+
+	* sysdeps/unix/sysv/linux/rtld-lowlevel.h: Remove mrlock
+	implementation.
+
 2007-06-18  Ulrich Drepper  <drepper@xxxxxxxxxx>
 
 	* pthreadP.h: Define PTHREAD_MUTEX_TYPE.

Modified: fsf/trunk/libc/nptl/sysdeps/unix/sysv/linux/rtld-lowlevel.h
==============================================================================
--- fsf/trunk/libc/nptl/sysdeps/unix/sysv/linux/rtld-lowlevel.h (original)
+++ fsf/trunk/libc/nptl/sysdeps/unix/sysv/linux/rtld-lowlevel.h Wed Jun 20 00:03:11 2007
@@ -24,115 +24,6 @@
 #include <lowlevellock.h>
 
 
-/* Special multi-reader lock used in ld.so.  */
-#define __RTLD_MRLOCK_WRITER 1
-#define __RTLD_MRLOCK_RWAIT 2
-#define __RTLD_MRLOCK_WWAIT 4
-#define __RTLD_MRLOCK_RBITS \
-  ~(__RTLD_MRLOCK_WRITER | __RTLD_MRLOCK_RWAIT | __RTLD_MRLOCK_WWAIT)
-#define __RTLD_MRLOCK_INC 8
-#define __RTLD_MRLOCK_TRIES 5
-
-
-typedef int __rtld_mrlock_t;
-
-
-#define __rtld_mrlock_define(CLASS,NAME) \
-  CLASS __rtld_mrlock_t NAME;
-
-
-#define _RTLD_MRLOCK_INITIALIZER 0
-#define __rtld_mrlock_initialize(NAME) \
-  (void) ((NAME) = 0)
-
-
-#define __rtld_mrlock_lock(lock) \
-  do {									      \
-    __label__ out;							      \
-    while (1)								      \
-      {									      \
-	int oldval;							      \
-	for (int tries = 0; tries < __RTLD_MRLOCK_TRIES; ++tries)	      \
-	  {								      \
-	    oldval = lock;						      \
-	    while (__builtin_expect ((oldval				      \
-				      & (__RTLD_MRLOCK_WRITER		      \
-					 | __RTLD_MRLOCK_WWAIT))	      \
-				     == 0, 1))				      \
-	      {								      \
-		int newval = ((oldval & __RTLD_MRLOCK_RBITS)		      \
-			      + __RTLD_MRLOCK_INC);			      \
-		int ret = atomic_compare_and_exchange_val_acq (&(lock),	      \
-							       newval,	      \
-							       oldval);	      \
-		if (__builtin_expect (ret == oldval, 1))		      \
-		  goto out;						      \
-		oldval = ret;						      \
-	      }								      \
-	    atomic_delay ();						      \
-	  }								      \
-	if ((oldval & __RTLD_MRLOCK_RWAIT) == 0)			      \
-	  {								      \
-	    atomic_or (&(lock), __RTLD_MRLOCK_RWAIT);			      \
-	    oldval |= __RTLD_MRLOCK_RWAIT;				      \
-	  }								      \
-	lll_private_futex_wait (lock, oldval);				      \
-      }									      \
-  out:;									      \
-  } while (0)
-
-
-#define __rtld_mrlock_unlock(lock) \
-  do {									      \
-    int oldval = atomic_exchange_and_add (&(lock), -__RTLD_MRLOCK_INC);	      \
-    if (__builtin_expect ((oldval					      \
-			   & (__RTLD_MRLOCK_RBITS | __RTLD_MRLOCK_WWAIT))     \
-			  == (__RTLD_MRLOCK_INC | __RTLD_MRLOCK_WWAIT), 0))   \
-      /* We have to wake all threads since there might be some queued	      \
-	 readers already.  */						      \
-      lll_private_futex_wake (&(lock), 0x7fffffff);			      \
-  } while (0)
-
-
-/* There can only ever be one thread trying to get the exclusive lock.  */
-#define __rtld_mrlock_change(lock) \
-  do {									      \
-    __label__ out;							      \
-    while (1)								      \
-      {									      \
-	int oldval;							      \
-	for (int tries = 0; tries < __RTLD_MRLOCK_TRIES; ++tries)	      \
-	  {								      \
-	    oldval = lock;						      \
-	    while (__builtin_expect ((oldval & __RTLD_MRLOCK_RBITS) == 0, 1)) \
-	      {								      \
-		int newval = ((oldval & __RTLD_MRLOCK_RWAIT)		      \
-			      + __RTLD_MRLOCK_WRITER);			      \
-		int ret = atomic_compare_and_exchange_val_acq (&(lock),	      \
-							       newval,	      \
-							       oldval);	      \
-		if (__builtin_expect (ret == oldval, 1))		      \
-		  goto out;						      \
-		oldval = ret;						      \
-	      }								      \
-	    atomic_delay ();						      \
-	  }								      \
-	atomic_or (&(lock), __RTLD_MRLOCK_WWAIT);			      \
-	oldval |= __RTLD_MRLOCK_WWAIT;					      \
-	lll_private_futex_wait (lock, oldval);				      \
-      }									      \
-  out:;									      \
-  } while (0)
-
-
-#define __rtld_mrlock_done(lock) \
-  do {				 \
-    int oldval = atomic_exchange_and_add (&(lock), -__RTLD_MRLOCK_WRITER);    \
-    if (__builtin_expect ((oldval & __RTLD_MRLOCK_RWAIT) != 0, 0))	      \
-      lll_private_futex_wake (&(lock), 0x7fffffff);			      \
-  } while (0)
-
-
 /* Function to wait for variable become zero.  Used in ld.so for
    reference counters.  */
 #define __rtld_waitzero(word) \

Modified: fsf/trunk/libc/sysdeps/generic/ldsodefs.h
==============================================================================
--- fsf/trunk/libc/sysdeps/generic/ldsodefs.h (original)
+++ fsf/trunk/libc/sysdeps/generic/ldsodefs.h Wed Jun 20 00:03:11 2007
@@ -38,7 +38,6 @@
 #include <bits/libc-lock.h>
 #include <hp-timing.h>
 #include <tls.h>
-#include <rtld-lowlevel.h>
 
 __BEGIN_DECLS
 
@@ -439,18 +438,18 @@
   EXTERN void (*_dl_rtld_unlock_recursive) (void *);
 #endif
 
-  /* Prevailing state of the stack, PF_X indicating it's executable.  */
-  EXTERN ElfW(Word) _dl_stack_flags;
-
   /* If loading a shared object requires that we make the stack executable
      when it was not, we do it by calling this function.
      It returns an errno code or zero on success.  */
   EXTERN int (*_dl_make_stack_executable_hook) (void **) internal_function;
 
+  /* Prevailing state of the stack, PF_X indicating it's executable.  */
+  EXTERN ElfW(Word) _dl_stack_flags;
+
+  /* Flag signalling whether there are gaps in the module ID allocation.  */
+  EXTERN bool _dl_tls_dtv_gaps;
   /* Highest dtv index currently needed.  */
   EXTERN size_t _dl_tls_max_dtv_idx;
-  /* Flag signalling whether there are gaps in the module ID allocation.  */
-  EXTERN bool _dl_tls_dtv_gaps;
   /* Information about the dtv slots.  */
   EXTERN struct dtv_slotinfo_list
   {
@@ -488,6 +487,12 @@
 
   EXTERN void (*_dl_wait_lookup_done) (void);
 
+  /* Scopes to free after next THREAD_GSCOPE_WAIT ().  */
+  EXTERN struct dl_scope_free_list
+  {
+    size_t count;
+    struct r_scope_elem **list[50];
+  } *_dl_scope_free_list;
 #ifdef SHARED
 };
 # define __rtld_global_attribute__
@@ -534,15 +539,15 @@
 #define DL_DEBUG_HELP       (1 << 9)
 #define DL_DEBUG_PRELINK    (1 << 10)
 
-  /* Cached value of `getpagesize ()'.  */
-  EXTERN size_t _dl_pagesize;
-
   /* OS version.  */
   EXTERN unsigned int _dl_osversion;
   /* Platform name.  */
   EXTERN const char *_dl_platform;
   EXTERN size_t _dl_platformlen;
 
+  /* Cached value of `getpagesize ()'.  */
+  EXTERN size_t _dl_pagesize;
+
   /* Copy of the content of `_dl_main_searchlist' at startup time.  */
   EXTERN struct r_scope_elem _dl_initial_searchlist;
 
@@ -570,9 +575,6 @@
 
   /* Expected cache ID.  */
   EXTERN int _dl_correct_cache_id;
-
-  /* 0 if internal pointer values should not be guarded, 1 if they should.  */
-  EXTERN int _dl_pointer_guard;
 
   /* Mask for hardware capabilities that are available.  */
   EXTERN uint64_t _dl_hwcap;
@@ -657,6 +659,9 @@
   /* List of auditing interfaces.  */
   struct audit_ifaces *_dl_audit;
   unsigned int _dl_naudit;
+
+  /* 0 if internal pointer values should not be guarded, 1 if they should.  */
+  EXTERN int _dl_pointer_guard;
 };
 # define __rtld_global_attribute__
 # ifdef IS_IN_rtld
@@ -840,9 +845,7 @@
     DL_LOOKUP_ADD_DEPENDENCY = 1,
     /* Return most recent version instead of default version for
        unversioned lookup.  */
-    DL_LOOKUP_RETURN_NEWEST = 2,
-    /* Set if the scopr lock in the UNDEF_MAP is taken.  */
-    DL_LOOKUP_SCOPE_LOCK = 4
+    DL_LOOKUP_RETURN_NEWEST = 2
   };
 
 /* Lookup versioned symbol.  */
@@ -1050,6 +1053,11 @@
 		       Lmid_t nsid, int argc, char *argv[], char *env[])
      attribute_hidden;
 
+/* Free or queue for freeing scope OLD.  If other threads might be
+   in the middle of _dl_fixup, _dl_profile_fixup or dl*sym using the
+   old scope, OLD can't be freed until no thread is using it.  */
+extern int _dl_scope_free (struct r_scope_elem **old) attribute_hidden;
+
 /* Add module to slot information data.  */
 extern void _dl_add_to_slotinfo (struct link_map  *l) attribute_hidden;
 
@@ -1061,6 +1069,8 @@
    but never touch anything.  Return null if it's not allocated yet.  */
 extern void *_dl_tls_get_addr_soft (struct link_map *l) internal_function;
 
+extern int _dl_addr_inside_object (struct link_map *l, const ElfW(Addr) addr)
+     internal_function attribute_hidden;
 
 __END_DECLS