bfd_elf_discard_info is only called once. Well, it was until commit
9b854f169df9 introduced cmdline_emit_object_only_section, but I think
and hope that function does enough reinitialisation to not cause a
problem. There would be a problem if bfd_elf_discard_info was called
iteratively, shrinking an eh_frame section on the first pass, then
further shrinking on another pass. That's because
_bfd_elf_discard_section_eh_frame uses rawsize to store the last
section size, which is against the general rules for input sections.
rawsize needs to be kept as the initial size to be able to read
section contents again (or you'd need to cache the edited contents).
Other eh_frame functions would break too.
So this tidy makes it obvious when looking at
_bfd_elf_discard_section_eh_frame alone that rawsize is only set once,
to the initial size. There are no functional changes here.
* elf-bfd.h (_bfd_elf_discard_section_eh_frame): Update decl.
* elf-eh-frame.c (_bfd_elf_discard_section_eh_frame): Return
an int status. Don't set rawsize unless it is zero.
* elflink.c (bfd_elf_discard_info): Use new return status
from _bfd_elf_discard_section_eh_frame rather than comparing
section size with rawsize.
extern bool _bfd_elf_end_eh_frame_parsing
(struct bfd_link_info *info) ATTRIBUTE_HIDDEN;
-extern bool _bfd_elf_discard_section_eh_frame
+extern int _bfd_elf_discard_section_eh_frame
(bfd *, struct bfd_link_info *, asection *,
bool (*) (bfd_vma, void *), struct elf_reloc_cookie *) ATTRIBUTE_HIDDEN;
extern bool _bfd_elf_adjust_eh_frame_global_symbol
}
/* This function is called for each input file before the .eh_frame
- section is relocated. It discards duplicate CIEs and FDEs for discarded
- functions. The function returns TRUE iff any entries have been
- deleted. */
+ section is relocated. It discards duplicate CIEs and FDEs for
+ discarded functions. The function returns 0 when no changes are
+ made, 1 when .eh_frame data has been edited and 2 when the editing
+ results in a section size change. */
-bool
+int
_bfd_elf_discard_section_eh_frame
(bfd *abfd, struct bfd_link_info *info, asection *sec,
bool (*reloc_symbol_deleted_p) (bfd_vma, void *),
eh_alignment = 4;
offset = (offset + eh_alignment - 1) & -eh_alignment;
- sec->rawsize = sec->size;
+ if (sec->rawsize == 0)
+ sec->rawsize = sec->size;
+ if (sec->size != offset)
+ changed = 2;
sec->size = offset;
- if (sec->size != sec->rawsize)
- changed = 1;
if (changed)
{
for (i = o->map_head.s; i != NULL; i = i->map_head.s)
{
+ int r;
+
if (i->size == 0)
continue;
return -1;
_bfd_elf_parse_eh_frame (abfd, info, i, &cookie);
- if (_bfd_elf_discard_section_eh_frame (abfd, info, i,
+ r = _bfd_elf_discard_section_eh_frame (abfd, info, i,
bfd_elf_reloc_symbol_deleted_p,
- &cookie))
+ &cookie);
+ if (r)
{
eh_changed = 1;
- if (i->size != i->rawsize)
+ if (r >= 2)
changed = 1;
}