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


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

A patch for dynamic linker


Here is a patch for

http://sources.redhat.com/ml/libc-alpha/2000-12/msg00172.html

I will try to create a testcase later.


-- 
H.J. Lu (hjl@valinux.com)
---
2000-12-28  H.J. Lu  <hjl@gnu.org>

	* elf/dl-deps.c (_dl_map_object_deps): Make sure the DSO state
	is always consistent even if its dependency is failed.

	* elf/dl-open.c (_dl_open): Increment the open count before
	calling _dl_close () in case of failure.

Index: elf/dl-deps.c
===================================================================
RCS file: /work/cvs/gnu/glibc/elf/dl-deps.c,v
retrieving revision 1.1.1.9
diff -u -p -r1.1.1.9 dl-deps.c
--- elf/dl-deps.c	2000/12/28 06:34:19	1.1.1.9
+++ elf/dl-deps.c	2000/12/28 18:20:42
@@ -141,6 +141,10 @@ _dl_map_object_deps (struct link_map *ma
   struct list known[1 + npreloads + 1];
   struct list *runp, *utail, *dtail;
   unsigned int nlist, nduplist, i;
+  /* Object name.  */
+  const char *name;
+  int errno_saved;
+  int errno_reason;
 
   auto inline void preload (struct link_map *map);
 
@@ -192,6 +196,10 @@ _dl_map_object_deps (struct link_map *ma
      The whole process is complicated by the fact that we better
      should use alloca for the temporary list elements.  But using
      alloca means we cannot use recursive function calls.  */
+  errno_saved = errno;
+  errno_reason = 0;
+  errno = 0;
+  name = NULL;
   for (runp = known; runp; )
     {
       struct link_map *l = runp->map;
@@ -227,15 +235,24 @@ _dl_map_object_deps (struct link_map *ma
 		struct link_map *dep;
 		/* Allocate new entry.  */
 		struct list *newp;
-		/* Object name.  */
-		const char *name;
+		const char *objname;
+		const char *errstring;
 
 		/* Recognize DSTs.  */
 		name = expand_dst (l, strtab + d->d_un.d_val, 0);
+		/* Store the tag in the argument structure.  */
+		args.name = name;
 
-		dep = _dl_map_object (l, name, 0,
-				      l->l_type == lt_executable ? lt_library :
-				      l->l_type, trace_mode, 0);
+		if (_dl_catch_error (&objname, &errstring, openaux, &args))
+		  {
+		    if (errno)
+		      errno_reason = errno;
+		    else
+		      errno_reason = -1;
+		    goto out;
+		  }
+		else
+		  dep = args.aux;
 
 		/* Add it in any case to the duplicate list.  */
 		newp = alloca (sizeof (struct list));
@@ -266,18 +283,15 @@ _dl_map_object_deps (struct link_map *ma
 		const char *objname;
 		const char *errstring;
 		struct list *newp;
-		/* Object name.  */
-		const char *name;
 
 		/* Recognize DSTs.  */
 		name = expand_dst (l, strtab + d->d_un.d_val,
 				   d->d_tag == DT_AUXILIARY);
+		/* Store the tag in the argument structure.  */
+		args.name = name;
 
 		if (d->d_tag == DT_AUXILIARY)
 		  {
-		    /* Store the tag in the argument structure.  */
-		    args.name = name;
-
 		    /* Say that we are about to load an auxiliary library.  */
 		    if (__builtin_expect (_dl_debug_libs, 0))
 		      _dl_debug_message (1, "load auxiliary object=",
@@ -310,10 +324,14 @@ _dl_map_object_deps (struct link_map *ma
 					 "\n", NULL);
 
 		    /* For filter objects the dependency must be available.  */
-		    args.aux = _dl_map_object (l, name, 0,
-					       (l->l_type == lt_executable
-						? lt_library : l->l_type),
-					       trace_mode, 0);
+		    if (_dl_catch_error (&objname, &errstring, openaux, &args))
+		      {
+			if (errno)
+			  errno_reason = errno;
+			else
+			  errno_reason = -1;
+			goto out;
+		      }
 		  }
 
 		/* The auxiliary object is actually available.
@@ -460,6 +478,10 @@ _dl_map_object_deps (struct link_map *ma
 	while (runp != NULL && runp->done);
     }
 
+out:
+  if (errno == 0 && errno_saved != 0)
+    __set_errno (errno_saved);
+
   if (map->l_initfini != NULL && map->l_type == lt_loaded)
     {
       /* This object was previously loaded as a dependency and we have
@@ -558,4 +580,8 @@ _dl_map_object_deps (struct link_map *ma
     }
   /* Terminate the list of dependencies.  */
   map->l_initfini[nlist] = NULL;
+
+  if (errno_reason)
+    _dl_signal_error (errno_reason == -1 ? 0 : errno_reason,
+		      name ?: "", N_("cannot load shared object file"));
 }
Index: elf/dl-open.c
===================================================================
RCS file: /work/cvs/gnu/glibc/elf/dl-open.c,v
retrieving revision 1.1.1.12
diff -u -p -r1.1.1.12 dl-open.c
--- elf/dl-open.c	2000/12/28 06:34:19	1.1.1.12
+++ elf/dl-open.c	2000/12/28 17:43:44
@@ -396,7 +396,12 @@ _dl_open (const char *file, int mode, co
       /* Remove the object from memory.  It may be in an inconsistent
 	 state if relocation failed, for example.  */
       if (args.map)
-	_dl_close (args.map);
+	{
+	  int i;
+	  for (i = 0; i < args.map->l_searchlist.r_nlist; ++i)
+	    ++args.map->l_searchlist.r_list[i]->l_opencount;
+	  _dl_close (args.map);
+	}
 
       /* Make a local copy of the error string so that we can release the
 	 memory allocated for it.  */

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