This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Fix double-counting of MIPS dynamic relocs
- From: Richard Sandiford <rdsandiford at googlemail dot com>
- To: binutils at sourceware dot org
- Date: Wed, 06 Aug 2008 21:00:28 +0100
- Subject: Fix double-counting of MIPS dynamic relocs
I was updating the GOT patches to work with:
http://sources.redhat.com/ml/binutils/2008-07/msg00350.html
and noticed that that patch double-counted relocations against
versioned symbols. The hash table callback is called for both
the indirect and direct definitions, and was reserving relocations
for both.
This is just a (small) pessimisation at the moment, but it
triggered an assert I added in the GOT patches.
Tested on mips64-linux-gnu (both with GCC and binutils).
OK to install?
Richard
bfd/
* elfxx-mips.c (allocate_dynrelocs): Ignore indirect and warning
symbols.
ld/testsuite/
* ld-mips-elf/reloc-estimate-1.d, ld-mips-elf/reloc-estimate-1.ld,
ld-mips-elf/reloc-estimate-1a.s, ld-mips-elf/reloc-estimate-1b.s:
New test.
* ld-mips-elf/mips-elf.exp: Run it.
Index: bfd/elfxx-mips.c
===================================================================
--- bfd/elfxx-mips.c 2008-08-06 20:52:58.000000000 +0100
+++ bfd/elfxx-mips.c 2008-08-06 20:57:18.000000000 +0100
@@ -7460,6 +7460,12 @@ allocate_dynrelocs (struct elf_link_hash
if (htab->is_vxworks && !info->shared)
return TRUE;
+ /* Ignore indirect and warning symbols. All relocations against
+ such symbols will be redirected to the target symbol. */
+ if (h->root.type == bfd_link_hash_indirect
+ || h->root.type == bfd_link_hash_warning)
+ return TRUE;
+
/* If this symbol is defined in a dynamic object, or we are creating
a shared library, we will need to copy any R_MIPS_32 or
R_MIPS_REL32 relocs against it into the output file. */
Index: ld/testsuite/ld-mips-elf/mips-elf.exp
===================================================================
--- ld/testsuite/ld-mips-elf/mips-elf.exp 2008-08-06 20:43:36.000000000 +0100
+++ ld/testsuite/ld-mips-elf/mips-elf.exp 2008-08-06 20:57:18.000000000 +0100
@@ -194,6 +194,7 @@ if { $linux_gnu } {
if $has_newabi {
run_dump_test "got-dump-2"
}
+ run_dump_test "reloc-estimate-1"
}
if $has_newabi {
Index: ld/testsuite/ld-mips-elf/reloc-estimate-1.d
===================================================================
--- /dev/null 2008-08-03 10:51:42.544096500 +0100
+++ ld/testsuite/ld-mips-elf/reloc-estimate-1.d 2008-08-06 20:57:18.000000000 +0100
@@ -0,0 +1,18 @@
+#name: MIPS reloc estimation 1
+#source: reloc-estimate-1a.s
+#source: reloc-estimate-1b.s
+#ld: -shared -T reloc-estimate-1.ld
+#objdump: -R -sj.foo
+
+.*
+
+DYNAMIC RELOCATION RECORDS
+OFFSET TYPE VALUE
+00000000 R_MIPS_NONE \*ABS\*
+00010000 R_MIPS_REL32 foo
+
+
+# The address must be 0x810. We should only ever allocate one dynamic
+# reloc over and above the first R_MIPS_NONE entry.
+Contents of section \.foo:
+ 0810 deadbeef ....
Index: ld/testsuite/ld-mips-elf/reloc-estimate-1.ld
===================================================================
--- /dev/null 2008-08-03 10:51:42.544096500 +0100
+++ ld/testsuite/ld-mips-elf/reloc-estimate-1.ld 2008-08-06 20:57:18.000000000 +0100
@@ -0,0 +1,29 @@
+SECTIONS
+{
+ . = 0;
+ .reginfo : { *(.reginfo) }
+
+ . = ALIGN (0x400);
+ .dynamic : { *(.dynamic) }
+ .dynsym : { *(.dynsym) }
+ .dynstr : { *(.dynstr) }
+
+ . = ALIGN (0x400);
+ .rel.dyn : { *(.rel.dyn) }
+ .foo : { *(.foo) }
+ .text : { *(.text) }
+
+ . = ALIGN (0x400);
+ .MIPS.stubs : { *(.MIPS.stubs) }
+
+ . = ALIGN (0x10000);
+ .data : { *(.data) }
+
+ . = ALIGN (0x400);
+ _gp = . + 0x7ff0;
+ .got : { *(.got) }
+}
+
+VERSION {
+ V2 { global: foo; local: *; };
+}
Index: ld/testsuite/ld-mips-elf/reloc-estimate-1a.s
===================================================================
--- /dev/null 2008-08-03 10:51:42.544096500 +0100
+++ ld/testsuite/ld-mips-elf/reloc-estimate-1a.s 2008-08-06 20:57:18.000000000 +0100
@@ -0,0 +1,6 @@
+ .section .foo,"a",@progbits
+ .word 0xdeadbeef
+
+ .abicalls
+ .data
+ .word foo
Index: ld/testsuite/ld-mips-elf/reloc-estimate-1b.s
===================================================================
--- /dev/null 2008-08-03 10:51:42.544096500 +0100
+++ ld/testsuite/ld-mips-elf/reloc-estimate-1b.s 2008-08-06 20:57:18.000000000 +0100
@@ -0,0 +1,7 @@
+ .abicalls
+ .symver foo2,foo@@V2
+ .global foo2
+ .data
+ .type foo2,%object
+ .size foo2,4
+foo2: .word 0