+
+ memcpy (i_shdrp, &i_shdr, sizeof (*i_shdrp));
+ shdrp = i_shdrp;
+ shindex = 0;
+ if (num_sec > SHN_LORESERVE)
+ {
+ for ( ; shindex < SHN_LORESERVE; shindex++)
+ elf_elfsections (abfd)[shindex] = shdrp++;
+ for ( ; shindex < SHN_HIRESERVE + 1; shindex++)
+ elf_elfsections (abfd)[shindex] = i_shdrp;
+ }
+ for ( ; 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 (! valid_section_index_p (i_shdrp[shindex].sh_link, num_sec))
+ 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)
+ && ! valid_section_index_p (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;
+ }
+ }
+
+ /* A further sanity check. */
+ if (i_ehdrp->e_shnum != 0)
+ {
+ if (! valid_section_index_p (i_ehdrp->e_shstrndx, elf_numsections (abfd)))
+ {
+ /* 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: %s has a corrupt string table index - ignoring"), abfd->filename);
+ }