Browse Source

Seperate out the symbol resolution debugging, so it doesn't clutter
things up when we don't care about symbol resolution problems. Make
the lib loader always look first in the directory where the shared lib
loader was found.
-Erik

Eric Andersen 23 years ago
parent
commit
ff1b55eb5e

+ 1 - 0
ldso/ldso/Makefile

@@ -29,6 +29,7 @@ LDSO_FULLNAME=ld-uClibc-$(MAJOR_VERSION).$(MINOR_VERSION).so
 
 
 # Enable this to enable debugging output from ld.so
 # Enable this to enable debugging output from ld.so
 #XXFLAGS+= -DDL_DEBUG
 #XXFLAGS+= -DDL_DEBUG
+#XXFLAGS+= -DDL_DEBUG_SYMBOLS
 
 
 XXFLAGS+=-DUCLIBC_TARGET_PREFIX=\"$(TARGET_PREFIX)\" \
 XXFLAGS+=-DUCLIBC_TARGET_PREFIX=\"$(TARGET_PREFIX)\" \
 	-DUCLIBC_DEVEL_PREFIX=\"$(DEVEL_PREFIX)\" \
 	-DUCLIBC_DEVEL_PREFIX=\"$(DEVEL_PREFIX)\" \

+ 2 - 2
ldso/ldso/arm/elfinterp.c

@@ -82,7 +82,7 @@ unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry)
 			(unsigned long) tpnt->loadaddr);
 			(unsigned long) tpnt->loadaddr);
 	got_addr = (char **) instr_addr;
 	got_addr = (char **) instr_addr;
 
 
-#ifdef DL_DEBUG
+#ifdef DL_DEBUG_SYMBOLS
 	_dl_dprintf(2, "Resolving symbol %s\n", 
 	_dl_dprintf(2, "Resolving symbol %s\n", 
 		strtab + symtab[symtab_index].st_name);
 		strtab + symtab[symtab_index].st_name);
 #endif
 #endif
@@ -95,7 +95,7 @@ unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry)
 			_dl_progname, strtab + symtab[symtab_index].st_name);
 			_dl_progname, strtab + symtab[symtab_index].st_name);
 		_dl_exit(1);
 		_dl_exit(1);
 	};
 	};
