Subject: Re: BFD/ld lossage on MIPS with NEW_TOOLCHAIN
To: None <tech-toolchain@netbsd.org>
From: Rafal Boni <rafal@mediaone.net>
List: tech-toolchain
Date: 10/04/2001 15:03:37
In message <200110040251.WAA23590@doppelganger.waterside.net>, I wrote: 

-> Folks:
-> 	I seem to be tripping over a nasty ld (actually, BFD) bug on my SGI
-> 	(mips) box with the new toolchain.
-> 
-> 	The short of the story is that ld generates seemingly incorrect MIPS
-> 	REL32 relocations for local symbols in shared libraries.  Using a 
-> 	small example, take the following snippet of assembly:

As was pointed out to me offline by cgd (Thanks, Chris!), this can also be
worked around in our dynamic linker... A patch to do that (and which works
with both old and new style libs) is attached below.  Again, it's a WIP and
has extra debug goo, but it does work.

--rafal

Index: reloc.c
===================================================================
RCS file: /cvsroot/basesrc/libexec/ld.elf_so/reloc.c,v
retrieving revision 1.42
diff -b -u -r1.42 reloc.c
--- reloc.c	2001/09/10 06:09:41	1.42
+++ reloc.c	2001/10/04 19:00:40
@@ -337,9 +337,20 @@
 		if (ELFDEFNNAME(ST_BIND)(def->st_info) == STB_LOCAL &&
 		  (ELFDEFNNAME(ST_TYPE)(def->st_info) == STT_SECTION ||
 		   ELFDEFNNAME(ST_TYPE)(def->st_info) == STT_NOTYPE)) {
+			rdbg(dodebug, ("REL32 in %s %p --> %p (type %d "
+				       "st_value == %x, diff %p)", 
+					obj->path, 
+					(void *)*where, (void*)(*where + 
+						(Elf_Addr)obj->relocbase), 
+					def->st_info, def->st_value,
+					(char*)*where - def->st_value));
+
+			/* XXXrkb: fix for broken binutils */
+			if (def->st_info == STT_SECTION && 
+				    (*where < def->st_value))
+			    *where += (Elf_Addr) def->st_value;
+
 			*where += (Elf_Addr)obj->relocbase;
-			rdbg(dodebug, ("REL32 in %s --> %p", obj->path,
-			    (void *)*where));
 		} else {
 			/* XXX maybe do something re: bootstrapping? */
 			def = _rtld_find_symdef(_rtld_objlist, rela->r_info,

----
Rafal Boni                                                  rafal@mediaone.net