OSDN Git Service

ldso: use _dl_strdup and _dl_dprintf only in ld-uClibc.so
authorPeter S. Mazinger <ps.m@gmx.net>
Wed, 30 Mar 2011 22:20:50 +0000 (00:20 +0200)
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Fri, 15 Jun 2012 12:00:35 +0000 (14:00 +0200)
Add support for %p to _dl_dprintf for later corrections in debug messages.
Disable _dl_debug_file if LD debugging is not enabled and change it's use to 2.

The use of dprintf in elfinterp.c will spit out warnings, will be fixed in the
reworked ldso.

Signed-off-by: Peter S. Mazinger <ps.m@gmx.net>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
ldso/include/ldso.h
ldso/ldso/arm/elfinterp.c
ldso/ldso/dl-elf.c
ldso/ldso/dl-tls.c
ldso/ldso/ldso.c
ldso/ldso/m68k/elfinterp.c
ldso/ldso/sparc/elfinterp.c

index fc356b0..f5bb6e0 100644 (file)
@@ -113,7 +113,8 @@ extern int   _dl_debug_file;
 #else
 # define __dl_debug_dprint(fmt, args...) do {} while (0)
 # define _dl_if_debug_dprint(fmt, args...) do {} while (0)
-# define _dl_debug_file 2
+/* disabled on purpose, _dl_debug_file should be guarded by __SUPPORT_LD_DEBUG__
+# define _dl_debug_file 2*/
 #endif /* __SUPPORT_LD_DEBUG__ */
 
 #ifdef IS_IN_rtld
@@ -149,8 +150,19 @@ extern void *_dl_realloc(void *__ptr, size_t __size);
 extern void _dl_free(void *);
 extern char *_dl_getenv(const char *symbol, char **envp);
 extern void _dl_unsetenv(const char *symbol, char **envp);
+#ifdef IS_IN_rtld
 extern char *_dl_strdup(const char *string);
 extern void _dl_dprintf(int, const char *, ...);
+#else
+# include <string.h>
+# define _dl_strdup strdup
+# include <stdio.h>
+# ifdef __USE_GNU
+#  define _dl_dprintf dprintf
+# else
+#  define _dl_dprintf(fd, fmt, args...) fprintf(stderr, fmt, ## args)
+# endif
+#endif
 
 #ifndef DL_GET_READY_TO_RUN_EXTRA_PARMS
 # define DL_GET_READY_TO_RUN_EXTRA_PARMS
index b6dfae2..c2f52b8 100644 (file)
@@ -77,9 +77,9 @@ unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry)
                _dl_exit(1);
        }
 #if defined (__SUPPORT_LD_DEBUG__)
-#if !defined __SUPPORT_LD_DEBUG_EARLY__
+# if !defined __SUPPORT_LD_DEBUG_EARLY__
        if ((unsigned long) got_addr < 0x40000000)
-#endif
+# endif
        {
                if (_dl_debug_bindings)
                {
index 31ba11f..55ff31e 100644 (file)
@@ -739,7 +739,7 @@ struct elf_resolve *_dl_load_elf_shared_library(unsigned rflags,
                        }
                }
 #else
-               _dl_dprintf(_dl_debug_file, "Can't modify %s's text section."
+               _dl_dprintf(2, "Can't modify %s's text section."
                        " Use GCC option -fPIC for shared objects, please.\n",
                        libname);
                _dl_exit(1);
@@ -1004,6 +1004,7 @@ int _dl_fixup(struct dyn_elf *rpnt, struct r_scope_elem *scope, int now_flag)
        return goof;
 }
 
+#ifdef IS_IN_rtld
 /* Minimal printf which handles only %s, %d, and %x */
 void _dl_dprintf(int fd, const char *fmt, ...)
 {
@@ -1069,7 +1070,7 @@ void _dl_dprintf(int fd, const char *fmt, ...)
                                                break;
                                        }
                                case 'x':
-                               case 'X':
+                               case 'p':
                                        {
                                                char tmp[22];
 #if __WORDSIZE > 32
@@ -1106,6 +1107,7 @@ char *_dl_strdup(const char *string)
        _dl_strcpy(retval, string);
        return retval;
 }
+#endif
 
 unsigned int _dl_parse_dynamic_info(ElfW(Dyn) *dpnt, unsigned long dynamic_info[],
                                     void *debug_addr, DL_LOADADDR_TYPE load_off)
index a672e74..6679693 100644 (file)
@@ -922,8 +922,7 @@ _dl_add_to_slotinfo (struct link_map  *l)
             generation.  */
          ++_dl_tls_generation;
 
-         _dl_dprintf (_dl_debug_file,
-                       "cannot create TLS data structures: ABORT\n");
+         _dl_dprintf(2, "cannot create TLS data structures: ABORT\n");
          _dl_exit (127);
        }
 
index d3891e2..becabd3 100644 (file)
@@ -241,7 +241,7 @@ void *_dl_malloc(size_t size)
                _dl_mmap_zero = _dl_malloc_addr = _dl_mmap((void *) 0, rounded_size,
                                PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_UNINITIALIZE, -1, 0);
                if (_dl_mmap_check_error(_dl_mmap_zero)) {
-                       _dl_dprintf(_dl_debug_file, "%s: mmap of a spare page failed!\n", _dl_progname);
+                       _dl_dprintf(2, "%s: mmap of a spare page failed!\n", _dl_progname);
                        _dl_exit(20);
                }
        }
