summary refs log tree commit diff
path: root/elf
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1999-01-20 18:32:29 +0000
committerUlrich Drepper <drepper@redhat.com>1999-01-20 18:32:29 +0000
commitd3556ac929680a279b9a989b0797c1dba7da8389 (patch)
treeb9aa42fdee1b57dd3b5203141dedc2b080c43e5d /elf
parent0f6052a803a04dd461e514884fe0856ee03fa4a0 (diff)
downloadglibc-d3556ac929680a279b9a989b0797c1dba7da8389.tar.gz
glibc-d3556ac929680a279b9a989b0797c1dba7da8389.tar.xz
glibc-d3556ac929680a279b9a989b0797c1dba7da8389.zip
Update.
	* elf/dl-close.c: Handle failed loads which would have gone in the
	global scope correctly.

	* elf/testobj1.c: Include stdlib.h to get NULL defined.
	* elf/testobj2.c: Likewise.
	* elf/testobj3.c: Likewise.
	* elf/testobj4.c: Likewise.
	* elf/testobj5.c: Likewise.

	* iconvdata/sami-ws2.c: New file.
Diffstat (limited to 'elf')
-rw-r--r--elf/dl-close.c60
-rw-r--r--elf/testobj1.c1
-rw-r--r--elf/testobj2.c1
-rw-r--r--elf/testobj3.c1
-rw-r--r--elf/testobj4.c1
-rw-r--r--elf/testobj5.c1
6 files changed, 46 insertions, 19 deletions
diff --git a/elf/dl-close.c b/elf/dl-close.c
index 6a68651d22..8caa2973d9 100644
--- a/elf/dl-close.c
+++ b/elf/dl-close.c
@@ -106,29 +106,35 @@ _dl_close (struct link_map *map)
 	      unsigned int cnt = _dl_main_searchlist->r_nlist;
 
 	      do
-		--cnt;
+		if (--cnt < 0)
+		  break;
 	      while (_dl_main_searchlist->r_list[cnt] != imap);
 
-	      while (++cnt < _dl_main_searchlist->r_nlist)
-		_dl_main_searchlist->r_list[cnt - 1]
-		  = _dl_main_searchlist->r_list[cnt];
+	      if (cnt >= 0)
+		{
+		  /* The object was already correctly registered.  */
+		  while (++cnt < _dl_main_searchlist->r_nlist)
+		    _dl_main_searchlist->r_list[cnt - 1]
+		      = _dl_main_searchlist->r_list[cnt];
 
-	      --_dl_main_searchlist->r_nlist;
-	      if (_dl_main_searchlist->r_nlist
-		  == _dl_initial_searchlist.r_nlist)
+		  --_dl_main_searchlist->r_nlist;
+		}
+	      else
 		{
-		  /* All object dynamically loaded by the program are
-		     unloaded.  Free the memory allocated for the global
-		     scope variable.  */
-		  struct link_map **old = _dl_main_searchlist->r_list;
-
-		  /* Put the old map in.  */
-		  _dl_main_searchlist->r_list = _dl_initial_searchlist.r_list;
-		  /* Signal that the old map is used.  */
-		  _dl_global_scope_alloc = 0;
-
-		  /* Now free the old map.  */
-		  free (old);
+		  /* This can happen if loading was interrupted by something
+		     like a missing symbol in the newly loaded objects.  In
+		     this case the object is already marked as global but
+		     `r_nlist' does not count it in.  The pointer is in the
+		     `r_list' array so we keep searching in the other
+		     direction.  */
+		  cnt = _dl_main_searchlist->r_nlist;
+		  while (_dl_main_searchlist->r_list[cnt] != imap)
+		    {
+		      ++cnt;
+		      /* Note that if _dl_global_scope_alloc is zero we
+			 should never come here in the first place.  */
+		      assert (cnt < _dl_global_scope_alloc);
+		    }
 		}
 	    }
 
@@ -186,6 +192,22 @@ _dl_close (struct link_map *map)
 
   free (list);
 
+  if (_dl_global_scope_alloc != 0
+      && _dl_main_searchlist->r_nlist == _dl_initial_searchlist.r_nlist)
+    {
+      /* All object dynamically loaded by the program are unloaded.  Free
+	 the memory allocated for the global scope variable.  */
+      struct link_map **old = _dl_main_searchlist->r_list;
+
+      /* Put the old map in.  */
+      _dl_main_searchlist->r_list = _dl_initial_searchlist.r_list;
+      /* Signal that the original map is used.  */
+      _dl_global_scope_alloc = 0;
+
+      /* Now free the old map.  */
+      free (old);
+    }
+
   /* Notify the debugger those objects are finalized and gone.  */
   _r_debug.r_state = RT_CONSISTENT;
   _dl_debug_state ();
diff --git a/elf/testobj1.c b/elf/testobj1.c
index b88a8d0ce6..354e1a7c6c 100644
--- a/elf/testobj1.c
+++ b/elf/testobj1.c
@@ -1,4 +1,5 @@
 #include <dlfcn.h>
+#include <stdlib.h>
 
 int
 obj1func1 (int a __attribute__ ((unused)))
diff --git a/elf/testobj2.c b/elf/testobj2.c
index ba91fe873d..dc34ecb323 100644
--- a/elf/testobj2.c
+++ b/elf/testobj2.c
@@ -1,4 +1,5 @@
 #include <dlfcn.h>
+#include <stdlib.h>
 
 int
 obj2func1 (int a __attribute__ ((unused)))
diff --git a/elf/testobj3.c b/elf/testobj3.c
index f89b904cd4..1fb10f9b7f 100644
--- a/elf/testobj3.c
+++ b/elf/testobj3.c
@@ -1,4 +1,5 @@
 #include <dlfcn.h>
+#include <stdlib.h>
 
 int
 obj3func1 (int a __attribute__ ((unused)))
diff --git a/elf/testobj4.c b/elf/testobj4.c
index 38905c824a..d780bef077 100644
--- a/elf/testobj4.c
+++ b/elf/testobj4.c
@@ -1,4 +1,5 @@
 #include <dlfcn.h>
+#include <stdlib.h>
 
 int
 obj4func1 (int a __attribute__ ((unused)))
diff --git a/elf/testobj5.c b/elf/testobj5.c
index 0a2bbe07db..e30ca14cdc 100644
--- a/elf/testobj5.c
+++ b/elf/testobj5.c
@@ -1,4 +1,5 @@
 #include <dlfcn.h>
+#include <stdlib.h>
 
 int
 obj5func1 (int a __attribute__ ((unused)))