/* .eh_frame section optimization.
- Copyright 2001 Free Software Foundation, Inc.
+ Copyright 2001, 2002 Free Software Foundation, Inc.
Written by Jakub Jelinek <jakub@redhat.com>.
This file is part of BFD, the Binary File Descriptor library.
hdr_info->last_cie_offset = sec_info->entry[last_cie_ndx].new_offset;
}
+ /* FIXME: Currently it is not possible to shrink sections to zero size at
+ this point, so build a fake minimal CIE. */
+ if (new_size == 0)
+ new_size = 16;
+
/* Shrink the sec as needed. */
-
sec->_cooked_size = new_size;
if (sec->_cooked_size == 0)
sec->flags |= SEC_EXCLUDE;
+ sec_info->entry[mid].lsda_offset)))
return (bfd_vma) -1;
- return (offset
- + (sec_info->entry[mid].new_offset - sec_info->entry[mid].offset));
+ return (offset + sec_info->entry[mid].new_offset
+ - sec_info->entry[mid].offset);
}
/* Write out .eh_frame section. This is called with the relocated
{
if (sec_info->entry[i].cie)
{
- cie_offset = sec_info->entry[i].new_offset;
- cie_offset += (sec_info->entry[i].sec->output_section->vma
- + sec_info->entry[i].sec->output_offset
- - sec->output_section->vma
- - sec->output_offset);
+ /* If CIE is removed due to no remaining FDEs referencing it
+ and there were no CIEs kept before it, sec_info->entry[i].sec
+ will be zero. */
+ if (sec_info->entry[i].sec == NULL)
+ cie_offset = 0;
+ else
+ {
+ cie_offset = sec_info->entry[i].new_offset;
+ cie_offset += (sec_info->entry[i].sec->output_section->vma
+ + sec_info->entry[i].sec->output_offset
+ - sec->output_section->vma
+ - sec->output_offset);
+ }
}
continue;
}
+
if (sec_info->entry[i].cie)
{
/* CIE */
p += sec_info->entry[i].size;
}
+ /* FIXME: Once _bfd_elf_discard_section_eh_frame will be able to
+ shrink sections to zero size, this won't be needed any more. */
+ if (p == contents && sec->_cooked_size == 16)
+ {
+ bfd_put_32 (abfd, 12, p); /* Fake CIE length */
+ bfd_put_32 (abfd, 0, p + 4); /* Fake CIE id */
+ p[8] = 1; /* Fake CIE version */
+ memset (p + 9, 0, 7); /* Fake CIE augmentation, 3xleb128
+ and 3xDW_CFA_nop as pad */
+ p += 16;
+ }
+
BFD_ASSERT ((bfd_size_type) (p - contents) == sec->_cooked_size);
return bfd_set_section_contents (abfd, sec->output_section,
== ELF_INFO_TYPE_EH_FRAME_HDR);
hdr_info = (struct eh_frame_hdr_info *)
elf_section_data (sec)->sec_info;
+ if (hdr_info->strip)
+ return true;
+
size = EH_FRAME_HDR_SIZE;
if (hdr_info->array && hdr_info->array_count == hdr_info->fde_count)
size += 4 + hdr_info->fde_count * 8;