[uClibc-cvs] uClibc/ldso/ldso ldso.c, 1.70, 1.71 readelflib1.c, 1.43, 1.44

Erik Andersen andersen at uclibc.org
Sun Aug 31 06:51:57 UTC 2003


Update of /var/cvs/uClibc/ldso/ldso
In directory winder:/tmp/cvs-serv22708/ldso

Modified Files:
	ldso.c readelflib1.c 
Log Message:
Weed out duplicates before trying to load libraries....  Delayed
checking for duplicates and returning an alias if an existing lib
is already loaded is still correct for the dlopen case.


Index: readelflib1.c
===================================================================
RCS file: /var/cvs/uClibc/ldso/ldso/readelflib1.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- readelflib1.c	19 Aug 2003 13:11:06 -0000	1.43
+++ readelflib1.c	31 Aug 2003 06:51:54 -0000	1.44
@@ -166,29 +166,19 @@
 	return NULL;
 }
 
-
-/*
- * Used to return error codes back to dlopen et. al.
- */
-
-unsigned long _dl_error_number;
-unsigned long _dl_internal_error_number;
-extern char *_dl_ldsopath;
-
-struct elf_resolve *_dl_load_shared_library(int secure, struct dyn_elf **rpnt,
-	struct elf_resolve *tpnt, char *full_libname)
+/* Check if the named library is already loaded... */
+struct elf_resolve *_dl_check_if_named_library_is_loaded(const char *full_libname)
 {
-	char *pnt, *pnt1;
+	const char *pnt, *pnt1;
 	struct elf_resolve *tpnt1;
-	char *libname, *libname2;
+	const char *libname, *libname2;
 
-	_dl_internal_error_number = 0;
 	pnt = libname = full_libname;
 
 	/* quick hack to ensure mylibname buffer doesn't overflow.  don't 
 	   allow full_libname or any directory to be longer than 1024. */
 	if (_dl_strlen(full_libname) > 1024)
-		goto goof;
+		return NULL;
 
 	/* Skip over any initial initial './' and '/' stuff to 
 	 * get the short form libname with no path garbage */ 
@@ -215,8 +205,47 @@
 			return tpnt1;
 		}
 	}
+	return NULL;
+}
 	
 
+
+/*
+ * Used to return error codes back to dlopen et. al.
+ */
+
+unsigned long _dl_error_number;
+unsigned long _dl_internal_error_number;
+extern char *_dl_ldsopath;
+
+struct elf_resolve *_dl_load_shared_library(int secure, struct dyn_elf **rpnt,
+	struct elf_resolve *tpnt, char *full_libname)
+{
+	char *pnt, *pnt1;
+	struct elf_resolve *tpnt1;
+	char *libname;
+
+	_dl_internal_error_number = 0;
+	libname = full_libname;
+
+	/* quick hack to ensure mylibname buffer doesn't overflow.  don't 
+	   allow full_libname or any directory to be longer than 1024. */
+	if (_dl_strlen(full_libname) > 1024)
+		goto goof;
+
+	/* Skip over any initial initial './' and '/' stuff to 
+	 * get the short form libname with no path garbage */ 
+	pnt1 = _dl_strrchr(libname, '/');
+	if (pnt1) {
+		libname = pnt1 + 1;
+	}
+
+	/* Critical step!  Weed out duplicates early to avoid
+	 * function aliasing, which wastes memory, and causes
+	 * really bad things to happen with weaks and globals. */
+	if ((tpnt1=_dl_check_if_named_library_is_loaded(libname))!=NULL)
+		return tpnt1;
+
 #if defined (__SUPPORT_LD_DEBUG__)
 	if(_dl_debug) _dl_dprintf(_dl_debug_file, "searching for library: '%s'\n", libname);
 #endif

Index: ldso.c
===================================================================
RCS file: /var/cvs/uClibc/ldso/ldso/ldso.c,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -d -r1.70 -r1.71
--- ldso.c	22 Aug 2003 02:56:46 -0000	1.70
+++ ldso.c	31 Aug 2003 06:51:53 -0000	1.71
@@ -902,6 +902,10 @@
 			*str2 = '\0';
 			if (!_dl_secure || _dl_strchr(str, '/') == NULL) 
 			{
+				if ((tpnt1 = _dl_check_if_named_library_is_loaded(str))) 
+				{
+					continue;
+				}
 				tpnt1 = _dl_load_shared_library(_dl_secure, &rpnt, NULL, str);
 				if (!tpnt1) {
 #ifdef __LDSO_LDD_SUPPORT__
@@ -978,6 +982,10 @@
 						c = *cp;
 						*cp = '\0';
 
+						if ((tpnt1 = _dl_check_if_named_library_is_loaded(cp2))) 
+						{
+							continue;
+						}
 						tpnt1 = _dl_load_shared_library(0, &rpnt, NULL, cp2);
 						if (!tpnt1) {
 #ifdef __LDSO_LDD_SUPPORT__
@@ -1068,6 +1076,10 @@
 					tpnt = NULL;
 					continue;
 				}
+				if ((tpnt1 = _dl_check_if_named_library_is_loaded(lpntstr))) 
+				{
+					continue;
+				}
 				if (!(tpnt1 = _dl_load_shared_library(0, &rpnt, tcurr, lpntstr)))
 				{
 #ifdef __LDSO_LDD_SUPPORT__




More information about the uClibc-cvs mailing list