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 08:01:28AM -0700, H. J. Lu wrote:
> 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.

At write_section_eh_frame time it is too late, sure.
But at _bfd_elf_discard_section_eh_frame time it is not.
I meant something like:

2003-10-03  Jakub Jelinek  <jakub@redhat.com>

	* elf-eh-frame.c (_bfd_elf_discard_section_eh_frame): If .eh_frame
	section doesn't use "eh" CIEs nor DW_EH_PE_aligned encoding,
	decrease section alignment to byte alignment.

--- bfd/elf-eh-frame.c.jj	2003-08-10 21:56:07.000000000 +0200
+++ bfd/elf-eh-frame.c	2003-10-03 17:59:25.000000000 +0200
@@ -223,6 +223,7 @@ _bfd_elf_discard_section_eh_frame
   unsigned int make_relative, make_lsda_relative;
   bfd_size_type new_size;
   unsigned int ptr_size;
+  bfd_boolean needs_alignment = FALSE;
 
   if (sec->_raw_size == 0)
     {
@@ -256,6 +257,11 @@ _bfd_elf_discard_section_eh_frame
     {
       /* Empty .eh_frame section.  */
       free (ehbuf);
+      if (hdr_info->table && sec->alignment_power)
+	{
+	  sec->alignment_power = 0;
+	  return TRUE;
+	}
       return FALSE;
     }
 
@@ -423,6 +429,7 @@ _bfd_elf_discard_section_eh_frame
 		 Just skip it.  */
 	      buf += ptr_size;
 	      SKIP_RELOCS (buf);
+	      needs_alignment = TRUE;
 	    }
 	  read_uleb128 (cie.code_align, buf);
 	  read_sleb128 (cie.data_align, buf);
@@ -527,6 +534,11 @@ _bfd_elf_discard_section_eh_frame
 	  if (cie.fde_encoding == DW_EH_PE_omit)
 	    cie.fde_encoding = DW_EH_PE_absptr;
 
+	  if (cie.fde_encoding == DW_EH_PE_aligned
+	      || cie.lsda_encoding == DW_EH_PE_aligned
+	      || cie.per_encoding == DW_EH_PE_aligned)
+	    needs_alignment = TRUE;
+
 	  initial_insn_length = cie.hdr.length - (buf - last_fde - 4);
 	  if (initial_insn_length <= 50)
 	    {
@@ -644,6 +656,11 @@ _bfd_elf_discard_section_eh_frame
     sec->flags |= SEC_EXCLUDE;
 
   free (ehbuf);
+  if (!needs_alignment && sec->alignment_power)
+    {
+      sec->alignment_power = 0;
+      return TRUE;
+    }
   return new_size != sec->_raw_size;
 
 free_no_table:

in addition to your patch (which would handle the cases when there is
a DW_EH_PE_aligned encoding used somewhere or GCC 2.x style CIE/FDEs).

> 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.

Concerning your patch, shouldn't you check that
sec->_cooked_size + new_fill <= sec->_raw_size?
If it was not, then you'd be writing the nops beyond end of allocated
buffer.

	Jakub


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