public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* mips rel32/64 to section symbol
@ 2003-03-11  2:48 Alexandre Oliva
  2003-03-11 18:05 ` Alexandre Oliva
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandre Oliva @ 2003-03-11  2:48 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 1183 bytes --]

Since we've all agreed that the current implementation of rel32
addends is broken for section symbols, but simply fixing ld to do the
right thing would require changes in ld.so that would break existing
executables, I went ahead and implemented Maciej's clever suggestion
to just emit NULL-symbol relocations instead of relocations to section
symbols.  I've tested this by creating a shared library with a static
void* initialized to point to itself, and running a program that
compared the pointer with its address.  Success on all of o32, n32 and
n64, without any changes to glibc, and this time only with
ABI-compliant relocations.

Eric Christopher approved this in private, but I'll put this in only
after my automated tester gives it a full round of testing on all 3
ABIs on big and little endian, and after I come up with testcases for
the linker to make sure this doesn't regress.  So far, I've only
tested it by hand on the 3 ABIs, verifying the presence of appropriate
relocations by visual inspection and testing that the program would
run with the old glibc as well as with a newly-built one.  I'm posting
it here earlier so as to give y'all more time to comment on it.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: bfd-mips-dyn-reloc-to-section.patch --]
[-- Type: text/x-patch, Size: 3119 bytes --]

Index: bfd/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* elfxx-mips.c (mips_elf_create_dynamic_relocation): Do not create
	dynamic relocations pointing to local or section symbols, use the
	NULL symbol instead.  Document the choice to not emit an
	additional R_MIPS_64 relocation.

Index: bfd/elfxx-mips.c
===================================================================
RCS file: /cvs/uberbaum/bfd/elfxx-mips.c,v
retrieving revision 1.44
diff -u -p -r1.44 elfxx-mips.c
--- bfd/elfxx-mips.c 2 Mar 2003 21:30:14 -0000 1.44
+++ bfd/elfxx-mips.c 11 Mar 2003 02:43:30 -0000
@@ -3832,7 +3832,6 @@ mips_elf_create_dynamic_relocation (outp
   else
     {
       long indx;
-      bfd_vma section_offset;
 
       /* We must now calculate the dynamic symbol table index to use
 	 in the relocation.  */
@@ -3862,15 +3861,18 @@ mips_elf_create_dynamic_relocation (outp
 		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 += section_offset;
-	  /* Now, the relocation is just against the section.  */
-	  symbol = sec->output_section->vma;
+	  /* Instead of generating a relocation using the section
+	     symbol, we may as well make it a fully relative
+	     relocation.  We want to avoid generating relocations to
+	     local symbols because we used to generate them
+	     incorrectly, without adding the original symbol value,
+	     which is mandated by the ABI for section symbols.  In
+	     order to give dynamic loaders and applications time to
+	     phase out the incorrect use, we refrain from emitting
+	     section-relative relocations.  It's not like they're
+	     useful, after all.  This should be a bit more efficient
+	     as well.  */
+	  indx = 0;
 	}
 
       /* If the relocation was previously an absolute relocation and
@@ -3884,6 +3886,18 @@ mips_elf_create_dynamic_relocation (outp
 	 know where the shared library will wind up at load-time.  */
       outrel[0].r_info = ELF_R_INFO (output_bfd, (unsigned long) indx,
 				     R_MIPS_REL32);
+      /* For strict adherence to the ABI specification, we should
+	 generate a R_MIPS_64 relocation record by itself before the
+	 _REL32/_64 record as well, such that the addend is read in as
+	 a 64-bit value (REL32 is a 32-bit relocation, after all).
+	 However, since none of the existing ELF64 MIPS dynamic
+	 loaders seems to care, we don't waste space with these
+	 artificial relocations.  If this turns out to not be true,
+	 mips_elf_allocate_dynamic_relocation() should be tweaked so
+	 as to make room for a pair of dynamic relocations per
+	 invocation if ABI_64_P, and here we should generate an
+	 additional relocation record with R_MIPS_64 by itself for a
+	 NULL symbol before this relocation record.  */
       outrel[1].r_info = ELF_R_INFO (output_bfd, (unsigned long) 0,
 				     ABI_64_P (output_bfd)
 				     ? R_MIPS_64

[-- Attachment #3: Type: text/plain, Size: 289 bytes --]


-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: mips rel32/64 to section symbol
  2003-03-11  2:48 mips rel32/64 to section symbol Alexandre Oliva
@ 2003-03-11 18:05 ` Alexandre Oliva
  2003-03-11 18:41   ` Eric Christopher
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandre Oliva @ 2003-03-11 18:05 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 212 bytes --]

On Mar 10, 2003, Alexandre Oliva <aoliva@redhat.com> wrote:

> I'll put this in only [...] after I come up with testcases for
> the linker to make sure this doesn't regress.

Here are the tests.  Ok to install?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: bfd-mips-dyn-reloc-to-section-tests.patch --]
[-- Type: text/x-patch, Size: 5226 bytes --]

Index: ld/testsuite/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* ld-mips-elf/mips-elf.exp (linux_gnu): New variable.  Add:
	* ld-mips-elf/rel32-o32.d, ld-mips-elf/rel32-n32.d,
	ld-mips-elf/rel64.d, ld-mips-elf/rel32.s, ld-mips-elf/rel64.s: New
	tests.

Index: ld/testsuite/ld-mips-elf/mips-elf.exp
===================================================================
RCS file: /cvs/uberbaum/ld/testsuite/ld-mips-elf/mips-elf.exp,v
retrieving revision 1.8
diff -u -p -r1.8 mips-elf.exp
--- ld/testsuite/ld-mips-elf/mips-elf.exp 28 Jan 2003 00:01:53 -0000 1.8
+++ ld/testsuite/ld-mips-elf/mips-elf.exp 11 Mar 2003 18:01:52 -0000
@@ -1,5 +1,5 @@
 # Expect script for MIPS ELF linker tests
-#   Copyright 2002 Free Software Foundation, Inc.
+#   Copyright 2002, 2003 Free Software Foundation, Inc.
 #
 # This file is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -20,6 +20,7 @@ if { [istarget mips*-*-*] } then {
 
     set elf [expr [istarget mips*-*-elf] || [istarget mips*-*-linux*] || \
 		  [istarget mips*-*-netbsd] || [istarget mips*-*-irix*]]
+    set linux_gnu [expr [istarget mips*-*-linux*]]
     set embedded_elf [expr [istarget mips*-*-elf]]
 
 
@@ -33,6 +34,13 @@ if { [istarget mips*-*-*] } then {
 	# Test multi-got link.
 	run_dump_test "multi-got-1"
     }
+
+    if { $linux_gnu } {
+	run_dump_test "rel32-o32"
+	run_dump_test "rel32-n32"
+	run_dump_test "rel64"
+    }
+
 
     if { $embedded_elf } {
 	# Check basic Embedded-PIC PC-relative HI/LO relocs.
Index: ld/testsuite/ld-mips-elf/rel32-n32.d
===================================================================
RCS file: ld/testsuite/ld-mips-elf/rel32-n32.d
diff -N ld/testsuite/ld-mips-elf/rel32-n32.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-mips-elf/rel32-n32.d 11 Mar 2003 18:01:52 -0000
@@ -0,0 +1,16 @@
+#name: MIPS rel32 n32
+#source: rel32.s
+#as: -KPIC -n32
+#readelf: -x 5 -r
+#ld: -shared -melf32btsmipn32
+
+Relocation section '.rel.dyn' at offset 0x3d0 contains 2 entries:
+ Offset     Info    Type            Sym.Value  Sym. Name
+00000000  00000000 R_MIPS_NONE      
+000003f0  00000003 R_MIPS_REL32     
+
+Hex dump of section '.text':
+  0x000003e0 00000000 00000000 00000000 00000000 ................
+  0x000003f0 000003f0 00000000 00000000 00000000 ................
+  0x00000400 00000000 00000000 00000000 00000000 ................
+  0x00000410 00000000 00000000 00000000 00000000 ................
Index: ld/testsuite/ld-mips-elf/rel32-o32.d
===================================================================
RCS file: ld/testsuite/ld-mips-elf/rel32-o32.d
diff -N ld/testsuite/ld-mips-elf/rel32-o32.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-mips-elf/rel32-o32.d 11 Mar 2003 18:01:52 -0000
@@ -0,0 +1,16 @@
+#name: MIPS rel32 o32
+#source: rel32.s
+#as: -KPIC -32
+#readelf: -x 6 -r
+#ld: -shared -melf32btsmip
+
+Relocation section '.rel.dyn' at offset 0x3e0 contains 2 entries:
+ Offset     Info    Type            Sym.Value  Sym. Name
+00000000  00000000 R_MIPS_NONE      
+00000400  00000003 R_MIPS_REL32     
+
+Hex dump of section '.text':
+  0x000003f0 00000000 00000000 00000000 00000000 ................
+  0x00000400 00000400 00000000 00000000 00000000 ................
+  0x00000410 00000000 00000000 00000000 00000000 ................
+  0x00000420 00000000 00000000 00000000 00000000 ................
Index: ld/testsuite/ld-mips-elf/rel32.s
===================================================================
RCS file: ld/testsuite/ld-mips-elf/rel32.s
diff -N ld/testsuite/ld-mips-elf/rel32.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-mips-elf/rel32.s 11 Mar 2003 18:01:52 -0000
@@ -0,0 +1,4 @@
+	.space 16
+.Lfoo:
+	.word .Lfoo
+	.space 16
Index: ld/testsuite/ld-mips-elf/rel64.d
===================================================================
RCS file: ld/testsuite/ld-mips-elf/rel64.d
diff -N ld/testsuite/ld-mips-elf/rel64.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-mips-elf/rel64.d 11 Mar 2003 18:01:52 -0000
@@ -0,0 +1,19 @@
+#name: MIPS rel64 n64
+#source: rel64.s
+#as: -KPIC -64
+#readelf: -x 6 -r
+#ld: -shared -melf64btsmip
+
+Relocation section '.rel.dyn' at offset 0x5b0 contains 2 entries:
+  Offset          Info           Type           Sym. Value    Sym. Name
+000000000000  000000000000 R_MIPS_NONE      
+                    Type2: R_MIPS_NONE      
+                    Type3: R_MIPS_NONE      
+0000000005e0  000000001203 R_MIPS_REL32     
+                    Type2: R_MIPS_64        
+                    Type3: R_MIPS_NONE      
+
+Hex dump of section '.text':
+  0x000005d0 00000000 00000000 00000000 00000000 ................
+  0x000005e0 00000000 000005e0 00000000 00000000 ................
+  0x000005f0 00000000 00000000 00000000 00000000 ................
Index: ld/testsuite/ld-mips-elf/rel64.s
===================================================================
RCS file: ld/testsuite/ld-mips-elf/rel64.s
diff -N ld/testsuite/ld-mips-elf/rel64.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-mips-elf/rel64.s 11 Mar 2003 18:01:52 -0000
@@ -0,0 +1,4 @@
+	.space 16
+.Lfoo:
+	.dword .Lfoo
+	.space 16

[-- Attachment #3: Type: text/plain, Size: 289 bytes --]


-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: mips rel32/64 to section symbol
  2003-03-11 18:05 ` Alexandre Oliva
@ 2003-03-11 18:41   ` Eric Christopher
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Christopher @ 2003-03-11 18:41 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: binutils

On Tue, 2003-03-11 at 10:05, Alexandre Oliva wrote:
> On Mar 10, 2003, Alexandre Oliva <aoliva@redhat.com> wrote:
> 
> > I'll put this in only [...] after I come up with testcases for
> > the linker to make sure this doesn't regress.
> 
> Here are the tests.  Ok to install?
> 

Yes.

-eric

-- 
Yeah, I used to play basketball...

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-03-11 18:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-11  2:48 mips rel32/64 to section symbol Alexandre Oliva
2003-03-11 18:05 ` Alexandre Oliva
2003-03-11 18:41   ` Eric Christopher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).