OSDN Git Service

Seperate out the symbol resolution debugging, so it doesn't clutter
authorEric Andersen <andersen@codepoet.org>
Fri, 8 Mar 2002 09:40:52 +0000 (09:40 -0000)
committerEric Andersen <andersen@codepoet.org>
Fri, 8 Mar 2002 09:40:52 +0000 (09:40 -0000)
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

ldso/ldso/Makefile
ldso/ldso/arm/elfinterp.c
ldso/ldso/dl-elf.c
ldso/ldso/i386/elfinterp.c
ldso/ldso/ldso.c
ldso/ldso/m68k/elfinterp.c
ldso/ldso/powerpc/elfinterp.c
ldso/ldso/readelflib1.c
ldso/ldso/sparc/elfinterp.c

index 06cdbbe..55d3f00 100644 (file)
@@ -29,6 +29,7 @@ LDSO_FULLNAME=ld-uClibc-$(MAJOR_VERSION).$(MINOR_VERSION).so
 
 # Enable this to enable debugging output from ld.so
 #XXFLAGS+= -DDL_DEBUG
+#XXFLAGS+= -DDL_DEBUG_SYMBOLS
 
 XXFLAGS+=-DUCLIBC_TARGET_PREFIX=\"$(TARGET_PREFIX)\" \
        -DUCLIBC_DEVEL_PREFIX=\"$(DEVEL_PREFIX)\" \
index de9d50b..aac7ecc 100644 (file)
@@ -82,7 +82,7 @@ unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry)
                        (unsigned long) tpnt->loadaddr);
        got_addr = (char **) instr_addr;
 
-#ifdef DL_DEBUG
+#ifdef DL_DEBUG_SYMBOLS
        _dl_dprintf(2, "Resolving symbol %s\n", 
                strtab + symtab[symtab_index].st_name);
 #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_exit(1);
        };
-#ifdef DL_DEBUG
+#ifdef DL_DEBUG_SYMBOLS
        if ((unsigned long) got_addr < 0x40000000) {
                _dl_dprintf(2, "Calling library function: %s\n", 
                        strtab + symtab[symtab_index].st_name);
index 35de7a1..ba01504 100644 (file)
@@ -110,7 +110,7 @@ int _dl_unmap_cache(void)
 static struct elf_resolve * 
 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 mylibname[2050];
        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_internal_error_number;
+extern char *_dl_ldsopath;
 
 struct elf_resolve *_dl_load_shared_library(int secure, 
        struct elf_resolve *tpnt, char *full_libname)
 {
-       char *pnt;
+       char *pnt, *pnt1;
        struct elf_resolve *tpnt1;
        char *libname;
 
@@ -176,6 +177,9 @@ struct elf_resolve *_dl_load_shared_library(int secure,
                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.
           For IBCS2 compatibility under linux, we substitute the string 
           /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) {
                                pnt += (unsigned long) tpnt->loadaddr +
                                        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) 
                                {
                                    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 */
        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) 
            {
                return tpnt1;
@@ -236,8 +246,22 @@ struct elf_resolve *_dl_load_shared_library(int secure,
        }
 #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.
           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, 
                        UCLIBC_TARGET_PREFIX "/usr/lib:"
                        UCLIBC_TARGET_PREFIX "/lib:"
@@ -250,12 +274,15 @@ struct elf_resolve *_dl_load_shared_library(int secure,
            return tpnt1;
        }
 
-  goof:
+goof:
        /* Well, we shot our wad on that one.  All we can do now is punt */
        if (_dl_internal_error_number)
                _dl_error_number = _dl_internal_error_number;
        else
                _dl_error_number = DL_ERROR_NOFILE;
+#ifdef DL_DEBUG
+           _dl_dprintf(2, "Bummer: could not find '%s'!\n", libname);
+#endif
        return NULL;
 }
 
index 8cd1eb2..be19327 100644 (file)
@@ -74,7 +74,7 @@ unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry)
                (unsigned long) tpnt->loadaddr);
        got_addr = (char **) instr_addr;
 
-#ifdef DL_DEBUG
+#ifdef DL_DEBUG_SYMBOLS
        _dl_dprintf(2, "Resolving symbol %s\n", 
                strtab + symtab[symtab_index].st_name);
 #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_exit(1);
        };
-#ifdef DL_DEBUG
+#ifdef DL_DEBUG_SYMBOLS
        if ((unsigned long) got_addr < 0x40000000) {
                _dl_dprintf(2, "Calling library function: %s\n", 
                        strtab + symtab[symtab_index].st_name);
index 6a3f19c..36580e2 100644 (file)
  */
 #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_preload = 0;                 /* Things to be loaded before the libs. */
+char *_dl_ldsopath = 0;
 static char *_dl_not_lazy = 0;
+static char *_dl_malloc_addr, *_dl_mmap_zero;
 
 #ifdef DL_TRACE
 static char *_dl_trace_loaded_objects = 0;
@@ -509,7 +510,7 @@ DL_BOOT(unsigned long args)
                                        SEND_STDERR(" undefined.\n");
                                        goof++;
                                }
