[uClibc-cvs] CVS update of uClibc/ldso/ldso (arm/elfinterp.c dl-startup.c i386/elfinterp.c mips/elfinterp.c powerpc/elfinterp.c)

Erik Andersen andersen at codepoet.org
Sun Jun 27 01:16:12 UTC 2004


    Date: Saturday, June 26, 2004 @ 19:16:12
  Author: andersen
    Path: /var/cvs/uClibc/ldso/ldso

Modified: arm/elfinterp.c (1.21 -> 1.22) dl-startup.c (1.12 -> 1.13)
          i386/elfinterp.c (1.31 -> 1.32) mips/elfinterp.c (1.15 -> 1.16)
          powerpc/elfinterp.c (1.39 -> 1.40)

Joakim Tjernlund writes:

Hi yet again :)

in dl-startup.c when performing boot strap relocation the following test
exists to make sure that only "_dl_" symbols are relocated:
/* We only do a partial dynamic linking right now.  The user
 is not supposed to define any symbols that start with a
 '_dl', so we can do this with confidence. */
 if (!symname || !_dl_symbol(symname)) {
        continue;
 }

However on PPC(and the other archs as well I suspect) all symbols are
"_dl_" symbols so the test is never true. The test can be removed and the
whole loop simplified(smaller). This also makes it possible to
simplify elfinterp.c

This remove the scanning of ldso.so relocs, making relocation faster.

I have tested this on PPC and it works well.
Do you think this optimization will work for the other arches as well?
I can't see why not.

     Jocke

* Tested on x86, arm, mipsel, and powerpc by Erik and works nicely 
 -Erik


Index: uClibc/ldso/ldso/arm/elfinterp.c
diff -u uClibc/ldso/ldso/arm/elfinterp.c:1.21 uClibc/ldso/ldso/arm/elfinterp.c:1.22
--- uClibc/ldso/ldso/arm/elfinterp.c:1.21	Thu Jun 24 01:52:08 2004
+++ uClibc/ldso/ldso/arm/elfinterp.c	Sat Jun 26 19:16:07 2004
@@ -188,8 +188,13 @@
 	Elf32_Sym *symtab;
 	ELF_RELOC *rpnt;
 	int symtab_index;
-	/* Now parse the relocation information */
 
+	/* When the dynamic linker bootstrapped itself, it resolved some symbols.
+	   Make sure we do not do them again */
+	if (tpnt->libtype == program_interpreter)
+		return 0;
+
+	/* Now parse the relocation information */
 	rpnt = (ELF_RELOC *) (rel_addr + tpnt->loadaddr);
 	rel_size = rel_size / sizeof(ELF_RELOC);
 
@@ -201,14 +206,6 @@
 
 		symtab_index = ELF32_R_SYM(rpnt->r_info);
 
-		/* When the dynamic linker bootstrapped itself, it resolved some symbols.
-		   Make sure we do not do them again */
-		if (!symtab_index && tpnt->libtype == program_interpreter)
-			continue;
-		if (symtab_index && tpnt->libtype == program_interpreter &&
-		    _dl_symbol(strtab + symtab[symtab_index].st_name))
-			continue;
-
 #if defined (__SUPPORT_LD_DEBUG__)
 		debug_sym(symtab,strtab,symtab_index);
 		debug_reloc(symtab,strtab,rpnt);
Index: uClibc/ldso/ldso/dl-startup.c
diff -u uClibc/ldso/ldso/dl-startup.c:1.12 uClibc/ldso/ldso/dl-startup.c:1.13
--- uClibc/ldso/ldso/dl-startup.c:1.12	Wed May 12 18:19:47 2004
+++ uClibc/ldso/ldso/dl-startup.c	Sat Jun 26 19:16:05 2004
@@ -490,7 +490,7 @@
 		unsigned long symbol_addr;
 		int symtab_index;
 		unsigned long rel_addr, rel_size;
-
+		Elf32_Sym *sym;
 
 		rel_addr = (indx ? tpnt->dynamic_info[DT_JMPREL] : tpnt->
 				dynamic_info[DT_RELOC_TABLE_ADDR]);
@@ -506,43 +506,24 @@
 			reloc_addr = (unsigned long *) (load_addr + (unsigned long) rpnt->r_offset);
 			symtab_index = ELF32_R_SYM(rpnt->r_info);
 			symbol_addr = 0;
+			sym = NULL;
 			if (symtab_index) {
 				char *strtab;
-				char *symname;
 				Elf32_Sym *symtab;
 
 				symtab = (Elf32_Sym *) (tpnt->dynamic_info[DT_SYMTAB] + load_addr);
 				strtab = (char *) (tpnt->dynamic_info[DT_STRTAB] + load_addr);
-				symname = strtab + symtab[symtab_index].st_name;
+				sym = &symtab[symtab_index];
+				symbol_addr = load_addr + sym->st_value;
 
-				/* We only do a partial dynamic linking right now.  The user
-				   is not supposed to define any symbols that start with a
-				   '_dl', so we can do this with confidence. */
-				if (!symname || !_dl_symbol(symname)) {
-					continue;
-				}
-
-				symbol_addr = load_addr + symtab[symtab_index].st_value;
-
-				if (!symbol_addr) {
-					/* This will segfault - you cannot call a function until
-					 * we have finished the relocations.
-					 */
-					SEND_STDERR("ELF dynamic loader - unable to self-bootstrap - symbol ");
-					SEND_STDERR(symname);
-					SEND_STDERR(" undefined.\n");
-					goof++;
-				}
 #ifdef __SUPPORT_LD_DEBUG_EARLY__
 				SEND_STDERR("relocating symbol: ");
-				SEND_STDERR(symname);
+				SEND_STDERR(strtab + sym->st_name);
 				SEND_STDERR("\n");
 #endif
-				PERFORM_BOOTSTRAP_RELOC(rpnt, reloc_addr, symbol_addr, load_addr, &symtab[symtab_index]);
-			} else {
-				/* Use this machine-specific macro to perform the actual relocation.  */
-				PERFORM_BOOTSTRAP_RELOC(rpnt, reloc_addr, symbol_addr, load_addr, NULL);
 			}
