This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: Re: EH frame optimization bug


On Fri, Oct 03, 2003 at 07:12:24AM -0700, H. J. Lu wrote:
> On Fri, Oct 03, 2003 at 07:20:09AM +0200, Jakub Jelinek wrote:
> > On Thu, Oct 02, 2003 at 10:36:42PM -0700, H. J. Lu wrote:
> > > 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?
> > 
> > Well, the primary thing is that for .eh_frame (as opposed to .debug_frame)
> > unless some FDE/CIE uses somewhere DW_EH_PE_aligned encoding or unless
> > GCC 2.x style FDE/CIEs are present I don't see why there should be any
> > padding in the .eh_frame section.
> > So IMHO if ld detects there are no such things in the .eh_frame section
> > (or even better just that the following CIE/FDE doesn't really need to be
> > aligned), it should remove any padding.
> > 
> 
> The problem is the section alignment. It is what your patch:
> 
> http://sources.redhat.com/ml/binutils/2003-06/msg00643.html
> 
> tried to fix. I don't think .eh_frame should get any special treatment.
> 

I think it is too late to remove paddings in _bfd_elf_write_section_eh_frame.
The only thing we can do at this point is to pad the current section
for the next section, which is aligned.

Here is an updated patch to make sure the last kept entry is padded.

H.J.
----
2003-10-03  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-03 07:08:24.000000000 -0700
@@ -1026,6 +1026,37 @@ _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)
+	{
+	  /* Find the last CIE/FDE.  */
+	  for (i = sec_info->count - 1; i > 0; i--)
+	    if (! sec_info->entry[i].removed)
+	      break;
+
+	  /* The size of the last CIE/FDE must be at least 4.  */
+	  if (sec_info->entry[i].removed
+	      || sec_info->entry[i].size < 4)
+	    abort ();
+
+	  new_fill = (1 << sec->alignment_power) - new_fill;
+
+	  buf = contents + sec_info->entry[i].new_offset;
+
+	  /* Update length.  */
+	  sec_info->entry[i].size += new_fill;
+	  bfd_put_32 (abfd, sec_info->entry[i].size - 4, buf);
+
+	  /* Pad it with DW_CFA_nop  */
+	  memset (p, 0, new_fill);
+	  p += new_fill;
+
+	  sec->_cooked_size += new_fill;
+	}
+    }
 
   BFD_ASSERT ((bfd_size_type) (p - contents) == sec->_cooked_size);
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]