From b5eb05bb7221e5cc8358fa4923c4b205ec3186d4 Mon Sep 17 00:00:00 2001 From: Marius Strobl Date: Fri, 11 Mar 2011 20:00:38 +0000 Subject: [PATCH] In the upstream rev. 1.61 of elf64-sparc.c the following bug was fixed: * elf64-sparc.c (sparc64_elf_relocate_section): Adjust addend of dynamic relocs against section symbols for the output section vma. However, with the addition of TLS support in the upstream rev. 1.104 this fix was essentially reverted. After factoring out the common parts of elf32-sparc.c and elf64-sparc.c a comment was added to elfxx-sparc.c in the upstream rev. 1.27 as part of unrelated changes, saying that the fix from elf64-sparc.c rev. 1.61 indeed should be implemented, but given that some unspecified OS has a broken ld.so expecting broken relocations deliberately is omitted. As the current behavior actually violates the SPARC ABI, FreeBSD never had such a broken ld.so and this is actually causing problems with at least kernel modules linked with binutils 2.17.50 committed in r218822 without the workaround committed in r219340 in place, re-implement the above fix in a way so that is only applied if the output format is ELFOSABI_FREEBSD. In the upstream version it probably would make sense to invert this check and only skip adjusting the addend for the OS with the broken ld.so, once it's determine which one that is. Approved by: dim --- contrib/binutils/bfd/elfxx-sparc.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/contrib/binutils/bfd/elfxx-sparc.c b/contrib/binutils/bfd/elfxx-sparc.c index 708af290e3c..c411a48eea8 100644 --- a/contrib/binutils/bfd/elfxx-sparc.c +++ b/contrib/binutils/bfd/elfxx-sparc.c @@ -2474,11 +2474,13 @@ _bfd_sparc_elf_relocate_section (bfd *output_bfd, Elf_Internal_Rela *rel; Elf_Internal_Rela *relend; int num_relocs; + const struct elf_backend_data *bed; htab = _bfd_sparc_elf_hash_table (info); symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; sym_hashes = elf_sym_hashes (input_bfd); local_got_offsets = elf_local_got_offsets (input_bfd); + bed = get_elf_backend_data (output_bfd); if (elf_hash_table (info)->hgot == NULL) got_base = 0; @@ -2876,11 +2878,6 @@ _bfd_sparc_elf_relocate_section (bfd *output_bfd, { asection *osec; - /* We are turning this relocation into one - against a section symbol. It would be - proper to subtract the symbol's value, - osec->vma, from the emitted reloc addend, - but ld.so expects buggy relocs. */ osec = sec->output_section; indx = elf_section_data (osec)->dynindx; @@ -2901,6 +2898,15 @@ _bfd_sparc_elf_relocate_section (bfd *output_bfd, bfd_set_error (bfd_error_bad_value); return FALSE; } + + /* We are turning this relocation into one + against a section symbol, so subtract out + the output section's address but not the + offset of the input section in the output + section on OSes where ld.so doesn't expect + buggy relocs. */ + if (bed->elf_osabi == ELFOSABI_FREEBSD) + outrel.r_addend -= osec->vma; } outrel.r_info = SPARC_ELF_R_INFO (htab, rel, indx,