]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
garbage collect debug sections when no alloc sections are kept
authorAlan Modra <amodra@gmail.com>
Fri, 19 May 2017 03:10:10 +0000 (12:40 +0930)
committerAlan Modra <amodra@gmail.com>
Fri, 19 May 2017 08:19:34 +0000 (17:49 +0930)
The pr20882 testcase fails on a number of targets that add attribute
or note sections to object files, and the default linker script says
those sections should be kept.  This patch changes --gc-sections to
drop debug and special sections like .comment when no SEC_ALLOC
section in an object file is kept.  The assumption is that debug
sections are describing code and data that will become part of the
final image in memory.

* elflink.c (_bfd_elf_gc_mark_extra_sections): Don't keep
debug and special sections when no non-note alloc sections in an
object are kept.

bfd/ChangeLog
bfd/elflink.c

index a85199a65bfede74b1eb245f66b6d7497406ccc0..a5ec80a76e2aa748620327df6524ba5879dce76c 100644 (file)
@@ -1,3 +1,9 @@
+2017-05-19  Alan Modra  <amodra@gmail.com>
+
+       * elflink.c (_bfd_elf_gc_mark_extra_sections): Don't keep
+       debug and special sections when no non-note alloc sections in an
+       object are kept.
+
 2017-05-18  Alan Modra  <amodra@gmail.com>
 
        * arc-got.h: Don't compare boolean values against TRUE or FALSE.
index 387c6fdd135030e70538d60e5a3904afbd7d8322..71da4c9fd03eb47c7096812e5e58ec3b50a08921 100644 (file)
@@ -12961,7 +12961,9 @@ _bfd_elf_gc_mark_extra_sections (struct bfd_link_info *info,
        {
          if ((isec->flags & SEC_LINKER_CREATED) != 0)
            isec->gc_mark = 1;
-         else if (isec->gc_mark)
+         else if (isec->gc_mark
+                  && (isec->flags & SEC_ALLOC) != 0
+                  && elf_section_type (isec) != SHT_NOTE)
            some_kept = TRUE;
 
          if (!debug_frag_seen
@@ -12970,8 +12972,8 @@ _bfd_elf_gc_mark_extra_sections (struct bfd_link_info *info,
            debug_frag_seen = TRUE;
        }
 
-      /* If no section in this file will be kept, then we can
-        toss out the debug and special sections.  */
+      /* If no non-note alloc section in this file will be kept, then
+        we can toss out the debug and special sections.  */
       if (!some_kept)
        continue;