Blame SOURCES/glibc-rh646954.patch

b40826
2010-10-26  Ulrich Drepper  <drepper@gmail.com>
b40826
b40826
	* elf/rtld.c (dl_main): Move assertion after the point where rtld map
b40826
	is added to the list.
b40826
b40826
2010-10-20  Andreas Krebbel  <Andreas.Krebbel@de.ibm.com>
b40826
	    Ulrich Drepper  <drepper@gmail.com>
b40826
b40826
	* elf/dl-object.c (_dl_new_object): Don't append the new object to
b40826
	the global list here.  Move code to...
b40826
	(_dl_add_to_namespace_list): ...here.  New function.
b40826
	* elf/rtld.c (dl_main): Invoke _dl_add_to_namespace_list.
b40826
	* sysdeps/generic/ldsodefs.h (_dl_add_to_namespace_list): Declare.
b40826
	* elf/dl-load.c (lose): Don't remove the element from the list.
b40826
	(_dl_map_object_from_fd): Invoke _dl_add_to_namespace_list.
b40826
	(_dl_map_object): Likewise.
b40826
b40826
Index: glibc-2.12-2-gc4ccff1/elf/dl-load.c
b40826
===================================================================
b40826
--- glibc-2.12-2-gc4ccff1.orig/elf/dl-load.c
b40826
+++ glibc-2.12-2-gc4ccff1/elf/dl-load.c
b40826
@@ -797,22 +797,7 @@ lose (int code, int fd, const char *name
b40826
   /* The file might already be closed.  */
b40826
   if (fd != -1)
b40826
     (void) __close (fd);
b40826
-  if (l != NULL)
b40826
-    {
b40826
-      /* We modify the list of loaded objects.  */
b40826
-      __rtld_lock_lock_recursive (GL(dl_load_write_lock));
b40826
-      /* Remove the stillborn object from the list and free it.  */
b40826
-      assert (l->l_next == NULL);
b40826
-      if (l->l_prev == NULL)
b40826
-	/* No other module loaded. This happens only in the static library,
b40826
-	   or in rtld under --verify.  */
b40826
-	GL(dl_ns)[l->l_ns]._ns_loaded = NULL;
b40826
-      else
b40826
-	l->l_prev->l_next = NULL;
b40826
-      --GL(dl_ns)[l->l_ns]._ns_nloaded;
b40826
-      free (l);
b40826
-      __rtld_lock_unlock_recursive (GL(dl_load_write_lock));
b40826
-    }
b40826
+  free (l);
b40826
   free (realname);
b40826
 
b40826
   if (r != NULL)
b40826
@@ -897,6 +882,9 @@ _dl_map_object_from_fd (const char *name
b40826
 	 never be unloaded.  */
b40826
       __close (fd);
b40826
 
b40826
+      /* Add the map for the mirrored object to the object list.  */
b40826
+      _dl_add_to_namespace_list (l, nsid);
b40826
+
b40826
       return l;
b40826
     }
b40826
 #endif
b40826
@@ -1491,6 +1479,9 @@ cannot enable executable stack as shared
b40826
     add_name_to_object (l, ((const char *) D_PTR (l, l_info[DT_STRTAB])
b40826
 			    + l->l_info[DT_SONAME]->d_un.d_val));
b40826
 
b40826
+  /* Now that the object is fully initialized add it to the object list.  */
b40826
+  _dl_add_to_namespace_list (l, nsid);
b40826
+
b40826
 #ifdef SHARED
b40826
   /* Auditing checkpoint: we have a new object.  */
b40826
   if (__builtin_expect (GLRO(dl_naudit) > 0, 0)
b40826
@@ -2215,7 +2206,7 @@ _dl_map_object (struct link_map *loader,
b40826
 	     have.  */
b40826
 	  static const Elf_Symndx dummy_bucket = STN_UNDEF;
b40826
 
b40826
-	  /* Enter the new object in the list of loaded objects.  */
b40826
+	  /* Allocate a new object map.  */
b40826
 	  if ((name_copy = local_strdup (name)) == NULL
b40826
 	      || (l = _dl_new_object (name_copy, name, type, loader,
b40826
 				      mode, nsid)) == NULL)
b40826
@@ -2233,6 +2224,9 @@ _dl_map_object (struct link_map *loader,
b40826
 	  l->l_nbuckets = 1;
b40826
 	  l->l_relocated = 1;
b40826
 
b40826
+	  /* Enter the object in the object list.  */
b40826
+	  _dl_add_to_namespace_list (l, nsid);
b40826
+
b40826
 	  return l;
b40826
 	}
b40826
       else if (found_other_class)
b40826
Index: glibc-2.12-2-gc4ccff1/elf/dl-object.c
b40826
===================================================================
b40826
--- glibc-2.12-2-gc4ccff1.orig/elf/dl-object.c
b40826
+++ glibc-2.12-2-gc4ccff1/elf/dl-object.c
b40826
@@ -26,16 +26,41 @@
b40826
 #include <assert.h>
b40826
 
b40826
 
b40826
+/* Add the new link_map NEW to the end of the namespace list.  */
b40826
+void
b40826
+internal_function
b40826
+_dl_add_to_namespace_list (struct link_map *new, Lmid_t nsid)
b40826
+{
b40826
+  /* We modify the list of loaded objects.  */
b40826
+  __rtld_lock_lock_recursive (GL(dl_load_write_lock));
b40826
+
b40826
+  if (GL(dl_ns)[nsid]._ns_loaded != NULL)
b40826
+    {
b40826
+      struct link_map *l = GL(dl_ns)[nsid]._ns_loaded;
b40826
+      while (l->l_next != NULL)
b40826
+	l = l->l_next;
b40826
+      new->l_prev = l;
b40826
+      /* new->l_next = NULL;   Would be necessary but we use calloc.  */
b40826
+      l->l_next = new;
b40826
+    }
b40826
+  else
b40826
+    GL(dl_ns)[nsid]._ns_loaded = new;
b40826
+  ++GL(dl_ns)[nsid]._ns_nloaded;
b40826
+  new->l_serial = GL(dl_load_adds);
b40826
+  ++GL(dl_load_adds);
b40826
+
b40826
+  __rtld_lock_unlock_recursive (GL(dl_load_write_lock));
b40826
+}
b40826
+
b40826
+
b40826
 /* Allocate a `struct link_map' for a new object being loaded,
b40826
    and enter it into the _dl_loaded list.  */
b40826
-
b40826
 struct link_map *
b40826
 internal_function
b40826
 _dl_new_object (char *realname, const char *libname, int type,
b40826
 		struct link_map *loader, int mode, Lmid_t nsid)
b40826
 {
b40826
   struct link_map *l;
b40826
-  int idx;
b40826
   size_t libname_len = strlen (libname) + 1;
b40826
   struct link_map *new;
b40826
   struct libname_list *newname;
b40826
@@ -93,31 +118,12 @@ _dl_new_object (char *realname, const ch
b40826
   new->l_scope = new->l_scope_mem;
b40826
   new->l_scope_max = sizeof (new->l_scope_mem) / sizeof (new->l_scope_mem[0]);
b40826
 
b40826
-  /* We modify the list of loaded objects.  */
b40826
-  __rtld_lock_lock_recursive (GL(dl_load_write_lock));
b40826
-
b40826
   /* Counter for the scopes we have to handle.  */
b40826
-  idx = 0;
b40826
+  int idx = 0;
b40826
 
b40826
   if (GL(dl_ns)[nsid]._ns_loaded != NULL)
b40826
-    {
b40826
-      l = GL(dl_ns)[nsid]._ns_loaded;
b40826
-      while (l->l_next != NULL)
b40826
-	l = l->l_next;
b40826
-      new->l_prev = l;
b40826
-      /* new->l_next = NULL;	Would be necessary but we use calloc.  */
b40826
-      l->l_next = new;
b40826
-
b40826
-      /* Add the global scope.  */
b40826
-      new->l_scope[idx++] = &GL(dl_ns)[nsid]._ns_loaded->l_searchlist;
b40826
-    }
b40826
-  else
b40826
-    GL(dl_ns)[nsid]._ns_loaded = new;
b40826
-  ++GL(dl_ns)[nsid]._ns_nloaded;
b40826
-  new->l_serial = GL(dl_load_adds);
b40826
-  ++GL(dl_load_adds);
b40826
-
b40826
-  __rtld_lock_unlock_recursive (GL(dl_load_write_lock));
b40826
+    /* Add the global scope.  */
b40826
+    new->l_scope[idx++] = &GL(dl_ns)[nsid]._ns_loaded->l_searchlist;
b40826
 
b40826
   /* If we have no loader the new object acts as it.  */
b40826
   if (loader == NULL)
b40826
Index: glibc-2.12-2-gc4ccff1/elf/rtld.c
b40826
===================================================================
b40826
--- glibc-2.12-2-gc4ccff1.orig/elf/rtld.c
b40826
+++ glibc-2.12-2-gc4ccff1/elf/rtld.c
b40826
@@ -1108,11 +1108,15 @@ of this helper program; chances are you 
b40826
       main_map = _dl_new_object ((char *) "", "", lt_executable, NULL,
b40826
 				 __RTLD_OPENEXEC, LM_ID_BASE);
b40826
       assert (main_map != NULL);
b40826
-      assert (main_map == GL(dl_ns)[LM_ID_BASE]._ns_loaded);
b40826
       main_map->l_phdr = phdr;
b40826
       main_map->l_phnum = phnum;
b40826
       main_map->l_entry = *user_entry;
b40826
 
b40826
+      /* Even though the link map is not yet fully initialized we can add
b40826
+	 it to the map list since there are no possible users running yet.  */
b40826
+      _dl_add_to_namespace_list (main_map, LM_ID_BASE);
b40826
+      assert (main_map == GL(dl_ns)[LM_ID_BASE]._ns_loaded);
b40826
+
b40826
       /* At this point we are in a bit of trouble.  We would have to
b40826
 	 fill in the values for l_dev and l_ino.  But in general we
b40826
 	 do not know where the file is.  We also do not handle AT_EXECFD
b40826
@@ -1380,6 +1384,9 @@ of this helper program; chances are you 
b40826
 	      l->l_libname->name = memcpy (copy, dsoname, len);
b40826
 	    }
b40826
 
b40826
+	  /* Add the vDSO to the object list.  */
b40826
+	  _dl_add_to_namespace_list (l, LM_ID_BASE);
b40826
+
b40826
 	  /* Rearrange the list so this DSO appears after rtld_map.  */
b40826
 	  assert (l->l_next == NULL);
b40826
 	  assert (l->l_prev == main_map);
b40826
Index: glibc-2.12-2-gc4ccff1/sysdeps/generic/ldsodefs.h
b40826
===================================================================
b40826
--- glibc-2.12-2-gc4ccff1.orig/sysdeps/generic/ldsodefs.h
b40826
+++ glibc-2.12-2-gc4ccff1/sysdeps/generic/ldsodefs.h
b40826
@@ -891,8 +891,11 @@ extern lookup_t _dl_lookup_symbol_x (con
b40826
 extern ElfW(Addr) _dl_symbol_value (struct link_map *map, const char *name)
b40826
      internal_function;
b40826
 
b40826
-/* Allocate a `struct link_map' for a new object being loaded,
b40826
-   and enter it into the _dl_main_map list.  */
b40826
+/* Add the new link_map NEW to the end of the namespace list.  */
b40826
+extern void _dl_add_to_namespace_list (struct link_map *new, Lmid_t nsid)
b40826
+     internal_function attribute_hidden;
b40826
+
b40826
+/* Allocate a `struct link_map' for a new object being loaded.  */
b40826
 extern struct link_map *_dl_new_object (char *realname, const char *libname,
b40826
 					int type, struct link_map *loader,
b40826
 					int mode, Lmid_t nsid)