]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PR21441, Unnecessary padding of .eh_frame section
authorAlan Modra <amodra@gmail.com>
Sun, 13 Aug 2017 23:55:17 +0000 (09:25 +0930)
committerAlan Modra <amodra@gmail.com>
Tue, 19 Sep 2017 05:09:48 +0000 (14:39 +0930)
Until all .eh_frame sections have been edited we don't know their
sizes.  So it isn't possible to properly decide whether a non-empty
.eh_frame section follows a given section until editing is complete.

bfd/
PR 21441
* elf-eh-frame.c (_bfd_elf_discard_section_eh_frame): Don't add
alignment padding here.
* elflink.c (bfd_elf_discard_info): Add .eh_frame padding here
in a reverse pass over sections.
ld/
PR 21441
* testsuite/ld-x86-64/pr21038a.d: Adjust.
* testsuite/ld-x86-64/pr21038a-now.d: Adjust.

(cherry picked from commit 79a94a2ad1e6e2f227de07427481e4bb8be84504)

bfd/ChangeLog
bfd/elf-eh-frame.c
bfd/elflink.c
ld/ChangeLog
ld/testsuite/ld-x86-64/pr21038a-now.d
ld/testsuite/ld-x86-64/pr21038a.d

index 40bcac93e3ec6466cb1a170ab18485fc7f6846b5..73377b9173395b37079349abae4becf771b7d596 100644 (file)
@@ -1,3 +1,11 @@
+2017-08-14  Alan Modra  <amodra@gmail.com>
+
+       PR 21441
+       * elf-eh-frame.c (_bfd_elf_discard_section_eh_frame): Don't add
+       alignment padding here.
+       * elflink.c (bfd_elf_discard_info): Add .eh_frame padding here
+       in a reverse pass over sections.
+
 2017-09-04  Nick Clifton  <nickc@redhat.com>
 
 2017-09-18  H.J. Lu  <hongjiu.lu@intel.com>
index 52ba9c62138bb7d2c8901d961ba322dbfe23e220..7e0d63f569d04fa19c0d6b9fe7d17d4696f6123b 100644 (file)
@@ -1594,16 +1594,7 @@ _bfd_elf_discard_section_eh_frame
        offset += size_of_output_cie_fde (ent);
       }
 
-  /* Pad the last FDE out to the output section alignment if there are
-     following sections, in order to ensure no padding between this
-     section and the next.  (Relies on the output section alignment
-     being the maximum of all input sections alignments, which is the
-     case unless someone is overriding alignment via scripts.)  */
   eh_alignment = 4;
-  if (sec->map_head.s != NULL
-      && (sec->map_head.s->size != 4
-         || sec->map_head.s->map_head.s != NULL))
-    eh_alignment = 1 << sec->output_section->alignment_power;
   offset = (offset + eh_alignment - 1) & -eh_alignment;
   sec->rawsize = sec->size;
   sec->size = offset;
index 736fb4c2f7fb40ee9e4badb0922bf260928980f5..6bab097b0574131f8e7d76cf927a4b976f228188 100644 (file)
@@ -13831,6 +13831,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
     {
       asection *i;
       int eh_changed = 0;
+      unsigned int eh_alignment;
 
       for (i = o->map_head.s; i != NULL; i = i->map_head.s)
        {
@@ -13856,6 +13857,34 @@ 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.  */
+         for (; i != NULL; i = i->map_tail.s)
+           {
+             bfd_size_type size = (i->size + eh_alignment - 1) & -eh_alignment;
+             if (i->size != size)
+               {
+                 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);
index f513008c2e1ad341a53dadbc2a4f18f154d1c787..56ce18b85a64a7fcacc632bd172bf1a8de0a4eb1 100644 (file)
@@ -1,3 +1,9 @@
+2017-08-14  Alan Modra  <amodra@gmail.com>
+
+       PR 21441
+       * testsuite/ld-x86-64/pr21038a.d: Adjust.
+       * testsuite/ld-x86-64/pr21038a-now.d: Adjust.
+
 2017-09-18  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/21924
index ebc512887a104bd64053752ae18aeeac22f6c4b8..6948ded162df6a467f4b6c97d590044fd0982bb1 100644 (file)
@@ -41,11 +41,7 @@ Contents of the .eh_frame section:
   DW_CFA_nop
   DW_CFA_nop
 
-0+58 0000000000000014 0000005c FDE cie=00000000 pc=0000000000000230..0000000000000238
-  DW_CFA_nop
-  DW_CFA_nop
-  DW_CFA_nop
-  DW_CFA_nop
+0+58 0000000000000010 0000005c FDE cie=00000000 pc=0000000000000230..0000000000000238
   DW_CFA_nop
   DW_CFA_nop
   DW_CFA_nop
index 81b26cb53c9c383e4a55f93a91e3b2295e53f27c..7b1b7dcd4c1eb2ac3ae103674609e45aafd88844 100644 (file)
@@ -40,11 +40,7 @@ Contents of the .eh_frame section:
   DW_CFA_nop
   DW_CFA_nop
 
-0+58 0000000000000014 0000005c FDE cie=00000000 pc=0000000000000230..0000000000000238
-  DW_CFA_nop
-  DW_CFA_nop
-  DW_CFA_nop
-  DW_CFA_nop
+0+58 0000000000000010 0000005c FDE cie=00000000 pc=0000000000000230..0000000000000238
   DW_CFA_nop
   DW_CFA_nop
   DW_CFA_nop