Subject: ld.elf_so change for reducing syscalls and others
To: None <tech-userlevel@netbsd.org>
From: Bang Jun-Young <junyoung@mogua.com>
List: tech-userlevel
Date: 09/28/2002 15:17:34
Here is (hopefully) the final change to ld.elf_so I made today. With
this change, the number of failures to open(2) went down to 30 from
521 when loading mozilla. 

Comments?

Index: search.c
===================================================================
RCS file: /cvsroot/basesrc/libexec/ld.elf_so/search.c,v
retrieving revision 1.13
diff -u -r1.13 search.c
--- search.c	2002/09/24 12:52:20	1.13
+++ search.c	2002/09/28 06:07:42
@@ -55,6 +55,8 @@
 /*
  * Data declarations.
  */
+Search_Path    *_rtld_invalid_paths;
+
 static Obj_Entry *_rtld_search_library_path __P((const char *, size_t,
     const char *, size_t, int));
 
@@ -67,17 +69,36 @@
 	int mode;
 {
 	char *pathname;
+	size_t pathnamelen;
 	Obj_Entry *obj;
+	Search_Path *sp;
+
+	pathnamelen = dirlen + 1 + namelen;
 
-	pathname = xmalloc(dirlen + 1 + namelen + 1);
+	for (sp = _rtld_invalid_paths; sp != NULL; sp = sp->sp_next) {
+		if (sp->sp_pathlen == pathnamelen &&
+		    !strncmp(name, sp->sp_path + sp->sp_pathlen - namelen,
+		    namelen) && !strncmp(dir, sp->sp_path, dirlen)) {
+			return NULL;
+		}
+	}
+
+	pathname = xmalloc(pathnamelen + 1);
 	(void)strncpy(pathname, dir, dirlen);
 	pathname[dirlen] = '/';
 	strcpy(pathname + dirlen + 1, name);
 
 	dbg(("  Trying \"%s\"", pathname));
 	obj = _rtld_load_object(pathname, mode);
-	if (obj == NULL)
-		free(pathname);
+	if (obj == NULL) {
+		Search_Path *path;
+
+		path = NEW(Search_Path);
+		path->sp_pathlen = pathnamelen;
+		path->sp_path = pathname;
+		path->sp_next = _rtld_invalid_paths;
+		_rtld_invalid_paths = path;
+	}
 	return obj;
 }
 

-- 
Bang Jun-Young <junyoung@mogua.com>