This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: PATCH: Re: EH frame optimization bug
On Thu, Oct 02, 2003 at 09:57:31PM -0400, Daniel Jacobowitz wrote:
> > > >
> > > > Something similar came up a few months ago but I can't find the reference
> > > > now. What's the right thing to do here? My instinct says, grow the last
> > > > FDE before the padding, but I have no idea how to do that. Is the alignment
> > > > of a .eh_frame section mandated?
> > >
> >
> > How about this patch?
>
> It seems reasonable, but I'd have thought that it would be safer/more
> useful to ignore old_fill.
>
Like this?
H.J.
----
2003-10-02 H.J. Lu <hongjiu.lu@intel.com>
* elf-eh-frame.c (_bfd_elf_write_section_eh_frame): Pad the
last CIE/FDE if needed.
--- bfd/elf-eh-frame.c.pad 2003-08-07 09:04:30.000000000 -0700
+++ bfd/elf-eh-frame.c 2003-10-02 22:31:48.000000000 -0700
@@ -1026,6 +1026,34 @@ _bfd_elf_write_section_eh_frame (bfd *ab
and 3xDW_CFA_nop as pad */
p += 16;
}
+ else
+ {
+ int new_fill = sec->_cooked_size % (1 << sec->alignment_power);
+
+ if (new_fill)
+ {
+ unsigned long length;
+
+ /* The size of the last FDE must be at least 4. */
+ if (sec_info->entry[sec_info->count - 1].size < 4)
+ abort ();
+
+ new_fill = (1 << sec->alignment_power) - new_fill;
+
+ buf = contents + sec_info->entry[sec_info->count - 1].new_offset;
+
+ /* Update length. */
+ length = bfd_get_32 (abfd, buf) + new_fill;
+ bfd_put_32 (abfd, length, buf);
+
+ /* Pad it with DW_CFA_nop */
+ memset (p, 0, new_fill);
+ p += new_fill;
+
+ sec_info->entry[sec_info->count - 1].size += new_fill;
+ sec->_cooked_size += new_fill;
+ }
+ }
BFD_ASSERT ((bfd_size_type) (p - contents) == sec->_cooked_size);