[git commit future 1/1] ldso: use _dl_strdup and _dl_dprintf only in ld-uClibc.so

Peter S. Mazinger ps.m at gmx.net
Wed Mar 30 11:53:36 UTC 2011


commit: http://git.uclibc.org/uClibc/commit/?id=0c2981bbeedf3a040a5da2fa2e02202e2bbab0aa
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/future

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 at gmx.net>
---
 ldso/include/ldso.h |   14 +++++++++++++-
 ldso/ldso/dl-elf.c  |    6 ++++--
 ldso/ldso/dl-tls.c  |    3 +--
 ldso/ldso/ldso.c    |   18 +++++++++---------
 4 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/ldso/include/ldso.h b/ldso/include/ldso.h
index cc65e6c..94bf7f6 100644
--- a/ldso/include/ldso.h
+++ b/ldso/include/ldso.h
@@ -98,7 +98,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
@@ -134,8 +135,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
diff --git a/ldso/ldso/dl-elf.c b/ldso/ldso/dl-elf.c
index 505247e..100af43 100644
--- a/ldso/ldso/dl-elf.c
+++ b/ldso/ldso/dl-elf.c
@@ -718,7 +718,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure,
 			}
 		}
 #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);
@@ -938,6 +938,7 @@ int _dl_fixup(struct dyn_elf *rpnt, 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, ...)
 {
@@ -1003,7 +1004,7 @@ void _dl_dprintf(int fd, const char *fmt, ...)
 						break;
 					}
 				case 'x':
-				case 'X':
+				case 'p':
 					{
 						char tmp[22];
 #if __WORDSIZE > 32
@@ -1040,6 +1041,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)
diff --git a/ldso/ldso/dl-tls.c b/ldso/ldso/dl-tls.c
index 43dd5a0..a3b5383 100644
--- a/ldso/ldso/dl-tls.c
+++ b/ldso/ldso/dl-tls.c
@@ -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);
 	}
 
diff --git a/ldso/ldso/ldso.c b/ldso/ldso/ldso.c
index 7ee9257..752dbe8 100644
--- a/ldso/ldso/ldso.c
+++ b/ldso/ldso/ldso.c
@@ -195,7 +195,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);
 		}
 	}
@@ -326,7 +326,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
 	}
 
 	if (_start == (void *) auxvt[AT_ENTRY].a_un.a_val) {
-		_dl_dprintf(_dl_debug_file, "Standalone execution is not supported yet\n");
+		_dl_dprintf(2, "Standalone execution is not supported yet\n");
 		_dl_exit(1);
 	}
 
@@ -444,7 +444,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
 			}
 #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
@@ -514,7 +514,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
 			_dl_debug_early("Found TLS header for appplication 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
 		}
@@ -642,7 +642,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
 					else
 #endif
 					{
-						_dl_dprintf(_dl_debug_file, "%s: can't load " "library '%s'\n", _dl_progname, str);
+						_dl_dprintf(2, "%s: can't load " "library '%s'\n", _dl_progname, str);
 						_dl_exit(15);
 					}
 				} else {
@@ -685,7 +685,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
 		}
 
 		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;
 		}
@@ -694,7 +694,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
 					     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;
 		}
@@ -733,7 +733,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
 				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 {
@@ -786,7 +786,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
 					} 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);
 					}
 				}
-- 
1.7.3.4



More information about the uClibc-cvs mailing list