This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Fix the size of .rel.dyn on MIPS
- From: Richard Sandiford <richard at codesourcery dot com>
- To: binutils at sourceware dot org
- Date: Thu, 19 Oct 2006 17:31:44 +0100
- Subject: Fix the size of .rel.dyn on MIPS
A few years ago, when trying to get binutils to work on IRIX, I found
that the n64 rtld would ignore all dynamic relocations before an
R_MIPS_NONE entry. Perhaps it walks back from the end of the
relocations to the beginning and assumes that the first null entry it
sees is the special null entry that starts the dynamic relocations.
(I think this would be ABI-conforming behaviour.)
Binutils sometimes allocates more dynamic relocations than it needs and
the unused slots are set to R_MIPS_NONE entries. However, because of
the above IRIX problem, I'd changed DT_RELSZ so that it didn't count
those relocs. This should also reduce dynamic linking time slightly.
However, I didn't change the size of the .rel.dyn section itself,
and the prelinker expects the two values to be the same.
Although it is possible to change the prelinker, I think the assumption
it makes is reasonable, and that this is really a fault in my IRIX patch.
Making .rel.dyn smaller will also make it more obvious that there is
spare room after the last useful relocation. In some cases, that spare
room might even be enough for the prelinker to do an in-place
REL-to-RELA conversion.
Tested on mips{,64}{,el}-{elf,linux-gnu} and mips-sgi-irix6.5.
OK to install?
Richard
bfd/
* elfxx-mips.c (_bfd_mips_elf_finish_dynamic_sections): Make the
size of .rel.dyn reflect the value of DT_RELSZ.
ld/testsuite/
* ld-mips-elf/multi-got-1.d: Remove trailing R_MIPS_NONE entries.
* ld-mips-elf/tls-multi-got-1.got: Likewise.
* ld-mips-elf/tls-multi-got-1.r: Likewise.
diff -udpr ../src.1/bfd/elfxx-mips.c ./bfd/elfxx-mips.c
--- ./bfd/elfxx-mips.c 2006-10-19 06:47:25.000000000 -0700
+++ ./bfd/elfxx-mips.c 2006-10-19 09:21:12.000000000 -0700
@@ -8873,6 +8873,10 @@ _bfd_mips_elf_finish_dynamic_sections (b
* (ABI_64_P (output_bfd)
? sizeof (Elf64_Mips_External_Rel)
: sizeof (Elf32_External_Rel)));
+ /* Adjust the section size too. Tools like the prelinker
+ can reasonably expect the values to the same. */
+ elf_section_data (s->output_section)->this_hdr.sh_size
+ = dyn.d_un.d_val;
break;
default:
diff -udpr ../src.1/ld/testsuite/ld-mips-elf/multi-got-1.d ./ld/testsuite/ld-mips-elf/multi-got-1.d
--- ./ld/testsuite/ld-mips-elf/multi-got-1.d 2006-10-19 06:47:25.000000000 -0700
+++ ./ld/testsuite/ld-mips-elf/multi-got-1.d 2006-10-19 09:22:43.000000000 -0700
@@ -25,7 +25,7 @@ Dynamic section at offset .* contains 17
0x70000013 \(MIPS_GOTSYM\) 0x[0-9a-f]+
0x00000000 \(NULL\) 0x0
-Relocation section '\.rel\.dyn' at offset 0x[0-9a-f]+ contains 8203 entries:
+Relocation section '\.rel\.dyn' at offset 0x[0-9a-f]+ contains 8193 entries:
Offset Info Type Sym.Value Sym. Name
00000000 00000000 R_MIPS_NONE
^[0-9a-f]+ [0-9a-f]+ R_MIPS_REL32 [0-9a-f]+ sym_2_[0-9]+
@@ -8220,13 +8220,3 @@ Relocation section '\.rel\.dyn' at offse
^[0-9a-f]+ [0-9a-f]+ R_MIPS_REL32 [0-9a-f]+ sym_2_[0-9]+
^[0-9a-f]+ [0-9a-f]+ R_MIPS_REL32 [0-9a-f]+ sym_2_[0-9]+
^[0-9a-f]+ [0-9a-f]+ R_MIPS_REL32 [0-9a-f]+ sym_2_[0-9]+
-00000000 00000000 R_MIPS_NONE
-00000000 00000000 R_MIPS_NONE
-00000000 00000000 R_MIPS_NONE
-00000000 00000000 R_MIPS_NONE
-00000000 00000000 R_MIPS_NONE
-00000000 00000000 R_MIPS_NONE
-00000000 00000000 R_MIPS_NONE
-00000000 00000000 R_MIPS_NONE
-00000000 00000000 R_MIPS_NONE
-00000000 00000000 R_MIPS_NONE
diff -udpr ../src.1/ld/testsuite/ld-mips-elf/tls-multi-got-1.got ./ld/testsuite/ld-mips-elf/tls-multi-got-1.got
--- ./ld/testsuite/ld-mips-elf/tls-multi-got-1.got 2006-10-19 06:47:25.000000000 -0700
+++ ./ld/testsuite/ld-mips-elf/tls-multi-got-1.got 2006-10-19 09:24:11.000000000 -0700
@@ -15,28 +15,6 @@ OFFSET TYPE VALUE
00143f7c R_MIPS_REL32 sym_1_9526
#...
00139bd0 R_MIPS_REL32 sym_2_8654
-00000000 R_MIPS_NONE \*ABS\*
-00000000 R_MIPS_NONE \*ABS\*
-00000000 R_MIPS_NONE \*ABS\*
-00000000 R_MIPS_NONE \*ABS\*
-00000000 R_MIPS_NONE \*ABS\*
-00000000 R_MIPS_NONE \*ABS\*
-00000000 R_MIPS_NONE \*ABS\*
-00000000 R_MIPS_NONE \*ABS\*
-00000000 R_MIPS_NONE \*ABS\*
-00000000 R_MIPS_NONE \*ABS\*
-00000000 R_MIPS_NONE \*ABS\*
-00000000 R_MIPS_NONE \*ABS\*
-00000000 R_MIPS_NONE \*ABS\*
-00000000 R_MIPS_NONE \*ABS\*
-00000000 R_MIPS_NONE \*ABS\*
-00000000 R_MIPS_NONE \*ABS\*
-00000000 R_MIPS_NONE \*ABS\*
-00000000 R_MIPS_NONE \*ABS\*
-00000000 R_MIPS_NONE \*ABS\*
-00000000 R_MIPS_NONE \*ABS\*
-00000000 R_MIPS_NONE \*ABS\*
-00000000 R_MIPS_NONE \*ABS\*
Contents of section .got:
diff -udpr ../src.1/ld/testsuite/ld-mips-elf/tls-multi-got-1.r ./ld/testsuite/ld-mips-elf/tls-multi-got-1.r
--- ./ld/testsuite/ld-mips-elf/tls-multi-got-1.r 2006-10-19 06:47:25.000000000 -0700
+++ ./ld/testsuite/ld-mips-elf/tls-multi-got-1.r 2006-10-19 09:23:11.000000000 -0700
@@ -20,7 +20,7 @@ Dynamic section at offset .* contains 18
0x0000001e \(FLAGS\) STATIC_TLS
0x00000000 \(NULL\) 0x0
-Relocation section '\.rel\.dyn' at offset 0x[0-9a-f]+ contains 20031 entries:
+Relocation section '\.rel\.dyn' at offset 0x[0-9a-f]+ contains 20009 entries:
Offset Info Type Sym.Value Sym. Name
[0-9a-f ]+R_MIPS_NONE
[0-9a-f ]+R_MIPS_TLS_DTPMOD
@@ -36,4 +36,3 @@ Relocation section '\.rel\.dyn' at offse
#...
[0-9a-f ]+R_MIPS_REL32 000cf2b4 sym_1_0465
[0-9a-f ]+R_MIPS_REL32 000e0ef8 sym_2_8654
-#...