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]

Re: A patch for glibc 2.0.7


> 
> hjl@lucon.org (H.J. Lu) writes:
> 
> > 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.
> 
> We cannot use global variables.  You should have learned this.  Your

I don't see it should be a problem. __dlopened will be always 1 after
main () since it is the only way to load a shared library beyond
main (). It is a constant. Here is a new patch.

> proposal for this C++ initialization problem cannot work.  We must
> find a different solution.
> 

It seems to work for me. Can you tell me why it cannot work?

Thanks.

H.J.
----
Index: dl-open.c
===================================================================
RCS file: /home/work/cvs/gnu/glibc-2.0/elf/dl-open.c,v
retrieving revision 1.1.1.5
diff -p -u -r1.1.1.5 dl-open.c
--- dl-open.c	1998/03/31 16:18:44	1.1.1.5
+++ dl-open.c	1998/07/23 23:20:49
@@ -36,6 +36,8 @@ extern char **__libc_argv;
 
 extern char **__environ;
 
+extern int __dlopened;
+
 static size_t _dl_global_scope_alloc;
 
 struct link_map *
@@ -51,6 +53,8 @@ _dl_open (const char *file, int mode)
     /* It was already open.  */
     return new;
 
+  __dlopened = 1;
+
   /* Load that object's dependencies.  */
   _dl_map_object_deps (new, NULL, 0, 0);
 
@@ -91,7 +95,14 @@ _dl_open (const char *file, int mode)
     }
 
   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


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