+			/* Use this machine-specific macro to perform the actual relocation.  */
+			PERFORM_BOOTSTRAP_RELOC(rpnt, reloc_addr, symbol_addr, load_addr, sym);
 		}
 	}
 
Index: uClibc/ldso/ldso/i386/elfinterp.c
diff -u uClibc/ldso/ldso/i386/elfinterp.c:1.31 uClibc/ldso/ldso/i386/elfinterp.c:1.32
--- uClibc/ldso/ldso/i386/elfinterp.c:1.31	Sat Feb 14 04:53:55 2004
+++ uClibc/ldso/ldso/i386/elfinterp.c	Sat Jun 26 19:16:08 2004
@@ -183,6 +183,11 @@
 	ELF_RELOC *rpnt;
 	int symtab_index;
 
+	/* When the dynamic linker bootstrapped itself, it resolved some symbols.
+	   Make sure we do not do them again */
+	if (tpnt->libtype == program_interpreter)
+		return 0;
+
 	/* Now parse the relocation information */
 	rpnt = (ELF_RELOC *)(intptr_t) (rel_addr + tpnt->loadaddr);
 	rel_size = rel_size / sizeof(ELF_RELOC);
@@ -195,14 +200,6 @@
 
 		symtab_index = ELF32_R_SYM(rpnt->r_info);
 
-		/* When the dynamic linker bootstrapped itself, it resolved some symbols.
-		   Make sure we do not do them again */
-		if (!symtab_index && tpnt->libtype == program_interpreter)
-			continue;
-		if (symtab_index && tpnt->libtype == program_interpreter &&
-		    _dl_symbol(strtab + symtab[symtab_index].st_name))
-			continue;
-
 #if defined (__SUPPORT_LD_DEBUG__)
 		debug_sym(symtab,strtab,symtab_index);
 		debug_reloc(symtab,strtab,rpnt);
Index: uClibc/ldso/ldso/mips/elfinterp.c
diff -u uClibc/ldso/ldso/mips/elfinterp.c:1.15 uClibc/ldso/ldso/mips/elfinterp.c:1.16
--- uClibc/ldso/ldso/mips/elfinterp.c:1.15	Sat Jun 19 15:32:41 2004
+++ uClibc/ldso/ldso/mips/elfinterp.c	Sat Jun 26 19:16:09 2004
@@ -187,6 +187,9 @@
 	unsigned long old_val=0;
 #endif
 
+	if (tpnt->libtype == program_interpreter)
+		return 0;
+
 	/* Now parse the relocation information */
 	rel_size = rel_size / sizeof(Elf32_Rel);
 	rpnt = (Elf32_Rel *) (rel_addr + tpnt->loadaddr);
@@ -202,9 +205,6 @@
 		symtab_index = ELF32_R_SYM(rpnt->r_info);
 		symbol_addr = 0;
 
-		if (!symtab_index && tpnt->libtype == program_interpreter)
-			continue;
-
 #if defined (__SUPPORT_LD_DEBUG__)
 		debug_sym(symtab,strtab,symtab_index);
 		debug_reloc(symtab,strtab,rpnt);
Index: uClibc/ldso/ldso/powerpc/elfinterp.c
diff -u uClibc/ldso/ldso/powerpc/elfinterp.c:1.39 uClibc/ldso/ldso/powerpc/elfinterp.c:1.40
--- uClibc/ldso/ldso/powerpc/elfinterp.c:1.39	Sat Jun 19 23:39:04 2004
+++ uClibc/ldso/ldso/powerpc/elfinterp.c	Sat Jun 26 19:16:10 2004
@@ -443,6 +443,11 @@
 	ELF_RELOC *rpnt;
 	int symtab_index;
 
+	/* When the dynamic linker bootstrapped itself, it resolved some symbols.
+	   Make sure we do not do them again */
+	if (tpnt->libtype == program_interpreter)
+		return 0;
+
 	/* Now parse the relocation information */
 	rpnt = (ELF_RELOC *)(intptr_t) (rel_addr + tpnt->loadaddr);
 	rel_size = rel_size / sizeof(ELF_RELOC);
@@ -455,14 +460,6 @@
 
 		symtab_index = ELF32_R_SYM(rpnt->r_info);
 
-		/* When the dynamic linker bootstrapped itself, it resolved some symbols.
-		   Make sure we do not do them again */
-		if (!symtab_index && tpnt->libtype == program_interpreter)
-			continue;
-		if (symtab_index && tpnt->libtype == program_interpreter &&
-		    _dl_symbol(strtab + symtab[symtab_index].st_name))
-			continue;
-
 #if defined (__SUPPORT_LD_DEBUG__)
 		debug_sym(symtab,strtab,symtab_index);
 		debug_reloc(symtab,strtab,rpnt);



More information about the uClibc-cvs mailing list