Elf_Internal_Ehdr *i_ehdrp;
const struct elf_backend_data *bed;
+ /* Skip non-load sections without section header. */
+ if ((abfd->flags & BFD_NO_SECTION_HEADER) != 0)
+ return true;
+
off = elf_next_file_pos (abfd);
shdrpp = elf_elfsections (abfd);
num_sec = elf_numsections (abfd);
for (count = 1; count < num_sec; count++)
{
- i_shdrp[count]->sh_name
- = _bfd_elf_strtab_offset (elf_shstrtab (abfd),
- i_shdrp[count]->sh_name);
+ /* Don't set the sh_name field without section header. */
+ if ((abfd->flags & BFD_NO_SECTION_HEADER) == 0)
+ i_shdrp[count]->sh_name
+ = _bfd_elf_strtab_offset (elf_shstrtab (abfd),
+ i_shdrp[count]->sh_name);
if (bed->elf_backend_section_processing)
if (!(*bed->elf_backend_section_processing) (abfd, i_shdrp[count]))
return false;
/* Write out the section header names. */
t = elf_tdata (abfd);
if (elf_shstrtab (abfd) != NULL
+ && t->shstrtab_hdr.sh_offset != -1
&& (bfd_seek (abfd, t->shstrtab_hdr.sh_offset, SEEK_SET) != 0
|| !_bfd_elf_strtab_emit (abfd, elf_shstrtab (abfd))))
return false;
return true;
}
+ /* Remove non-alloc sections for --strip-section-headers. */
+ if (strip_section_headers
+ && (bfd_section_flags (sec) & SEC_ALLOC) == 0)
+ return true;
+
if ((bfd_section_flags (sec) & SEC_DEBUGGING) != 0)
{
if (strip_symbols == STRIP_DEBUG
if (strip_section_headers)
{
- non_fatal (_("--strip_section_headers is unsupported on `%s'"),
+ non_fatal (_("--strip-section-headers is unsupported on `%s'"),
bfd_get_archive_filename (ibfd));
return false;
}