Fix placement of .rel.dyn on MIPS

Richard Sandiford richard@codesourcery.com
Thu Oct 19 18:21:00 GMT 2006


One unusual thing about the MIPS bfd backend is that it puts all its
dynamic relocations in a single dynobj section (rather than putting
relocations against .foo in .rel(a).foo).  It does this so that it
can easily sort the dynamic relocations before the output .rel.dyn
has been populated.

The linker scripts do not handle an input .rel.dyn section, so this
dynobj section gets placed as an orphan.

Tested on mips{,64}{,el}-{elf,linux-gnu} and mips-sgi-irix6.5.
OK to install?

Richard


ld/
	* emulparams/elf32bmip.sh (OTHER_GOT_RELOC_SECTIONS): Define.
	* emulparams/elf32bmipn32-defs.sh (OTHER_GOT_RELOC_SECTIONS): Likewise.

ld/testsuite/
	* ld-mips-elf/rel32-o32.d: Bump the section number of .text by 1
	to account for the fact that .rel.dyn is now before .text in the
	section table.
	* ld-mips-elf/rel32-n32.d: Likewise.
	* ld-mips-elf/rel64.d: Likewise.

diff -udpr ../src.1/ld/emulparams/elf32bmipn32-defs.sh ./ld/emulparams/elf32bmipn32-defs.sh
--- ./ld/emulparams/elf32bmipn32-defs.sh	2006-10-19 09:04:21.000000000 -0700
+++ ./ld/emulparams/elf32bmipn32-defs.sh	2006-10-19 08:38:10.000000000 -0700
@@ -37,6 +37,13 @@ TEXT_START_ADDR=0x10000000
 MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
 ENTRY=__start
 
+# Unlike most targets, the MIPS backend puts all dynamic relocations
+# in a single dynobj section, which it also calls ".rel.dyn".  It does
+# this so that it can easily sort all dynamic relocations before the
+# output section has been populated.
+OTHER_GOT_RELOC_SECTIONS="
+  .rel.dyn      ${RELOCATING-0} : { *(.rel.dyn) }
+"
 # GOT-related settings.  
 # If the output has a GOT section, there must be exactly 0x7ff0 bytes
 # between .got and _gp.  The ". = ." below stops the orphan code from
diff -udpr ../src.1/ld/emulparams/elf32bmip.sh ./ld/emulparams/elf32bmip.sh
--- ./ld/emulparams/elf32bmip.sh	2006-10-19 09:04:21.000000000 -0700
+++ ./ld/emulparams/elf32bmip.sh	2006-10-19 08:38:10.000000000 -0700
@@ -20,6 +20,13 @@ INITIAL_READONLY_SECTIONS="${INITIAL_REA
   .reginfo      ${RELOCATING-0} : { *(.reginfo) }
 "
 OTHER_TEXT_SECTIONS='*(.mips16.fn.*) *(.mips16.call.*)'
+# Unlike most targets, the MIPS backend puts all dynamic relocations
+# in a single dynobj section, which it also calls ".rel.dyn".  It does
+# this so that it can easily sort all dynamic relocations before the
+# output section has been populated.
+OTHER_GOT_RELOC_SECTIONS="
+  .rel.dyn      ${RELOCATING-0} : { *(.rel.dyn) }
+"
 # If the output has a GOT section, there must be exactly 0x7ff0 bytes
 # between .got and _gp.  The ". = ." below stops the orphan code from
 # inserting other sections between the assignment to _gp and the start
diff -udpr ../src.1/ld/testsuite/ld-mips-elf/rel32-n32.d ./ld/testsuite/ld-mips-elf/rel32-n32.d
--- ./ld/testsuite/ld-mips-elf/rel32-n32.d	2006-10-19 09:05:36.000000000 -0700
+++ ./ld/testsuite/ld-mips-elf/rel32-n32.d	2006-10-19 09:01:23.000000000 -0700
@@ -1,7 +1,7 @@
 #name: MIPS rel32 n32
 #source: rel32.s
 #as: -KPIC -EB -n32
-#readelf: -x 6 -r
+#readelf: -x 7 -r
 #ld: -shared -melf32btsmipn32
 
 Relocation section '.rel.dyn' at offset .* contains 2 entries:
diff -udpr ../src.1/ld/testsuite/ld-mips-elf/rel32-o32.d ./ld/testsuite/ld-mips-elf/rel32-o32.d
--- ./ld/testsuite/ld-mips-elf/rel32-o32.d	2006-10-19 09:05:36.000000000 -0700
+++ ./ld/testsuite/ld-mips-elf/rel32-o32.d	2006-10-19 09:01:07.000000000 -0700
@@ -1,7 +1,7 @@
 #name: MIPS rel32 o32
 #source: rel32.s
 #as: -KPIC -EB -32
-#readelf: -x 6 -r
+#readelf: -x 7 -r
 #ld: -shared -melf32btsmip
 
 Relocation section '.rel.dyn' at offset .* contains 2 entries:
diff -udpr ../src.1/ld/testsuite/ld-mips-elf/rel64.d ./ld/testsuite/ld-mips-elf/rel64.d
--- ./ld/testsuite/ld-mips-elf/rel64.d	2006-10-19 09:05:36.000000000 -0700
+++ ./ld/testsuite/ld-mips-elf/rel64.d	2006-10-19 09:01:35.000000000 -0700
@@ -1,7 +1,7 @@
 #name: MIPS rel64 n64
 #source: rel64.s
 #as: -KPIC -EB -64
-#readelf: -x 6 -r
+#readelf: -x 7 -r
 #ld: -shared -melf64btsmip
 
 Relocation section '.rel.dyn' at offset .* contains 2 entries:



More information about the Binutils mailing list