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]
Other format: [Raw text]

Re: enabling caching for dl_iterate_phdr()


>>>>> On Sat, 24 Jan 2004 12:11:14 -0800, Ulrich Drepper <drepper@redhat.com> said:

  Uli> David Mosberger wrote:
  >> Attached is an updated patch.  "make check subdirs=elf" passes
  >> all tests (including the new tst-dlmodcount test).

  Uli> I've applied the patch.

Thanks!

In the meantime, it occurred to me that we can get rid of one of the
"unsigned long long" variables by taking advantage of the fact that
"_dl_nloaded == _dl_load_adds - _dl_load_subs" (provided there are
never more than 0xffffffff shared objects loaded).  Apart from saving
8 bytes of global data, it also has the advantage that it makes code
maintenance a bit easier.  The rule is very simple now: wherever
_dl_nloaded gets incremented, _dl_load_adds needs to be incremented as
well.

If it looks OK to you, please apply (it was "make subdirs=elf check" tested).

Thanks,

	--david

ChangeLog

2004-01-26  David Mosberger  <davidm@hpl.hp.com>

	* elf/link.h (struct dl_phdr_info): Fix typo in comment.
	* elf/rtld.c (dl_main): After incrementing dl_nloaded, also
	increment dl_load_adds.
	* elf/dl-iteratephdr.c (__dl_iterate_phdr): Replace GL(dl_load_subs)
	with equivalent GL(dl_load_adds - GL(dl_nloaded).
	(dl_iterate_phdr): Likewise.
	* elf/dl-close.c (_dl_close): Delete increment of GL(dl_load_subs).
	* elf/dl-support.c: Remove global variable _dl_load_subs.
	* sysdeps/generic/ldsodefs.h (struct rtld_global): Remove
	_dl_load_subs member.

Index: elf/dl-close.c
===================================================================
RCS file: /cvs/glibc/libc/elf/dl-close.c,v
retrieving revision 1.99
diff -u -r1.99 dl-close.c
--- elf/dl-close.c	24 Jan 2004 20:07:38 -0000	1.99
+++ elf/dl-close.c	26 Jan 2004 21:42:35 -0000
@@ -319,7 +319,6 @@
   /* Notify the debugger we are about to remove some loaded objects.  */
   _r_debug.r_state = RT_DELETE;
   _dl_debug_state ();
-  ++GL(dl_load_subs);
 
 #ifdef USE_TLS
   size_t tls_free_start;
Index: elf/dl-iteratephdr.c
===================================================================
RCS file: /cvs/glibc/libc/elf/dl-iteratephdr.c,v
retrieving revision 1.10
diff -u -r1.10 dl-iteratephdr.c
--- elf/dl-iteratephdr.c	24 Jan 2004 20:07:51 -0000	1.10
+++ elf/dl-iteratephdr.c	26 Jan 2004 21:42:35 -0000
@@ -49,7 +49,7 @@
       info.dlpi_phdr = l->l_phdr;
       info.dlpi_phnum = l->l_phnum;
       info.dlpi_adds = GL(dl_load_adds);
-      info.dlpi_subs = GL(dl_load_subs);
+      info.dlpi_subs = GL(dl_load_adds) - GL(dl_nloaded);
       ret = callback (&info, sizeof (struct dl_phdr_info), data);
       if (ret)
 	break;
@@ -87,7 +87,7 @@
       info.dlpi_phdr = _dl_phdr;
       info.dlpi_phnum = _dl_phnum;
       info.dlpi_adds = GL(dl_load_adds);
-      info.dlpi_subs = GL(dl_load_subs);
+      info.dlpi_subs = GL(dl_load_adds) - GL(dl_nloaded);
       ret = (*callback) (&info, sizeof (struct dl_phdr_info), data);
       if (ret)
 	return ret;
Index: elf/dl-support.c
===================================================================
RCS file: /cvs/glibc/libc/elf/dl-support.c,v
retrieving revision 1.80
diff -u -r1.80 dl-support.c
--- elf/dl-support.c	24 Jan 2004 20:08:29 -0000	1.80
+++ elf/dl-support.c	26 Jan 2004 21:42:35 -0000
@@ -73,8 +73,6 @@
 
 /* Incremented whenever something may have been added to dl_loaded. */
 unsigned long long _dl_load_adds;
-/* Incremented whenever something may have been removed from dl_loaded. */
-unsigned long long _dl_load_subs;
 
 /* Fake scope.  In dynamically linked binaries this is the scope of the
    main application but here we don't have something like this.  So
Index: elf/link.h
===================================================================
RCS file: /cvs/glibc/libc/elf/link.h,v
retrieving revision 1.77
diff -u -r1.77 link.h
--- elf/link.h	24 Jan 2004 20:08:50 -0000	1.77
+++ elf/link.h	26 Jan 2004 21:42:35 -0000
@@ -103,7 +103,7 @@
 
     /* Note: the next two members were introduced after the first
        version of this structure was available.  Check the SIZE
-       argument pass to the dl_iterate_phdr() callback to determine
+       argument passed to the dl_iterate_phdr() callback to determine
        whether or not they are provided.  */
 
     /* Incremented when a new object may have been added.  */
Index: elf/rtld.c
===================================================================
RCS file: /cvs/glibc/libc/elf/rtld.c,v
retrieving revision 1.310
diff -u -r1.310 rtld.c
--- elf/rtld.c	24 Jan 2004 08:33:44 -0000	1.310
+++ elf/rtld.c	26 Jan 2004 21:42:35 -0000
@@ -1020,6 +1020,7 @@
   GL(dl_loaded)->l_next = &GL(dl_rtld_map);
   GL(dl_rtld_map).l_prev = GL(dl_loaded);
   ++GL(dl_nloaded);
+  ++GL(dl_load_adds);
 
   /* If LD_USE_LOAD_BIAS env variable has not been seen, default
      to not using bias for non-prelinked PIEs and libraries
Index: sysdeps/generic/ldsodefs.h
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/generic/ldsodefs.h,v
retrieving revision 1.89
diff -u -r1.89 ldsodefs.h
--- sysdeps/generic/ldsodefs.h	24 Jan 2004 20:10:18 -0000	1.89
+++ sysdeps/generic/ldsodefs.h	26 Jan 2004 21:42:36 -0000
@@ -267,8 +267,6 @@
 
   /* Incremented whenever something may have been added to dl_loaded.  */
   EXTERN unsigned long long _dl_load_adds;
-  /* Incremented whenever something may have been removed from dl_loaded.  */
-  EXTERN unsigned long long _dl_load_subs;
 
 #ifndef MAP_ANON
   /* File descriptor referring to the zero-fill device.  */


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