This is the mail archive of the
binutils-cvs@sourceware.org
mailing list for the binutils project.
[binutils-gdb] Work around sparc glibc bug
- From: Alan Modra <amodra at sourceware dot org>
- To: bfd-cvs at sourceware dot org
- Date: 8 Dec 2017 21:37:16 -0000
- Subject: [binutils-gdb] Work around sparc glibc bug
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a9d44aad42e127adadbad35f23931d8d83aa40c1
commit a9d44aad42e127adadbad35f23931d8d83aa40c1
Author: Alan Modra <amodra@gmail.com>
Date: Fri Dec 8 11:40:31 2017 +1030
Work around sparc glibc bug
* elfxx-sparc.c (_bfd_sparc_elf_relocate_section): When emitting
dynamic R_SPARC_RELATIVE for GOT entries, ensure the section
contents are zeroed.
Diff:
---
bfd/ChangeLog | 6 ++++++
bfd/elfxx-sparc.c | 26 +++++++++++++++-----------
2 files changed, 21 insertions(+), 11 deletions(-)
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 7f59fa0..69ca494 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2017-12-09 Alan Modra <amodra@gmail.com>
+
+ * elfxx-sparc.c (_bfd_sparc_elf_relocate_section): When emitting
+ dynamic R_SPARC_RELATIVE for GOT entries, ensure the section
+ contents are zeroed.
+
2017-12-08 Nick Clifton <nickc@redhat.com>
* elfcode.h (elf_write_relocs): Check for an empty howto field.
diff --git a/bfd/elfxx-sparc.c b/bfd/elfxx-sparc.c
index adc9ed3..9885059 100644
--- a/bfd/elfxx-sparc.c
+++ b/bfd/elfxx-sparc.c
@@ -3212,10 +3212,6 @@ _bfd_sparc_elf_relocate_section (bfd *output_bfd,
off &= ~1;
else
{
- SPARC_ELF_PUT_WORD (htab, output_bfd, relocation,
- htab->elf.sgot->contents + off);
- h->got.offset |= 1;
-
if (h->dynindx == -1
&& !h->forced_local
&& h->root.type != bfd_link_hash_undefweak
@@ -3225,6 +3221,10 @@ _bfd_sparc_elf_relocate_section (bfd *output_bfd,
generate R_SPARC_RELATIVE here. */
relative_reloc = TRUE;
}
+ else
+ SPARC_ELF_PUT_WORD (htab, output_bfd, relocation,
+ htab->elf.sgot->contents + off);
+ h->got.offset |= 1;
}
}
else
@@ -3245,12 +3245,10 @@ _bfd_sparc_elf_relocate_section (bfd *output_bfd,
else
{
if (bfd_link_pic (info))
- {
- relative_reloc = TRUE;
- }
-
- SPARC_ELF_PUT_WORD (htab, output_bfd, relocation,
- htab->elf.sgot->contents + off);
+ relative_reloc = TRUE;
+ else
+ SPARC_ELF_PUT_WORD (htab, output_bfd, relocation,
+ htab->elf.sgot->contents + off);
local_got_offsets[r_symndx] |= 1;
}
}
@@ -3271,8 +3269,14 @@ _bfd_sparc_elf_relocate_section (bfd *output_bfd,
outrel.r_info = SPARC_ELF_R_INFO (htab, NULL,
0, R_SPARC_RELATIVE);
outrel.r_addend = relocation;
- relocation = 0;
sparc_elf_append_rela (output_bfd, s, &outrel);
+ /* Versions of glibc ld.so at least up to 2.26 wrongly
+ add the section contents to the value calculated for
+ a RELATIVE reloc. Zero the contents to work around
+ this bug. */
+ relocation = 0;
+ SPARC_ELF_PUT_WORD (htab, output_bfd, relocation,
+ htab->elf.sgot->contents + off);
}
relocation = htab->elf.sgot->output_offset + off - got_base;