From 27e200d1792d17772c81d4390d94a3bf9bc997ec Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Wed, 9 Sep 2009 15:03:51 +0000 Subject: PR 10478: * elf.c (bfd_section_from_shdr): Do not reject sparc binaries with section headers containing sh_link values of SHN_BEFORE or SHN_AFTER. * elfcode.h (elf_object_p): Likewise. readelf.c (get_elf_section_flags): Add support for SHF_EXCLUDE and SHF_ORDERED. (process_section_headers): Warn about out of range sh_link values. When displaying detailed section header information annote the SHN_BEFORE and SHN_AFTER values. --- bfd/ChangeLog | 9 ++++++++- bfd/elf.c | 20 +++++++++++++++++--- bfd/elfcode.h | 18 +++++++++++++++++- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 39ee6fd19a2..82a663bf916 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,11 @@ +2009-09-09 Nick Clifton + + PR 10478: + * elf.c (bfd_section_from_shdr): Do not reject sparc binaries with + section headers containing sh_link values of SHN_BEFORE or + SHN_AFTER. + * elfcode.h (elf_object_p): Likewise. + 2009-09-09 Tristan Gingold Handle DYLD_INFO introduced by Darwin10. @@ -12,7 +20,6 @@ (bfd_mach_o_load_command_name): AddB FD_MACH_O_LC_DYLD_INFO. (bfd_mach_o_print_dyld_info): New function. - 2009-09-09 M R Swami Reddy * elf32-cr16.c (elf32_cr16_relocate_section): Add code to discard the diff --git a/bfd/elf.c b/bfd/elf.c index 13f690465ee..ed974c0176b 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -1514,10 +1514,24 @@ bfd_section_from_shdr (bfd *abfd, unsigned int shindex) case SHT_DYNAMIC: /* Dynamic linking information. */ if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) return FALSE; - if (hdr->sh_link > elf_numsections (abfd) - || elf_elfsections (abfd)[hdr->sh_link] == NULL) + if (hdr->sh_link > elf_numsections (abfd)) + { + /* PR 10478: Accept sparc binaries with a sh_link + field set to SHN_BEFORE or SHN_AFTER. */ + switch (bfd_get_arch (abfd)) + { + case bfd_arch_sparc: + if (hdr->sh_link == (SHN_LORESERVE & 0xffff) /* SHN_BEFORE */ + || hdr->sh_link == ((SHN_LORESERVE + 1) & 0xffff) /* SHN_AFTER */) + break; + /* Otherwise fall through. */ + default: + return FALSE; + } + } + else if (elf_elfsections (abfd)[hdr->sh_link] == NULL) return FALSE; - if (elf_elfsections (abfd)[hdr->sh_link]->sh_type != SHT_STRTAB) + else if (elf_elfsections (abfd)[hdr->sh_link]->sh_type != SHT_STRTAB) { Elf_Internal_Shdr *dynsymhdr; diff --git a/bfd/elfcode.h b/bfd/elfcode.h index 10aa13140e7..889d25ab736 100644 --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -760,7 +760,23 @@ elf_object_p (bfd *abfd) /* Sanity check sh_link and sh_info. */ if (i_shdrp[shindex].sh_link >= num_sec) - goto got_wrong_format_error; + { + /* PR 10478: Accept sparc binaries with a sh_link + field set to SHN_BEFORE or SHN_AFTER. */ + switch (ebd->elf_machine_code) + { + case EM_OLD_SPARCV9: + case EM_SPARC32PLUS: + case EM_SPARCV9: + case EM_SPARC: + if (i_shdrp[shindex].sh_link == (SHN_LORESERVE & 0xffff) /* SHN_BEFORE */ + || i_shdrp[shindex].sh_link == ((SHN_LORESERVE + 1) & 0xffff) /* SHN_AFTER */) + break; + /* Otherwise fall through. */ + default: + goto got_wrong_format_error; + } + } if (((i_shdrp[shindex].sh_flags & SHF_INFO_LINK) || i_shdrp[shindex].sh_type == SHT_RELA -- cgit v1.2.1