+
+ memcpy (i_shdrp, &i_shdr, sizeof (*i_shdrp));
+ for (shdrp = i_shdrp, shindex = 0; shindex < num_sec; shindex++)
+ elf_elfsections (abfd)[shindex] = shdrp++;
+
+ /* Read in the rest of the section header table and convert it
+ to internal form. */
+ for (shindex = 1; shindex < i_ehdrp->e_shnum; shindex++)
+ {
+ if (bfd_bread (&x_shdr, sizeof x_shdr, abfd) != sizeof (x_shdr))
+ goto got_no_match;
+ elf_swap_shdr_in (abfd, &x_shdr, i_shdrp + shindex);
+
+ /* Sanity check sh_link and sh_info. */
+ if (i_shdrp[shindex].sh_link >= num_sec)
+ {
+ /* PR 10478: Accept Solaris binaries with a sh_link
+ field set to SHN_BEFORE or SHN_AFTER. */
+ switch (ebd->elf_machine_code)
+ {
+ case EM_386:
+ case EM_IAMCU:
+ case EM_X86_64:
+ 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
+ || i_shdrp[shindex].sh_type == SHT_REL)
+ && i_shdrp[shindex].sh_info >= num_sec)
+ goto got_wrong_format_error;
+
+ /* If the section is loaded, but not page aligned, clear
+ D_PAGED. */
+ if (i_shdrp[shindex].sh_size != 0
+ && (i_shdrp[shindex].sh_flags & SHF_ALLOC) != 0
+ && i_shdrp[shindex].sh_type != SHT_NOBITS
+ && (((i_shdrp[shindex].sh_addr - i_shdrp[shindex].sh_offset)
+ % ebd->minpagesize)
+ != 0))
+ abfd->flags &= ~D_PAGED;
+ }
+
+ if (i_ehdrp->e_shstrndx >= elf_numsections (abfd)
+ || i_shdrp[i_ehdrp->e_shstrndx].sh_type != SHT_STRTAB)
+ {
+ /* PR 2257:
+ We used to just goto got_wrong_format_error here
+ but there are binaries in existance for which this test
+ will prevent the binutils from working with them at all.
+ So we are kind, and reset the string index value to 0
+ so that at least some processing can be done. */
+ i_ehdrp->e_shstrndx = SHN_UNDEF;
+ _bfd_error_handler
+ (_("warning: %pB has a corrupt string table index - ignoring"),
+ abfd);
+ }