[uClibc-cvs] uClibc/ldso/ldso ld_hash.h,1.15,1.16 ldso.c,1.62,1.63 linuxelf.h,1.9,1.10 readelflib1.c,1.39,1.40

Erik Andersen andersen at codepoet.org
Sat Mar 1 07:11:45 UTC 2003


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

Modified Files:
	ld_hash.h ldso.c linuxelf.h readelflib1.c 
Log Message:
Fix the shared library loader so we can properly debug things like pthreads.
Mips gdb support for pthreads and similar complex stuff is broken, but then it
couldn't have worked before either...
 -Erik


Index: ld_hash.h
===================================================================
RCS file: /var/cvs/uClibc/ldso/ldso/ld_hash.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- ld_hash.h	19 Aug 2002 10:22:36 -0000	1.15
+++ ld_hash.h	1 Mar 2003 07:11:38 -0000	1.16
@@ -10,7 +10,7 @@
 {
   /* These entries must be in this order to be compatible with the
    * interface used by gdb to obtain the list of symbols. */
-  unsigned long l_addr;	/* address at which object is mapped */
+  Elf32_Addr l_addr;	/* address at which object is mapped */
   char *l_name;		/* full name of loaded object */
   Elf32_Dyn *l_ld;	/* dynamic structure of object */
   struct link_map *l_next;

Index: ldso.c
===================================================================
RCS file: /var/cvs/uClibc/ldso/ldso/ldso.c,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- ldso.c	26 Feb 2003 02:05:41 -0000	1.62
+++ ldso.c	1 Mar 2003 07:11:38 -0000	1.63
@@ -148,6 +148,7 @@
 static int (*_dl_elf_main) (int, char **, char **);
 static int (*_dl_elf_init) (void);
 struct r_debug *_dl_debug_addr = NULL;
+static struct r_debug *_tmp_debug_addr = NULL;
 unsigned long *_dl_brkp;
 unsigned long *_dl_envp;
 int _dl_fixup(struct elf_resolve *tpnt);
@@ -155,7 +156,7 @@
 char *_dl_get_last_path_component(char *path);
 static void _dl_get_ready_to_run(struct elf_resolve *tpnt, struct elf_resolve *app_tpnt, 
 		unsigned long load_addr, unsigned long *hash_addr, Elf32_auxv_t auxvt[AT_EGID + 1], 
-		char **envp, struct r_debug *debug_addr);
+		char **envp);
 #include "boot1_arch.h"
 #include "ldso.h"				/* Pull in the name of ld.so */
 
@@ -209,12 +210,8 @@
 	unsigned char *malloc_buffer, *mmap_zero;
 	Elf32_Dyn *dpnt;
 	unsigned long *hash_addr;
-	struct r_debug *debug_addr;
 	int indx;
 	int status;
-#ifndef FORCE_SHAREABLE_TEXT_SEGMENTS
-	Elf32_Dyn *dpnt_debug = NULL;
-#endif
 
 
 	/* WARNING! -- we cannot make _any_ funtion calls until we have
@@ -382,8 +379,8 @@
 	/*
 	 * This is used by gdb to locate the chain of shared libraries that are currently loaded.
 	 */
-	debug_addr = LD_MALLOC(sizeof(struct r_debug));
-	_dl_memset(debug_addr, 0, sizeof(*debug_addr));
+	_tmp_debug_addr = LD_MALLOC(sizeof(struct r_debug));
+	_dl_memset(_tmp_debug_addr, 0, sizeof(struct r_debug));
 
 	/* OK, that was easy.  Next scan the DYNAMIC section of the image.
 	   We are only doing ourself right now - we will have to do the rest later */
@@ -433,13 +430,13 @@
 						continue;
 					}
 					app_tpnt->dynamic_info[dpnt->d_tag] = dpnt->d_un.d_val;
+#if !defined(__mips__)
 					if (dpnt->d_tag == DT_DEBUG) {
-#ifdef FORCE_SHAREABLE_TEXT_SEGMENTS
-						dpnt->d_un.d_val = (unsigned long) debug_addr;
+						dpnt->d_un.d_val = (unsigned long) _tmp_debug_addr;
+					}
 #else
-						dpnt_debug = (unsigned long) debug_addr;
+#warning "Debugging threads on mips won't work till someone fixes this..."
 #endif
-					}
 					if (dpnt->d_tag == DT_TEXTREL)
 						app_tpnt->dynamic_info[DT_TEXTREL] = 1;
 					dpnt++;
@@ -506,13 +503,6 @@
 			}
 		}
 	}
-#ifdef __SUPPORT_LD_DEBUG_EARLY__
-	SEND_STDERR("About to store the debug structure address\n");
-#endif
-	/* Now we can store the debug structure address */
-	if (dpnt_debug != NULL) {
-		dpnt_debug->d_un.d_val = (unsigned long) debug_addr;
-	}
 #endif
 	
 #if defined(__mips__)
