Subject: Re: CVS commit: basesrc/libexec/ld.elf_so
To: None <rafal@netbsd.org>
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
List: port-mips
Date: 11/11/2001 14:08:22
In article <20011014231323.8E4DCB009@cvs.netbsd.org>
rafal@netbsd.org wrote:

> Module Name:	basesrc
> Committed By:	rafal
> Date:		Sun Oct 14 23:13:22 UTC 2001
> 
> Modified Files:
> 	basesrc/libexec/ld.elf_so: symbol.c
> 	basesrc/libexec/ld.elf_so/arch/mips: mips_reloc.c
> 
> Log Message:
> Fix how underfined weak symbols are treated -- before, ld.so would do nothing
> with them, rather than defaulting them to zero.  This caused breakage with
> the drawf EH stuff and init/fini code when they weren't used by the caller
> (and hence the appropriate handlers were left undefined).  Also fix an un-
> initialized variable in symbol.c that only MIPS MD code tripped over.

After this change, still old binaries compiled before init/fini changes
dumps core in _rtld_relocate_mips_got().
The attached patch (i.e. partially backing out this change) seems
to fix this problem. Is it correct?
---
Izumi Tsutsui
tsutsui@ceres.dti.ne.jp

Index: mips_reloc.c
===================================================================
RCS file: /cvsroot/basesrc/libexec/ld.elf_so/arch/mips/mips_reloc.c,v
retrieving revision 1.4
diff -u -r1.4 mips_reloc.c
--- mips_reloc.c	2001/10/14 23:13:22	1.4
+++ mips_reloc.c	2001/11/11 04:42:49
@@ -73,39 +73,41 @@
 			    obj->path, sym->st_name + obj->strtab,
 			    (u_long) ELF_R_TYPE(info), 
 			    (u_long) obj->symtabno - i - 1);
+		else {
 
-		if (sym->st_shndx == SHN_UNDEF) {
+			if (sym->st_shndx == SHN_UNDEF) {
 #if 0	/* These don't seem to work? */
 
-			if (ELFDEFNNAME(ST_TYPE)(sym->st_info) ==
-			    STT_FUNC) {
-				if (sym->st_value)
-					*got = sym->st_value +
-					    (Elf_Word)obj->relocbase;
-				else
+				if (ELFDEFNNAME(ST_TYPE)(sym->st_info) ==
+				    STT_FUNC) {
+					if (sym->st_value)
+						*got = sym->st_value +
+						    (Elf_Word)obj->relocbase;
+					else
+						*got = def->st_value +
+						    (Elf_Word)defobj->relocbase;
+				} else
+#endif
 					*got = def->st_value +
 					    (Elf_Word)defobj->relocbase;
+			} else if (sym->st_shndx == SHN_COMMON) {
+				*got = def->st_value +
+				    (Elf_Word)defobj->relocbase;
+			} else if (ELFDEFNNAME(ST_TYPE)(sym->st_info) ==
+			    STT_FUNC &&
+			    *got != sym->st_value) {
+				*got += (Elf_Word)obj->relocbase;
+			} else if (ELFDEFNNAME(ST_TYPE)(sym->st_info) ==
+			    STT_SECTION && ELFDEFNNAME(ST_BIND)(sym->st_info) ==
+			    STB_GLOBAL) {
+				if (sym->st_shndx == SHN_ABS)
+					*got = sym->st_value +
+					    (Elf_Word)obj->relocbase;
+				/* else SGI stuff ignored */
 			} else
-#endif
 				*got = def->st_value +
 				    (Elf_Word)defobj->relocbase;
-		} else if (sym->st_shndx == SHN_COMMON) {
-			*got = def->st_value +
-			    (Elf_Word)defobj->relocbase;
-		} else if (ELFDEFNNAME(ST_TYPE)(sym->st_info) ==
-		    STT_FUNC &&
-		    *got != sym->st_value) {
-			*got += (Elf_Word)obj->relocbase;
-		} else if (ELFDEFNNAME(ST_TYPE)(sym->st_info) ==
-		    STT_SECTION && ELFDEFNNAME(ST_BIND)(sym->st_info) ==
-		    STB_GLOBAL) {
-			if (sym->st_shndx == SHN_ABS)
-				*got = sym->st_value +
-				    (Elf_Word)obj->relocbase;
-			/* else SGI stuff ignored */
-		} else
-			*got = def->st_value +
-			    (Elf_Word)defobj->relocbase;
+		}
 
 		++sym;
 		++got;