Subject: Re: why ld.elf_so is slow starting mozilla
To: David Laight <david@l8s.co.uk>
From: Charles M. Hannum <abuse@spamalicious.com>
List: tech-toolchain
Date: 10/03/2002 00:49:55
So I tried the following experimental patch.  It reduced the number of
comparisons for one example looks of dlsym() from 610 to 61 (literally
a 10x reduction) for me.  I guess it also makes ld.elf_so use a little
less memory.

I *think* that this is always safe -- _rtld_list_main is always
searched first, and the objects cannot be unloaded...


Index: rtld.c
===================================================================
RCS file: /cvsroot/basesrc/libexec/ld.elf_so/rtld.c,v
retrieving revision 1.82
diff -u -r1.82 rtld.c
--- rtld.c	2002/09/26 22:26:26	1.82
+++ rtld.c	2002/10/03 00:53:02
@@ -405,8 +405,10 @@
 	if (_rtld_load_needed_objects(_rtld_objmain, RTLD_GLOBAL) == -1)
 		_rtld_die();
 
-	for (obj = _rtld_objlist;  obj != NULL;  obj = obj->next)
+	for (obj = _rtld_objlist; obj != NULL; obj = obj->next) {
+		obj->main = 1;
 		_rtld_objlist_add(&_rtld_list_main, obj);
+	}
 
 	dbg(("relocating objects"));
 	if (_rtld_relocate_objects(_rtld_objmain, bind_now) == -1)
@@ -498,7 +500,8 @@
 	const Needed_Entry *needed;
 
 	_rtld_objlist_add(&obj->dldags, root);
-	_rtld_objlist_add(&root->dagmembers, obj);
+	if (!obj->main)
+		_rtld_objlist_add(&root->dagmembers, obj);
 	for (needed = obj->needed; needed != NULL; needed = needed->next)
 		if (needed->obj != NULL)
 			_rtld_init_dag1(root, needed->obj);
Index: rtld.h
===================================================================
RCS file: /cvsroot/basesrc/libexec/ld.elf_so/rtld.h,v
retrieving revision 1.60
diff -u -r1.60 rtld.h
--- rtld.h	2002/09/26 20:42:10	1.60
+++ rtld.h	2002/10/03 00:53:02
@@ -182,7 +182,8 @@
 			symbolic:1,	/* True if generated with
 					 * "-Bsymbolic" */
 			printed:1,	/* True if ldd has printed it */
-			isdynamic:1;	/* True if this is a pure PIC object */
+			isdynamic:1,	/* True if this is a pure PIC object */
+			main:1;		/* True if on _rtld_list_main */
 
 	struct link_map linkmap;	/* for GDB */
 
Index: symbol.c
===================================================================
RCS file: /cvsroot/basesrc/libexec/ld.elf_so/symbol.c,v
retrieving revision 1.22
diff -u -r1.22 symbol.c
--- symbol.c	2002/09/24 20:27:07	1.22
+++ symbol.c	2002/10/03 00:53:02
@@ -127,6 +127,7 @@
 		assert(symnum < obj->nchains);
 		symp = obj->symtab + symnum;
 		strp = obj->strtab + symp->st_name;
+		rdbg(("check %s vs %s in %p", name, strp, obj));
 		if (name[1] == strp[1] && !strcmp(name, strp)) {
 			if (symp->st_shndx != SHN_UNDEF)
 				return symp;