@@ -624,14 +614,17 @@
 	   free to start using global variables, since these things have all been
 	   fixed up by now.  Still no function calls outside of this library ,
 	   since the dynamic resolver is not yet ready. */
-	_dl_get_ready_to_run(tpnt, app_tpnt, load_addr, hash_addr, auxvt, envp, debug_addr);
+	_dl_get_ready_to_run(tpnt, app_tpnt, load_addr, hash_addr, auxvt, envp);
+
 
+	/* Notify the debugger that all objects are now mapped in.  */
+	_dl_debug_addr->r_state = RT_CONSISTENT;
+	_dl_debug_state();
 
 
 	/* OK we are done here.  Turn out the lights, and lock up. */
 	_dl_elf_main = (int (*)(int, char **, char **)) auxvt[AT_ENTRY].a_un.a_fcn;
 
-
 	/*
 	 * Transfer control to the application.
 	 */
@@ -652,7 +645,7 @@
 
 static void _dl_get_ready_to_run(struct elf_resolve *tpnt, struct elf_resolve *app_tpnt, 
 		unsigned long load_addr, unsigned long *hash_addr, Elf32_auxv_t auxvt[AT_EGID + 1], 
-		char **envp, struct r_debug *debug_addr)
+		char **envp)
 {
 	elf_phdr *ppnt;
 	char *lpntstr;
@@ -891,6 +884,22 @@
 		_dl_exit(1);
 	}
 #endif
+
+	/*
+	 * OK, fix one more thing - set up _tmp_debug_addr so it will point
+	 * to our chain.  Later we may need to fill in more fields, but this
+	 * should be enough for now.
+	 */
+	_tmp_debug_addr->r_map = (struct link_map *) _dl_loaded_modules;
+	_tmp_debug_addr->r_version = 1;
+	_tmp_debug_addr->r_ldbase = load_addr;
+	_tmp_debug_addr->r_brk = (unsigned long) &_dl_debug_state;
+	_dl_debug_addr = _tmp_debug_addr;
+
+	/* Notify the debugger we are in a consistant state */
+	_dl_debug_addr->r_state = RT_CONSISTENT;
+	_dl_debug_state();
+
 	/* OK, we now have the application in the list, and we have some
 	   basic stuff in place.  Now search through the list for other shared
 	   libraries that should be loaded, and insert them on the list in the
@@ -1229,20 +1238,9 @@
 		(intptr_t) _dl_find_hash("on_exit", NULL, NULL, symbolrel);
 #endif
 
-	/*
-	 * OK, fix one more thing - set up the debug_addr structure to point
-	 * to our chain.  Later we may need to fill in more fields, but this
-	 * should be enough for now.
-	 */
-	debug_addr->r_map = (struct link_map *) _dl_loaded_modules;
-	debug_addr->r_version = 1;
-	debug_addr->r_ldbase = load_addr;
-	debug_addr->r_brk = (unsigned long) &_dl_debug_state;
-	_dl_debug_addr = debug_addr;
-	debug_addr->r_state = RT_CONSISTENT;
-	/* This is written in this funny way to keep gcc from inlining the
-	   function call. */
-	((void (*)(void)) debug_addr->r_brk) ();
+	/* Notify the debugger we have added some objects. */
+	_dl_debug_addr->r_state = RT_ADD;
+	_dl_debug_state();
 
 	for (rpnt = _dl_symbol_tables; rpnt!=NULL&& rpnt->next!=NULL; rpnt=rpnt->next)
 	  ;
@@ -1299,9 +1297,8 @@
  * can set an internal breakpoint on it, so that we are notified when the
  * address mapping is changed in some way.
  */
-void _dl_debug_state()
+void _dl_debug_state(void)
 {
-	return;
 }
 
 int _dl_fixup(struct elf_resolve *tpnt)

Index: linuxelf.h
===================================================================
RCS file: /var/cvs/uClibc/ldso/ldso/linuxelf.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- linuxelf.h	20 Nov 2002 10:49:56 -0000	1.9
+++ linuxelf.h	1 Mar 2003 07:11:38 -0000	1.10
@@ -12,7 +12,6 @@
 
 
 /* Some function prototypes */
-extern void * _dl_malloc(int size);
 extern int _dl_map_cache(void);
 extern int _dl_unmap_cache(void);
 int _dl_copy_fixups(struct dyn_elf * tpnt);

Index: readelflib1.c
===================================================================
RCS file: /var/cvs/uClibc/ldso/ldso/readelflib1.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- readelflib1.c	24 Jan 2003 16:28:09 -0000	1.39
+++ readelflib1.c	1 Mar 2003 07:11:39 -0000	1.40
@@ -743,7 +743,6 @@
 	return;
 }
 
-void *(*_dl_malloc_function) (size_t size) = NULL;
 char *_dl_strdup(const char *string)
 {
 	char *retval;
@@ -755,6 +754,7 @@
 	return retval;
 }
 
+void *(*_dl_malloc_function) (size_t size) = NULL;
 void *_dl_malloc(int size)
 {
 	void *retval;




More information about the uClibc-cvs mailing list