-#ifdef DL_DEBUG
+#ifdef DL_DEBUG_SYMBOLS
 	if ((unsigned long) got_addr < 0x40000000) {
 	if ((unsigned long) got_addr < 0x40000000) {
 		_dl_dprintf(2, "Calling library function: %s\n", 
 		_dl_dprintf(2, "Calling library function: %s\n", 
 			strtab + symtab[symtab_index].st_name);
 			strtab + symtab[symtab_index].st_name);

+ 30 - 3
ldso/ldso/dl-elf.c

@@ -110,7 +110,7 @@ int _dl_unmap_cache(void)
 static struct elf_resolve * 
 static struct elf_resolve * 
 search_for_named_library(char *name, int secure, const char *path_list)
 search_for_named_library(char *name, int secure, const char *path_list)
 {
 {
-	int i, count = 0;
+	int i, count = 1;
 	char *path, *path_n;
 	char *path, *path_n;
 	char mylibname[2050];
 	char mylibname[2050];
 	struct elf_resolve *tpnt1;
 	struct elf_resolve *tpnt1;
@@ -154,11 +154,12 @@ search_for_named_library(char *name, int secure, const char *path_list)
 
 
 unsigned long _dl_error_number;
 unsigned long _dl_error_number;
 unsigned long _dl_internal_error_number;
 unsigned long _dl_internal_error_number;
+extern char *_dl_ldsopath;
 
 
 struct elf_resolve *_dl_load_shared_library(int secure, 
 struct elf_resolve *_dl_load_shared_library(int secure, 
 	struct elf_resolve *tpnt, char *full_libname)
 	struct elf_resolve *tpnt, char *full_libname)
 {
 {
-	char *pnt;
+	char *pnt, *pnt1;
 	struct elf_resolve *tpnt1;
 	struct elf_resolve *tpnt1;
 	char *libname;
 	char *libname;
 
 
@@ -176,6 +177,9 @@ struct elf_resolve *_dl_load_shared_library(int secure,
 		pnt++;
 		pnt++;
 	}
 	}
 
 
+#ifdef DL_DEBUG
+	    _dl_dprintf(2, "searching for library: '%s'\n", libname);
+#endif
 	/* If the filename has any '/', try it straight and leave it at that.
 	/* If the filename has any '/', try it straight and leave it at that.
 	   For IBCS2 compatibility under linux, we substitute the string 
 	   For IBCS2 compatibility under linux, we substitute the string 
 	   /usr/i486-sysv4/lib for /usr/lib in library names. */
 	   /usr/i486-sysv4/lib for /usr/lib in library names. */
@@ -197,6 +201,9 @@ struct elf_resolve *_dl_load_shared_library(int secure,
 			if (pnt) {
 			if (pnt) {
 				pnt += (unsigned long) tpnt->loadaddr +
 				pnt += (unsigned long) tpnt->loadaddr +
 					tpnt->dynamic_info[DT_STRTAB];
 					tpnt->dynamic_info[DT_STRTAB];
+#ifdef DL_DEBUG
+				_dl_dprintf(2, "searching RPATH: '%s'\n", pnt);
+#endif
 				if ((tpnt1 = search_for_named_library(libname, secure, pnt)) != NULL) 
 				if ((tpnt1 = search_for_named_library(libname, secure, pnt)) != NULL) 
 				{
 				{
 				    return tpnt1;
 				    return tpnt1;
@@ -207,6 +214,9 @@ struct elf_resolve *_dl_load_shared_library(int secure,
 
 
 	/* Check in LD_{ELF_}LIBRARY_PATH, if specified and allowed */
 	/* Check in LD_{ELF_}LIBRARY_PATH, if specified and allowed */
 	if (_dl_library_path) {
 	if (_dl_library_path) {
+#ifdef DL_DEBUG
+	    _dl_dprintf(2, "searching _dl_library_path: '%s'\n", _dl_library_path);
+#endif
 	    if ((tpnt1 = search_for_named_library(libname, secure, _dl_library_path)) != NULL) 
 	    if ((tpnt1 = search_for_named_library(libname, secure, _dl_library_path)) != NULL) 
 	    {
 	    {
 		return tpnt1;
 		return tpnt1;
@@ -236,8 +246,22 @@ struct elf_resolve *_dl_load_shared_library(int secure,
 	}
 	}
 #endif
 #endif
 
 
+	/* Look for libraries wherever the shared library loader
+	 * was installed */
+#ifdef DL_DEBUG
+	_dl_dprintf(2, "searching in ldso dir: %s\n", _dl_ldsopath);
+#endif
+	if ((tpnt1 = search_for_named_library(libname, secure, _dl_ldsopath)) != NULL) 
+	{
+	    return tpnt1;
+	}
+
+
 	/* Lastly, search the standard list of paths for the library.
 	/* Lastly, search the standard list of paths for the library.
 	   This list must exactly match the list in uClibc/ldso/util/ldd.c */
 	   This list must exactly match the list in uClibc/ldso/util/ldd.c */
+#ifdef DL_DEBUG
+	    _dl_dprintf(2, "searching full lib path list\n");
+#endif
 	if ((tpnt1 = search_for_named_library(libname, secure, 
 	if ((tpnt1 = search_for_named_library(libname, secure, 
 			UCLIBC_TARGET_PREFIX "/usr/lib:"
 			UCLIBC_TARGET_PREFIX "/usr/lib:"
 			UCLIBC_TARGET_PREFIX "/lib:"
 			UCLIBC_TARGET_PREFIX "/lib:"
@@ -250,12 +274,15 @@ struct elf_resolve *_dl_load_shared_library(int secure,
 	    return tpnt1;
 	    return tpnt1;
 	}
 	}
 
 
-  goof:
+goof:
 	/* Well, we shot our wad on that one.  All we can do now is punt */
 	/* Well, we shot our wad on that one.  All we can do now is punt */
 	if (_dl_internal_error_number)
 	if (_dl_internal_error_number)
 		_dl_error_number = _dl_internal_error_number;
 		_dl_error_number = _dl_internal_error_number;
 	else
 	else
 		_dl_error_number = DL_ERROR_NOFILE;
 		_dl_error_number = DL_ERROR_NOFILE;
+#ifdef DL_DEBUG
+	    _dl_dprintf(2, "Bummer: could not find '%s'!\n", libname);
+#endif
 	return NULL;
 	return NULL;
 }
 }
 
 

+ 2 - 2
ldso/ldso/i386/elfinterp.c

@@ -74,7 +74,7 @@ unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry)
 		(unsigned long) tpnt->loadaddr);
 		(unsigned long) tpnt->loadaddr);
 	got_addr = (char **) instr_addr;
 	got_addr = (char **) instr_addr;
 
 
-#ifdef DL_DEBUG
+#ifdef DL_DEBUG_SYMBOLS
 	_dl_dprintf(2, "Resolving symbol %s\n", 
 	_dl_dprintf(2, "Resolving symbol %s\n", 
 		strtab + symtab[symtab_index].st_name);
 		strtab + symtab[symtab_index].st_name);
 #endif
 #endif
@@ -87,7 +87,7 @@ unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry)
 			_dl_progname, strtab + symtab[symtab_index].st_name);
 			_dl_progname, strtab + symtab[symtab_index].st_name);
 		_dl_exit(1);
 		_dl_exit(1);
 	};
 	};
-#ifdef DL_DEBUG
+#ifdef DL_DEBUG_SYMBOLS
 	if ((unsigned long) got_addr < 0x40000000) {
 	if ((unsigned long) got_addr < 0x40000000) {
 		_dl_dprintf(2, "Calling library function: %s\n", 
 		_dl_dprintf(2, "Calling library function: %s\n", 
 			strtab + symtab[symtab_index].st_name);
 			strtab + symtab[symtab_index].st_name);

+ 15 - 2
ldso/ldso/ldso.c

@@ -139,10 +139,11 @@
  */
  */
 #define REALIGN() malloc_buffer = (char *) (((unsigned long) malloc_buffer + 3) & ~(3))
 #define REALIGN() malloc_buffer = (char *) (((unsigned long) malloc_buffer + 3) & ~(3))
 
 
-static char *_dl_malloc_addr, *_dl_mmap_zero;
 char *_dl_library_path = 0;		/* Where we look for libraries */
 char *_dl_library_path = 0;		/* Where we look for libraries */
 char *_dl_preload = 0;			/* Things to be loaded before the libs. */
 char *_dl_preload = 0;			/* Things to be loaded before the libs. */
+char *_dl_ldsopath = 0;
 static char *_dl_not_lazy = 0;
 static char *_dl_not_lazy = 0;
+static char *_dl_malloc_addr, *_dl_mmap_zero;
 
 
 #ifdef DL_TRACE
 #ifdef DL_TRACE
 static char *_dl_trace_loaded_objects = 0;
 static char *_dl_trace_loaded_objects = 0;
@@ -509,7 +510,7 @@ DL_BOOT(unsigned long args)
 					SEND_STDERR(" undefined.\n");
 					SEND_STDERR(" undefined.\n");
 					goof++;
 					goof++;
 				}
 				}
-#ifdef DL_DEBUG
+#ifdef DL_DEBUG_SYMBOLS
 				SEND_STDERR("About to fixup symbol: ");
 				SEND_STDERR("About to fixup symbol: ");
 				SEND_STDERR(strtab + symtab[symtab_index].st_name);
 				SEND_STDERR(strtab + symtab[symtab_index].st_name);
 				SEND_STDERR("\n");
 				SEND_STDERR("\n");
@@ -661,6 +662,18 @@ static void _dl_get_ready_to_run(struct elf_resolve *tpnt, struct elf_resolve *a
 					(auxvt[AT_PHDR].a_un.a_val & 0xfffff000));
 					(auxvt[AT_PHDR].a_un.a_val & 0xfffff000));
 		}
 		}
 	}
 	}
+	/* Store the path where the shared lib loader was found for 
+	 * later use */
+	{
+		char *pnt, *pnt1;
+		pnt = _dl_strdup(tpnt->libname);
+		pnt1 = _dl_strrchr(pnt, '/');
+		if (pnt != pnt1) {
+			*pnt1 = '\0';
+			_dl_ldsopath = pnt;
+		}
+	}
+
 #ifdef DL_DEBUG
 #ifdef DL_DEBUG
 	_dl_dprintf(2, "Lib Loader:\t(%x) %s\n", tpnt->loadaddr, tpnt->libname);
 	_dl_dprintf(2, "Lib Loader:\t(%x) %s\n", tpnt->loadaddr, tpnt->libname);
 #endif
 #endif

+ 2 - 3
ldso/ldso/m68k/elfinterp.c

@@ -83,7 +83,7 @@ unsigned int _dl_linux_resolver (int dummy1, int dummy2,
   instr_addr = (int) this_reloc->r_offset + (int) tpnt->loadaddr;
   instr_addr = (int) this_reloc->r_offset + (int) tpnt->loadaddr;
   got_addr = (char **) instr_addr;
   got_addr = (char **) instr_addr;
 
 
-#ifdef DL_DEBUG
+#ifdef DL_DEBUG_SYMBOLS
   _dl_dprintf (2, "Resolving symbol %s\n",
   _dl_dprintf (2, "Resolving symbol %s\n",
 		strtab + symtab[symtab_index].st_name);
 		strtab + symtab[symtab_index].st_name);
 #endif
 #endif
@@ -97,8 +97,7 @@ unsigned int _dl_linux_resolver (int dummy1, int dummy2,
 		    _dl_progname, strtab + symtab[symtab_index].st_name);
 		    _dl_progname, strtab + symtab[symtab_index].st_name);
       _dl_exit (1);
       _dl_exit (1);
     }
     }
-/* #define DL_DEBUG */
+#ifdef DL_DEBUG_SYMBOLS
-#ifdef DL_DEBUG
   if ((unsigned int) got_addr < 0x40000000)
   if ((unsigned int) got_addr < 0x40000000)
     _dl_dprintf (2, "Calling library function: %s\n",
     _dl_dprintf (2, "Calling library function: %s\n",
 		  strtab + symtab[symtab_index].st_name);
 		  strtab + symtab[symtab_index].st_name);

+ 2 - 2
ldso/ldso/powerpc/elfinterp.c

@@ -49,7 +49,7 @@ static char *_dl_reltypes[] =
    working. */
    working. */
 
 
 
 
-#ifdef DL_DEBUG
+#ifdef DL_DEBUG_SYMBOLS
 static void debug_sym(Elf32_Sym *symtab,char *strtab,int symtab_index);
 static void debug_sym(Elf32_Sym *symtab,char *strtab,int symtab_index);
 static void debug_reloc(ELF_RELOC *rpnt);
 static void debug_reloc(ELF_RELOC *rpnt);
 #define DPRINTF(fmt,args...) _dl_dprintf(2,fmt,args)
 #define DPRINTF(fmt,args...) _dl_dprintf(2,fmt,args)
@@ -547,7 +547,7 @@ static void fixup_jmpslot(unsigned long reloc_addr, unsigned long targ_addr)
 #endif
 #endif
 
 
 
 
-#ifdef DL_DEBUG
+#ifdef DL_DEBUG_SYMBOLS
 static void debug_sym(Elf32_Sym *symtab,char *strtab,int symtab_index)
 static void debug_sym(Elf32_Sym *symtab,char *strtab,int symtab_index)
 {
 {
 	if(symtab_index){
 	if(symtab_index){

+ 30 - 3
ldso/ldso/readelflib1.c

@@ -110,7 +110,7 @@ int _dl_unmap_cache(void)
 static struct elf_resolve * 
 static struct elf_resolve * 
 search_for_named_library(char *name, int secure, const char *path_list)
 search_for_named_library(char *name, int secure, const char *path_list)
 {
 {
-	int i, count = 0;
+	int i, count = 1;
 	char *path, *path_n;
 	char *path, *path_n;
 	char mylibname[2050];
 	char mylibname[2050];
 	struct elf_resolve *tpnt1;
 	struct elf_resolve *tpnt1;
@@ -154,11 +154,12 @@ search_for_named_library(char *name, int secure, const char *path_list)
 
 
 unsigned long _dl_error_number;
 unsigned long _dl_error_number;
 unsigned long _dl_internal_error_number;
 unsigned long _dl_internal_error_number;
+extern char *_dl_ldsopath;
 
 
 struct elf_resolve *_dl_load_shared_library(int secure, 
 struct elf_resolve *_dl_load_shared_library(int secure, 
 	struct elf_resolve *tpnt, char *full_libname)
 	struct elf_resolve *tpnt, char *full_libname)
 {
 {
-	char *pnt;
+	char *pnt, *pnt1;
 	struct elf_resolve *tpnt1;
 	struct elf_resolve *tpnt1;
 	char *libname;
 	char *libname;
 
 
@@ -176,6 +177,9 @@ struct elf_resolve *_dl_load_shared_library(int secure,
 		pnt++;
 		pnt++;
 	}
 	}
 
 
+#ifdef DL_DEBUG
+	    _dl_dprintf(2, "searching for library: '%s'\n", libname);
+#endif
 	/* If the filename has any '/', try it straight and leave it at that.
 	/* If the filename has any '/', try it straight and leave it at that.
 	   For IBCS2 compatibility under linux, we substitute the string 
 	   For IBCS2 compatibility under linux, we substitute the string 
 	   /usr/i486-sysv4/lib for /usr/lib in library names. */
 	   /usr/i486-sysv4/lib for /usr/lib in library names. */
@@ -197,6 +201,9 @@ struct elf_resolve *_dl_load_shared_library(int secure,
 			if (pnt) {
 			if (pnt) {
 				pnt += (unsigned long) tpnt->loadaddr +
 				pnt += (unsigned long) tpnt->loadaddr +
 					tpnt->dynamic_info[DT_STRTAB];
 					tpnt->dynamic_info[DT_STRTAB];
+#ifdef DL_DEBUG
+				_dl_dprintf(2, "searching RPATH: '%s'\n", pnt);
+#endif
 				if ((tpnt1 = search_for_named_library(libname, secure, pnt)) != NULL) 
 				if ((tpnt1 = search_for_named_library(libname, secure, pnt)) != NULL) 
 				{
 				{
 				    return tpnt1;
 				    return tpnt1;
@@ -207,6 +214,9 @@ struct elf_resolve *_dl_load_shared_library(int secure,
 
 
 	/* Check in LD_{ELF_}LIBRARY_PATH, if specified and allowed */
 	/* Check in LD_{ELF_}LIBRARY_PATH, if specified and allowed */
 	if (_dl_library_path) {
 	if (_dl_library_path) {
+#ifdef DL_DEBUG
+	    _dl_dprintf(2, "searching _dl_library_path: '%s'\n", _dl_library_path);
+#endif
 	    if ((tpnt1 = search_for_named_library(libname, secure, _dl_library_path)) != NULL) 
 	    if ((tpnt1 = search_for_named_library(libname, secure, _dl_library_path)) != NULL) 
 	    {
 	    {
 		return tpnt1;
 		return tpnt1;
@@ -236,8 +246,22 @@ struct elf_resolve *_dl_load_shared_library(int secure,
 	}
 	}
 #endif
 #endif
 
 
+	/* Look for libraries wherever the shared library loader
+	 * was installed */
+#ifdef DL_DEBUG
+	_dl_dprintf(2, "searching in ldso dir: %s\n", _dl_ldsopath);
+#endif
+	if ((tpnt1 = search_for_named_library(libname, secure, _dl_ldsopath)) != NULL) 
+	{
+	    return tpnt1;
+	}
+
+
 	/* Lastly, search the standard list of paths for the library.
 	/* Lastly, search the standard list of paths for the library.
 	   This list must exactly match the list in uClibc/ldso/util/ldd.c */
 	   This list must exactly match the list in uClibc/ldso/util/ldd.c */
+#ifdef DL_DEBUG
+	    _dl_dprintf(2, "searching full lib path list\n");
+#endif
 	if ((tpnt1 = search_for_named_library(libname, secure, 
 	if ((tpnt1 = search_for_named_library(libname, secure, 
 			UCLIBC_TARGET_PREFIX "/usr/lib:"
 			UCLIBC_TARGET_PREFIX "/usr/lib:"
 			UCLIBC_TARGET_PREFIX "/lib:"
 			UCLIBC_TARGET_PREFIX "/lib:"
@@ -250,12 +274,15 @@ struct elf_resolve *_dl_load_shared_library(int secure,
 	    return tpnt1;
 	    return tpnt1;
 	}
 	}
 
 
-  goof:
+goof:
 	/* Well, we shot our wad on that one.  All we can do now is punt */
 	/* Well, we shot our wad on that one.  All we can do now is punt */
 	if (_dl_internal_error_number)
 	if (_dl_internal_error_number)
 		_dl_error_number = _dl_internal_error_number;
 		_dl_error_number = _dl_internal_error_number;
 	else
 	else
 		_dl_error_number = DL_ERROR_NOFILE;
 		_dl_error_number = DL_ERROR_NOFILE;
+#ifdef DL_DEBUG
+	    _dl_dprintf(2, "Bummer: could not find '%s'!\n", libname);
+#endif
 	return NULL;
 	return NULL;
 }
 }
 
 

+ 2 - 3
ldso/ldso/sparc/elfinterp.c

@@ -91,7 +91,7 @@ unsigned int _dl_linux_resolver(unsigned int reloc_entry, unsigned int * plt)
 
 
   _dl_dprintf(2, "symtab_index %d\n", symtab_index);
   _dl_dprintf(2, "symtab_index %d\n", symtab_index);
 
 
-#ifdef DL_DEBUG
+#ifdef DL_DEBUG_SYMBOLS
   _dl_dprintf(2, "Resolving symbol %s\n",
   _dl_dprintf(2, "Resolving symbol %s\n",
 	strtab + symtab[symtab_index].st_name);
 	strtab + symtab[symtab_index].st_name);
 #endif
 #endif
@@ -104,8 +104,7 @@ unsigned int _dl_linux_resolver(unsigned int reloc_entry, unsigned int * plt)
 	       _dl_progname, strtab + symtab[symtab_index].st_name);
 	       _dl_progname, strtab + symtab[symtab_index].st_name);
     _dl_exit(31);
     _dl_exit(31);
   };
   };
-/* #define DL_DEBUG */
+#ifdef DL_DEBUG_SYMBOLS
-#ifdef DL_DEBUG
   if((unsigned int) got_addr < 0x40000000) {
   if((unsigned int) got_addr < 0x40000000) {
     _dl_dprintf(2, "Calling library function: %s\n",
     _dl_dprintf(2, "Calling library function: %s\n",
 	       strtab + symtab[symtab_index].st_name);
 	       strtab + symtab[symtab_index].st_name);