@@ -465,7 +465,7 @@ void *_dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
 
 #ifndef __LDSO_STANDALONE_SUPPORT__
        if (_start == (void *) auxvt[AT_ENTRY].a_un.a_val) {
-               _dl_dprintf(_dl_debug_file, "Standalone execution is not enabled\n");
+               _dl_dprintf(2, "Standalone execution is not enabled\n");
                _dl_exit(1);
        }
 #endif
@@ -579,7 +579,7 @@ of this helper program; chances are you did not intend to run this program.\n\
                 */
                app_tpnt = _dl_load_elf_shared_library(_dl_secure, &rpnt, _dl_progname);
                if (!app_tpnt) {
-                       _dl_dprintf(_dl_debug_file, "can't load '%s'\n", _dl_progname);
+                       _dl_dprintf(2, "can't load '%s'\n", _dl_progname);
                        _dl_exit(16);
                }
                /*
@@ -674,7 +674,7 @@ of this helper program; chances are you did not intend to run this program.\n\
                        }
 #else
                        if (app_tpnt->dynamic_info[DT_TEXTREL]) {
-                               _dl_dprintf(_dl_debug_file, "Can't modify application's text section; use the GCC option -fPIE for position-independent executables.\n");
+                               _dl_dprintf(2, "Can't modify application's text section; use the GCC option -fPIE for position-independent executables.\n");
                                _dl_exit(1);
                        }
 #endif
@@ -737,7 +737,7 @@ of this helper program; chances are you did not intend to run this program.\n\
                        _dl_debug_early("Found TLS header for application program\n");
                        break;
 #else
-                       _dl_dprintf(_dl_debug_file, "Program uses unsupported TLS data!\n");
+                       _dl_dprintf(2, "Program uses unsupported TLS data!\n");
                        _dl_exit(1);
 #endif
                }
@@ -827,7 +827,7 @@ of this helper program; chances are you did not intend to run this program.\n\
 
 #ifndef __LDSO_LDD_SUPPORT__
        if (trace_loaded_objects) {
-               _dl_dprintf(_dl_debug_file, "Use the ldd provided by uClibc\n");
+               _dl_dprintf(2, "Use the ldd provided by uClibc\n");
                _dl_exit(1);
        }
 #endif
@@ -883,7 +883,7 @@ of this helper program; chances are you did not intend to run this program.\n\
                                        else
 #endif
                                        {
-                                               _dl_dprintf(_dl_debug_file, "%s: library '%s' "
+                                               _dl_dprintf(2, "%s: library '%s' "
                                                        "from LD_PRELOAD can't be preloaded: ignored.\n",
                                                        _dl_progname, str);
                                        }
@@ -928,7 +928,7 @@ of this helper program; chances are you did not intend to run this program.\n\
                }
 
                if ((fd = _dl_open(LDSO_PRELOAD, O_RDONLY, 0)) < 0) {
-                       _dl_dprintf(_dl_debug_file, "%s: can't open file '%s'\n",
+                       _dl_dprintf(2, "%s: can't open file '%s'\n",
                                    _dl_progname, LDSO_PRELOAD);
                        break;
                }
@@ -937,7 +937,7 @@ of this helper program; chances are you did not intend to run this program.\n\
                                             PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
                _dl_close(fd);
                if (preload == (caddr_t) -1) {
-                       _dl_dprintf(_dl_debug_file, "%s:%i: can't map '%s'\n",
+                       _dl_dprintf(2, "%s:%i: can't map '%s'\n",
                                    _dl_progname, __LINE__, LDSO_PRELOAD);
                        break;
                }
@@ -976,7 +976,7 @@ of this helper program; chances are you did not intend to run this program.\n\
                                else
 # endif
                                {
-                                       _dl_dprintf(_dl_debug_file, "%s: can't load library '%s'\n", _dl_progname, cp2);
+                                       _dl_dprintf(2, "%s: can't load library '%s'\n", _dl_progname, cp2);
                                        _dl_exit(15);
                                }
                        } else {
@@ -1037,7 +1037,7 @@ of this helper program; chances are you did not intend to run this program.\n\
                                        } else
 #endif
                                        {
-                                               _dl_dprintf(_dl_debug_file, "%s: can't load library '%s'\n", _dl_progname, lpntstr);
+                                               _dl_dprintf(2, "%s: can't load library '%s'\n", _dl_progname, lpntstr);
                                                _dl_exit(16);
                                        }
                                }
index 4e87142..fd7fe85 100644 (file)
@@ -241,8 +241,11 @@ _dl_do_reloc(struct elf_resolve *tpnt, struct r_scope_elem *scope,
                                _dl_memcpy ((void *) reloc_addr,
                                            (void *) symbol_addr,
                                            sym_ref.sym->st_size);
-                       } else
+                       }
+#if defined (__SUPPORT_LD_DEBUG__)
+                       else
                                _dl_dprintf(_dl_debug_file, "no symbol_addr to copy !?\n");
+#endif
                        break;
 
                default:
index e3f0e47..bb61be9 100644 (file)
@@ -275,8 +275,11 @@ _dl_do_reloc(struct elf_resolve *tpnt, struct r_scope_elem *scope,
                                _dl_memcpy((char *)reloc_addr,
                                           (char *)symbol_addr,
                                           sym_ref.sym->st_size);
-                       } else
+                       }
+#if defined (__SUPPORT_LD_DEBUG__)
+                       else
                                _dl_dprintf(_dl_debug_file, "no symbol_addr to copy !?\n");
+#endif
                        break;
 #if defined USE_TLS && USE_TLS
                case R_SPARC_TLS_DTPMOD32: