This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[PATCH] Remove r_duplist & r_nduplist


Hi!

As I wrote already yesterday, I don't see what is r_duplist for (used only
for RTLD_NEXT and there it cannot be right).
This patch removes duplist completely, saving some code and memory especially in
dl-deps. It passed glibc make check, plus all the tests I wrote yesterday
either give the same result, or in the one case I wrote exactly to show this
problem they give the same results as Solaris RTLD_NEXT.
If you want I'll hack up a glibc testcase from it.

Also, _dl_symbol_value seems to be unused (not exported from glibc, not used
by glibc internally and in addition to that marked as internal_function, so
anything outside of glibc wouldn't know how to call it anyway), so I've
removed it.

2001-05-18  Jakub Jelinek  <jakub@redhat.com>

	* include/link.h (struct r_scope_elem): Remove r_duplist and
	r_nduplist fields.
	* elf/dl-load.c (_dl_map_object_from_fd): Don't initialize them.
	* elf/dl-lookup.c (_dl_lookup_symbol_skip): Look in r_list, not
	r_duplist.
	(_dl_lookup_versioned_symbol_skip): Likewise.
	* elf/dl-deps.c (struct list): Remove dup field, rename unique to
	next.
	(_dl_map_object_deps): Don't compute duplicate list.

	* elf/dl-symbol.c: Removed.
	* elf/Makefile (routines): Remove dl-symbol.

--- libc/elf/dl-load.c.jj	Tue Mar 20 13:45:11 2001
+++ libc/elf/dl-load.c	Fri May 18 09:42:03 2001
@@ -1126,8 +1126,6 @@ _dl_map_object_from_fd (const char *name
 
       l->l_symbolic_searchlist.r_list[0] = l;
       l->l_symbolic_searchlist.r_nlist = 1;
-      l->l_symbolic_searchlist.r_duplist = l->l_symbolic_searchlist.r_list;
-      l->l_symbolic_searchlist.r_nduplist = 1;
 
       /* Now move the existing entries one back.  */
       memmove (&l->l_scope[1], &l->l_scope[0],
--- libc/elf/dl-lookup.c.jj	Fri Mar  2 13:44:29 2001
+++ libc/elf/dl-lookup.c	Fri May 18 09:43:34 2001
@@ -299,12 +299,11 @@ _dl_lookup_symbol_skip (const char *unde
 
   /* Search the relevant loaded objects for a definition.  */
   scope = symbol_scope;
-  for (i = 0; (*scope)->r_duplist[i] != skip_map; ++i)
-    assert (i < (*scope)->r_nduplist);
+  for (i = 0; (*scope)->r_list[i] != skip_map; ++i)
+    assert (i < (*scope)->r_nlist);
 
-  if (i >= (*scope)->r_nlist
-	 || ! do_lookup (undef_name, hash, *ref, &current_value, *scope, i,
-			 skip_map, 0, 0))
+  if (! do_lookup (undef_name, hash, *ref, &current_value, *scope, i,
+		   skip_map, 0, 0))
     while (*++scope)
       if (do_lookup (undef_name, hash, *ref, &current_value, *scope, 0,
 		     skip_map, 0, 0))
@@ -502,12 +501,11 @@ _dl_lookup_versioned_symbol_skip (const 
 
   /* Search the relevant loaded objects for a definition.  */
   scope = symbol_scope;
-  for (i = 0; (*scope)->r_duplist[i] != skip_map; ++i)
-    assert (i < (*scope)->r_nduplist);
+  for (i = 0; (*scope)->r_list[i] != skip_map; ++i)
+    assert (i < (*scope)->r_nlist);
 
-  if (i >= (*scope)->r_nlist
-      || ! do_lookup_versioned (undef_name, hash, *ref, &current_value,
-				*scope, i, version, skip_map, 0, 0))
+  if (! do_lookup_versioned (undef_name, hash, *ref, &current_value,
+			     *scope, i, version, skip_map, 0, 0))
     while (*++scope)
       if (do_lookup_versioned (undef_name, hash, *ref, &current_value, *scope,
 			       0, version, skip_map, 0, 0))
--- libc/elf/dl-deps.c.jj	Tue Apr 17 23:58:34 2001
+++ libc/elf/dl-deps.c	Fri May 18 10:01:48 2001
@@ -72,20 +72,15 @@ openaux (void *a)
 
 
 
-/* We use a very special kind of list to track the two kinds paths
+/* We use a very special kind of list to track the path
    through the list of loaded shared objects.  We have to
-
-   - produce a flat list with unique members of all involved objects
-
-   - produce a flat list of all shared objects.
+   produce a flat list with unique members of all involved objects.
 */
 struct list
   {
     int done;			/* Nonzero if this map was processed.  */
     struct link_map *map;	/* The data.  */
-
-    struct list *unique;	/* Elements for normal list.  */
-    struct list *dup;		/* Elements in complete list.  */
+    struct list *next;	/* Elements for normal list.  */
   };
 
 
@@ -139,8 +134,8 @@ _dl_map_object_deps (struct link_map *ma
 		     int trace_mode)
 {
   struct list known[1 + npreloads + 1];
-  struct list *runp, *utail, *dtail;
-  unsigned int nlist, nduplist, i;
+  struct list *runp, *tail;
+  unsigned int nlist, i;
   /* Object name.  */
   const char *name;
   int errno_saved;
@@ -153,9 +148,7 @@ _dl_map_object_deps (struct link_map *ma
     {
       known[nlist].done = 0;
       known[nlist].map = map;
-
-      known[nlist].unique = &known[nlist + 1];
-      known[nlist].dup = &known[nlist + 1];
+      known[nlist].next = &known[nlist + 1];
 
       ++nlist;
       /* We use `l_reserved' as a mark bit to detect objects we have
@@ -175,17 +168,10 @@ _dl_map_object_deps (struct link_map *ma
     preload (preloads[i]);
 
   /* Terminate the lists.  */
-  known[nlist - 1].unique = NULL;
-  known[nlist - 1].dup = NULL;
+  known[nlist - 1].next = NULL;
 
   /* Pointer to last unique object.  */
-  utail = &known[nlist - 1];
-  /* Pointer to last loaded object.  */
-  dtail = &known[nlist - 1];
-
-  /* Until now we have the same number of libraries in the normal and
-     the list with duplicates.  */
-  nduplist = nlist;
+  tail = &known[nlist - 1];
 
   /* Process each element of the search list, loading each of its
      auxiliary objects and immediate dependencies.  Auxiliary objects
@@ -235,8 +221,6 @@ _dl_map_object_deps (struct link_map *ma
 	      {
 		/* Map in the needed object.  */
 		struct link_map *dep;
-		/* Allocate new entry.  */
-		struct list *newp;
 		const char *objname;
 
 		/* Recognize DSTs.  */
@@ -255,21 +239,19 @@ _dl_map_object_deps (struct link_map *ma
 		else
 		  dep = args.aux;
 
-		/* Add it in any case to the duplicate list.  */
-		newp = alloca (sizeof (struct list));
-		newp->map = dep;
-		newp->dup = NULL;
-		dtail->dup = newp;
-		dtail = newp;
-		++nduplist;
-
 		if (! dep->l_reserved)
 		  {
-		    /* Append DEP to the unique list.  */
+		    /* Allocate new entry.  */
+		    struct list *newp;
+
+		    newp = alloca (sizeof (struct list));
+
+		    /* Append DEP to the list.  */
+		    newp->map = dep;
 		    newp->done = 0;
-		    newp->unique = NULL;
-		    utail->unique = newp;
-		    utail = newp;
+		    newp->next = NULL;
+		    tail->next = newp;
+		    tail = newp;
 		    ++nlist;
 		    /* Set the mark bit that says it's already in the list.  */
 		    dep->l_reserved = 1;
@@ -343,7 +325,7 @@ _dl_map_object_deps (struct link_map *ma
 		   but we have no back links.  So we copy the contents of
 		   the current entry over.  Note that ORIG and NEWP now
 		   have switched their meanings.  */
-		orig->dup = memcpy (newp, orig, sizeof (*newp));
+		memcpy (newp, orig, sizeof (*newp));
 
 		/* Initialize new entry.  */
 		orig->done = 0;
@@ -372,22 +354,22 @@ _dl_map_object_deps (struct link_map *ma
 		    /* This object is already in the search list we
 		       are building.  Don't add a duplicate pointer.
 		       Just added by _dl_map_object.  */
-		    for (late = newp; late->unique; late = late->unique)
-		      if (late->unique->map == args.aux)
+		    for (late = newp; late->next; late = late->next)
+		      if (late->next->map == args.aux)
 			break;
 
-		    if (late->unique)
+		    if (late->next)
 		      {
 			/* The object is somewhere behind the current
 			   position in the search path.  We have to
 			   move it to this earlier position.  */
-			orig->unique = newp;
+			orig->next = newp;
 
-			/* Now remove the later entry from the unique list
+			/* Now remove the later entry from the list
 			   and adjust the tail pointer.  */
-			if (utail == late->unique)
-			  utail = late;
-			late->unique = late->unique->unique;
+			if (tail == late->next)
+			  tail = late;
+			late->next = late->next->next;
 
 			/* We must move the object earlier in the chain.  */
 			if (args.aux->l_prev)
@@ -406,25 +388,25 @@ _dl_map_object_deps (struct link_map *ma
 			/* The object must be somewhere earlier in the
 			   list.  That's good, we only have to insert
 			   an entry for the duplicate list.  */
-			orig->unique = NULL;	/* Never used.  */
+			orig->next = NULL;	/* Never used.  */
 
 			/* Now we have a problem.  The element
-			   pointing to ORIG in the unique list must
+			   pointing to ORIG in the list must
 			   point to NEWP now.  This is the only place
 			   where we need this backreference and this
 			   situation is really not that frequent.  So
 			   we don't use a double-linked list but
 			   instead search for the preceding element.  */
 			late = known;
-			while (late->unique != orig)
-			  late = late->unique;
-			late->unique = newp;
+			while (late->next != orig)
+			  late = late->next;
+			late->next = newp;
 		      }
 		  }
 		else
 		  {
 		    /* This is easy.  We just add the symbol right here.  */
-		    orig->unique = newp;
+		    orig->next = newp;
 		    ++nlist;
 		    /* Set the mark bit that says it's already in the list.  */
 		    args.aux->l_reserved = 1;
@@ -444,17 +426,12 @@ _dl_map_object_deps (struct link_map *ma
 		    args.aux->l_next = newp->map;
 		  }
 
-		/* Move the tail pointers if necessary.  */
-		if (orig == utail)
-		  utail = newp;
-		if (orig == dtail)
-		  dtail = newp;
+		/* Move the tail pointer if necessary.  */
+		if (orig == tail)
+		  tail = newp;
 
 		/* Move on the insert point.  */
 		orig = newp;
-
-		/* We always add an entry to the duplicate list.  */
-		++nduplist;
 	      }
 	}
 
@@ -473,7 +450,7 @@ _dl_map_object_deps (struct link_map *ma
       /* If we have no auxiliary objects just go on to the next map.  */
       if (runp->done)
 	do
-	  runp = runp->unique;
+	  runp = runp->next;
 	while (runp != NULL && runp->done);
     }
 
@@ -492,8 +469,7 @@ out:
   /* Store the search list we built in the object.  It will be used for
      searches in the scope of this object.  */
   map->l_initfini =
-    (struct link_map **) malloc ((2 * nlist + 1
-				  + (nlist == nduplist ? 0 : nduplist))
+    (struct link_map **) malloc ((2 * nlist + 1)
 				 * sizeof (struct link_map *));
   if (map->l_initfini == NULL)
     _dl_signal_error (ENOMEM, map->l_name,
@@ -503,7 +479,7 @@ out:
   map->l_searchlist.r_list = &map->l_initfini[nlist + 1];
   map->l_searchlist.r_nlist = nlist;
 
-  for (nlist = 0, runp = known; runp; runp = runp->unique)
+  for (nlist = 0, runp = known; runp; runp = runp->next)
     {
       if (trace_mode && runp->map->l_faked)
 	/* This can happen when we trace the loading.  */
@@ -514,23 +490,6 @@ out:
       /* Now clear all the mark bits we set in the objects on the search list
 	 to avoid duplicates, so the next call starts fresh.  */
       runp->map->l_reserved = 0;
-    }
-
-  map->l_searchlist.r_nduplist = nduplist;
-  if (nlist == nduplist)
-    map->l_searchlist.r_duplist = map->l_searchlist.r_list;
-  else
-    {
-      unsigned int cnt;
-
-      map->l_searchlist.r_duplist = map->l_searchlist.r_list + nlist;
-
-      for (cnt = 0, runp = known; runp; runp = runp->dup)
-	if (trace_mode && runp->map->l_faked)
-	  /* This can happen when we trace the loading.  */
-	  --map->l_searchlist.r_nduplist;
-	else
-	  map->l_searchlist.r_duplist[cnt++] = runp->map;
     }
 
   /* Now determine the order in which the initialization has to happen.  */
--- libc/include/link.h.jj	Thu Nov  2 08:51:40 2000
+++ libc/include/link.h	Fri May 18 09:41:32 2001
@@ -93,11 +93,6 @@ struct r_scope_elem
   struct link_map **r_list;
   /* Number of entries in the scope.  */
   unsigned int r_nlist;
-
-  /* Array of maps which also includes duplicates.  */
-  struct link_map **r_duplist;
-  /* Number of elements in this list.  */
-  unsigned int r_nduplist;
 };
 
 
--- libc/elf/dl-symbol.c.jj	Fri Sep  1 11:37:58 2000
+++ libc/elf/dl-symbol.c	Fri May 18 10:40:39 2001
@@ -1,33 +0,0 @@
-/* Look up a symbol's run-time value in the scope of a loaded object.
-   Copyright (C) 1995, 96, 98, 99, 2000 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
-   modify it under the terms of the GNU Library General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
-
-   You should have received a copy of the GNU Library General Public
-   License along with the GNU C Library; see the file COPYING.LIB.  If not,
-   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
-
-#include <stddef.h>
-#include <ldsodefs.h>
-
-/* Look up symbol NAME in MAP's scope and return its run-time address.  */
-
-ElfW(Addr)
-internal_function
-_dl_symbol_value (struct link_map *map, const char *name)
-{
-  const ElfW(Sym) *ref = NULL;
-  lookup_t result;
-  result = _dl_lookup_symbol (name, map, &ref, map->l_local_scope, 0, 1);
-  return (result ? LOOKUP_VALUE_ADDRESS (result) : 0) + ref->st_value;
-}
--- libc/elf/Makefile.jj	Fri May 11 00:47:48 2001
+++ libc/elf/Makefile	Fri May 18 10:40:55 2001
@@ -21,7 +21,7 @@
 subdir		:= elf
 
 headers		= elf.h bits/elfclass.h link.h
-routines	= $(dl-routines) dl-open dl-close dl-symbol dl-support \
+routines	= $(dl-routines) dl-open dl-close dl-support \
 		  dl-addr enbl-secure dl-profstub dl-origin dl-libc dl-sym
 
 # The core dynamic linking functions are in libc for the static and

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]