-#ifdef DL_DEBUG
+#ifdef DL_DEBUG_SYMBOLS
                                SEND_STDERR("About to fixup symbol: ");
                                SEND_STDERR(strtab + symtab[symtab_index].st_name);
                                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));
                }
        }
+       /* 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
        _dl_dprintf(2, "Lib Loader:\t(%x) %s\n", tpnt->loadaddr, tpnt->libname);
 #endif
index 167ce41..0fa8da8 100644 (file)
@@ -83,7 +83,7 @@ unsigned int _dl_linux_resolver (int dummy1, int dummy2,
   instr_addr = (int) this_reloc->r_offset + (int) tpnt->loadaddr;
   got_addr = (char **) instr_addr;
 
-#ifdef DL_DEBUG
+#ifdef DL_DEBUG_SYMBOLS
   _dl_dprintf (2, "Resolving symbol %s\n",
                strtab + symtab[symtab_index].st_name);
 #endif
@@ -97,8 +97,7 @@ unsigned int _dl_linux_resolver (int dummy1, int dummy2,
                    _dl_progname, strtab + symtab[symtab_index].st_name);
       _dl_exit (1);
     }
-/* #define DL_DEBUG */
-#ifdef DL_DEBUG
+#ifdef DL_DEBUG_SYMBOLS
   if ((unsigned int) got_addr < 0x40000000)
     _dl_dprintf (2, "Calling library function: %s\n",
                  strtab + symtab[symtab_index].st_name);
index 1935960..aed640e 100644 (file)
@@ -49,7 +49,7 @@ static char *_dl_reltypes[] =
    working. */
 
 
-#ifdef DL_DEBUG
+#ifdef DL_DEBUG_SYMBOLS
 static void debug_sym(Elf32_Sym *symtab,char *strtab,int symtab_index);
 static void debug_reloc(ELF_RELOC *rpnt);
 #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
 
 
-#ifdef DL_DEBUG
+#ifdef DL_DEBUG_SYMBOLS
 static void debug_sym(Elf32_Sym *symtab,char *strtab,int symtab_index)
 {
        if(symtab_index){
index 35de7a1..ba01504 100644 (file)
@@ -110,7 +110,7 @@ int _dl_unmap_cache(void)
 static struct elf_resolve * 
 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 mylibname[2050];
        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_internal_error_number;
+extern char *_dl_ldsopath;
 
 struct elf_resolve *_dl_load_shared_library(int secure, 
        struct elf_resolve *tpnt, char *full_libname)
 {
-       char *pnt;
+       char *pnt, *pnt1;
        struct elf_resolve *tpnt1;
        char *libname;
 
@@ -176,6 +177,9 @@ struct elf_resolve *_dl_load_shared_library(int secure,
                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.
           For IBCS2 compatibility under linux, we substitute the string 
           /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) {
                                pnt += (unsigned long) tpnt->loadaddr +
                                        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) 
                                {
                                    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 */
        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) 
            {
                return tpnt1;
@@ -236,8 +246,22 @@ struct elf_resolve *_dl_load_shared_library(int secure,
        }
 #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.
           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, 
                        UCLIBC_TARGET_PREFIX "/usr/lib:"
                        UCLIBC_TARGET_PREFIX "/lib:"
@@ -250,12 +274,15 @@ struct elf_resolve *_dl_load_shared_library(int secure,
            return tpnt1;
        }
 
-  goof:
+goof:
        /* Well, we shot our wad on that one.  All we can do now is punt */
        if (_dl_internal_error_number)
                _dl_error_number = _dl_internal_error_number;
        else
                _dl_error_number = DL_ERROR_NOFILE;
+#ifdef DL_DEBUG
+           _dl_dprintf(2, "Bummer: could not find '%s'!\n", libname);
+#endif
        return NULL;
 }
 
index 46754d6..3ccdcb4 100644 (file)
@@ -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);
 
-#ifdef DL_DEBUG
+#ifdef DL_DEBUG_SYMBOLS
   _dl_dprintf(2, "Resolving symbol %s\n",
        strtab + symtab[symtab_index].st_name);
 #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_exit(31);
   };
-/* #define DL_DEBUG */
-#ifdef DL_DEBUG
+#ifdef DL_DEBUG_SYMBOLS
   if((unsigned int) got_addr < 0x40000000) {
     _dl_dprintf(2, "Calling library function: %s\n",
               strtab + symtab[symtab_index].st_name);