elf32-mips breaks binary compatibility

Ralf Baechle ralf@uni-koblenz.de
Mon Aug 16 15:07:00 GMT 1999


Hi,

the current elf32-mips.c fixes an ancient bug in how relocations in glibc
are being computed.  The bad thing is that this breaks binary compatibility
with for dynamic objects generated by older linkers like binutils 2.8.1.
So far this went unnoticed because the problem got compensated by an
equivalent hack in glibc's dynamic linker, so this bug is by now probably
not only well established for Linux/MIPS systems but probably OpenBSD and
NetBSD as well ...

The problem: when generating references to global symbols old linkers have
not added the symbols value to the field being relocated in the linker
output.  That means for example for

	.globl	var
var:	.word	var + 0x1234

ld would have emited a 32-bit word with the value 0x1234 into output file
while current ld would emit 0x1234 + actual address of var into the
linker output.  Note that this bug affects only ELF shared library
generation; normal executables alway had been ok.

(And this made a few programs dump core because the equivalent bug in the
GNU libc dynamic linker affected all binaries, not just DSOs ...)

Right now I'm working on changing the current linker to tag all binaries
such that the dynamic linker can recognice them and do the right thing.
Mark has suggested using a DT_MIPS_LINUX_VERSION tag.  I'm a bit
reluctant to allocate such a new DT_ tag because MIPS / SGI are using them
for all sorts of purposes and I want to avoid a future clash.  So my
proposal which is a bit hackish would be to use the DT_MIPS_TIME_STAMP
tag with a special magic time stamp.  I've choosen the value 11717580
which is equivalent to a date in 1970, therfore should never ever be
generated in a binary generated by a SGI linker; current GNU linkers don't
emit this tag at all.  Comments?

Following below a patch which does the wrong thing and reintroduces the
wrong behaviour into current bfd and a short piece of code which
demonstrates the difference in the linker output.

  Ralf

Index: binutils-cygnus/bfd/elf32-mips.c
===================================================================
RCS file: /cvs/binutils/binutils/bfd/elf32-mips.c,v
retrieving revision 1.49
diff -u -r1.49 elf32-mips.c
--- elf32-mips.c	1999/08/15 22:56:20	1.49
+++ elf32-mips.c	1999/08/16 00:24:31
@@ -5658,7 +5661,6 @@
   else
     {
       long indx;
-      bfd_vma section_offset;
 
       /* We must now calculate the dynamic symbol table index to use
 	 in the relocation.  */
@@ -5685,23 +5687,12 @@
 		abort ();
 	    }
 
-	  /* Figure out how far the target of the relocation is from
-	     the beginning of its section.  */
-	  section_offset = symbol - sec->output_section->vma;
 	  /* The relocation we're building is section-relative.
 	     Therefore, the original addend must be adjusted by the
 	     section offset.  */
-	  *addendp += symbol - sec->output_section->vma;
-	  /* Now, the relocation is just against the section.  */
-	  symbol = sec->output_section->vma;
+	  *addendp += symbol;
 	}
-      
-      /* If the relocation was previously an absolute relocation, we
-	 must adjust it by the value we give it in the dynamic symbol
-	 table.  */
-      if (r_type != R_MIPS_REL32)
-	*addendp += symbol;
-
+ 
       /* The relocation is always an REL32 relocation because we don't
 	 know where the shared library will wind up at load-time.  */
       outrel.r_info = ELF32_R_INFO (indx, R_MIPS_REL32);

begin 664 nuke-ld-13.tar.gz
M'XL("(D!KC<"`VYU:V4M;&0M,3,N=&%R`.W6SVO;,!0'<%^MO^(=<M@.\F1;
MMB!06$<.8[1K8>RP2T&QY%:M(@7+IMU_/]NX35)8>VGZ([P/Q(KT!%)X?(-=
M=Z.I533-OT3[`IP)44`$`*+D.^.$`92BR#EC15D"I$RP-((B>@5=:&4#$#72
MUD_M>Z[^0;E-_T_EC:Z-U2]^1LI8R?G_^\_[XMC_7&2Y&/J?\:R(@&'_]^[X
M%QS!RJP#M<9U=U0&<K+87;**G'W[L?A]>KZ[[I?7JENM"9'6SL&:94B")R0Y
M_W[V\\]F81KG$-+$0\@23^+9IY/%9Z#A2C9:`?4P^PJSBV%].JDO4O77R96I
M:*.MK_H=C\I!5ZWQ[BA1LI7]O.ZLI95WK79M&+8_W*2R6CI0)K3C-_)H/B<Q
M;59`Z_LK;VX*E6\TB0[85O[['QSV<L9S^4]3,>6_+/,R&Q:X8)C_UQ`G?CW$
M*%Z;*B,D'M,TC)?6+VU<-WY)AL<\3FY]H^+:^ZUJ/^D_]S6>'714#C[_Z1OE
M'X9WOBG_F1!C_@N!^7\'^5?>N$LR/K?_`3`W""&$$$(((8000@@AA!!""+U'
*_P`Y[-W<`"@`````
`
end


More information about the Binutils mailing list