This is the mail archive of the libc-hacker@sourceware.cygnus.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 glibc 2.0.7


Hi,

This patch fixes a bug and also introduce a new variable, __dlopened.
It can be used by a shared library to check it is loaded via dlopen ()
or not.


-- 
H.J. Lu (hjl@gnu.org)
-----
Thu Jul 23 07:08:13 1998  H.J. Lu  <hjl@gnu.org>

	* elf/dl-open.c (_dl_open): Increment the open count if the
	shared object is put at the first place on the global scope
	list.
	Don't put the shared object on the global scope list twice.
	Use __dlopened to indicate if a shared object is loaded via
	dlopen.

	* elf/Makefile (routines): Add dlopened.

	* elf/dlopened.c: New.

Index: elf/dl-open.c
===================================================================
RCS file: /home/work/cvs/gnu/glibc-2.0/elf/dl-open.c,v
retrieving revision 1.1.1.5
diff -u -r1.1.1.5 dl-open.c
--- elf/dl-open.c	1998/03/31 16:18:44	1.1.1.5
+++ elf/dl-open.c	1998/07/23 21:53:46
@@ -36,6 +36,8 @@
 
 extern char **__environ;
 
+extern int __dlopened;
+
 static size_t _dl_global_scope_alloc;
 
 struct link_map *
@@ -91,7 +93,14 @@
     }
 
   new->l_global = (mode & RTLD_GLOBAL) ? 1 : 0;
-  if (new->l_global)
+
+  if (_dl_loaded == new)
+    /* We are put at the first place on the global scope list, one way
+       or the other. We may be used by other shared objects. We have to
+       make sure that it stays in memory for them. Increment the open
+       count. */
+    new->l_opencount++;
+  else if (new->l_global)
     {
       /* The symbols of the new object and its dependencies are to be
 	 introduced into the global scope that will be used to resolve
@@ -150,10 +159,12 @@
   r->r_state = RT_ADD;
   _dl_debug_state ();
 
+  __dlopened = 1;
   /* Run the initializer functions of new objects.  */
   while (init = _dl_init_next (new))
     (*(void (*) (int, char **, char **)) init) (__libc_argc, __libc_argv,
 						__environ);
+  __dlopened = 0;
 
   if (_dl_sysdep_start == NULL)
     /* We must be the static _dl_open in libc.a.  A static program that
Index: elf/Makefile
===================================================================
RCS file: /home/work/cvs/gnu/glibc-2.0/elf/Makefile,v
retrieving revision 1.1.1.4
diff -u -r1.1.1.4 Makefile
--- elf/Makefile	1998/07/21 21:15:59	1.1.1.4
+++ elf/Makefile	1998/07/23 21:50:06
@@ -22,7 +22,7 @@
 
 headers		= elf.h elfclass.h link.h dlfcn.h
 routines	= $(dl-routines) dl-open dl-close dl-symbol dl-support \
-		  enbl-secure
+		  enbl-secure dlopened
 
 # The core dynamic linking functions are in libc for the static and
 # profiled libraries.
--- /dev/null	Tue May  5 13:32:27 1998
+++ elf/dlopened.c	Thu Jul 23 14:50:23 1998
@@ -0,0 +1 @@
+int __dlopened = 0;


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