aboutsummaryrefslogtreecommitdiff
path: root/bfd/elflink.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2017-08-31 19:39:14 +0930
committerAlan Modra <amodra@gmail.com>2017-08-31 19:40:35 +0930
commit9866ffe25a0fe73f5153f2720650baf0dd9cc828 (patch)
treea376674444cbc25e4486a62c09be7f9151cff19d /bfd/elflink.c
parent654670a4f0928e3eddc6395d6804deb2e61a0614 (diff)
downloadfsf-binutils-gdb-9866ffe25a0fe73f5153f2720650baf0dd9cc828.zip
fsf-binutils-gdb-9866ffe25a0fe73f5153f2720650baf0dd9cc828.tar.gz
fsf-binutils-gdb-9866ffe25a0fe73f5153f2720650baf0dd9cc828.tar.bz2
Remove .eh_frame zero terminators
The machinery to do this was there, but not enabled if the terminator was the only thing in the section. bfd/ * elf-eh-frame.c (_bfd_elf_parse_eh_frame): Don't exit early for a section containing just a terminator. Allow multiple terminators at end of section. * elflink.c (bfd_elf_discard_info): Iterate over .eh_frame sections when not adding alignment. Assert on terminator in the middle of FDEs. ld/ * testsuite/ld-elf/eh3.d: Update. * testsuite/ld-elf/eh4.d: Update.
Diffstat (limited to 'bfd/elflink.c')
-rw-r--r--bfd/elflink.c57
1 files changed, 27 insertions, 30 deletions
diff --git a/bfd/elflink.c b/bfd/elflink.c
index f6f57fa..6008915 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -13862,39 +13862,36 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
fini_reloc_cookie_for_section (&cookie, i);
}
+
eh_alignment = 1 << o->alignment_power;
- if (eh_alignment > 4)
- {
- /* Skip over zero terminator, and prevent empty sections
- from adding alignment padding at the end. */
- for (i = o->map_tail.s; i != NULL; i = i->map_tail.s)
- if (i->size == 0)
- i->flags |= SEC_EXCLUDE;
- else if (i->size > 4)
- break;
- /* The last non-empty eh_frame section doesn't need padding. */
- if (i != NULL)
- i = i->map_tail.s;
- /* Any prior sections must pad the last FDE out to the
- output section alignment. Otherwise we might have zero
- padding between sections, which would be seen as a
- terminator. If there is a terminator in the middle of
- FDEs, don't increase its size as that will write bogus
- data of whatever was after the terminator in the input
- file, to the output file. */
- for (; i != NULL; i = i->map_tail.s)
- if (i->size != 4)
+ /* Skip over zero terminator, and prevent empty sections from
+ adding alignment padding at the end. */
+ for (i = o->map_tail.s; i != NULL; i = i->map_tail.s)
+ if (i->size == 0)
+ i->flags |= SEC_EXCLUDE;
+ else if (i->size > 4)
+ break;
+ /* The last non-empty eh_frame section doesn't need padding. */
+ if (i != NULL)
+ i = i->map_tail.s;
+ /* Any prior sections must pad the last FDE out to the output
+ section alignment. Otherwise we might have zero padding
+ between sections, which would be seen as a terminator. */
+ for (; i != NULL; i = i->map_tail.s)
+ if (i->size == 4)
+ /* All but the last zero terminator should have been removed. */
+ BFD_FAIL ();
+ else
+ {
+ bfd_size_type size
+ = (i->size + eh_alignment - 1) & -eh_alignment;
+ if (i->size != size)
{
- bfd_size_type size
- = (i->size + eh_alignment - 1) & -eh_alignment;
- if (i->size != size)
- {
- i->size = size;
- changed = 1;
- eh_changed = 1;
- }
+ i->size = size;
+ changed = 1;
+ eh_changed = 1;
}
- }
+ }
if (eh_changed)
elf_link_hash_traverse (elf_hash_table (info),
_bfd_elf_adjust_eh_frame_global_symbol, NULL);