This is the mail archive of the binutils@sourceware.org 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: garbage collect debug sections when no alloc sections are kept


On Thu, May 18, 2017 at 07:26:33AM -0700, H.J. Lu wrote:
> On Thu, May 18, 2017 at 6:36 AM, Alan Modra <amodra@gmail.com> wrote:
> >         * elflink.c (_bfd_elf_gc_mark_extra_sections): Don't keep
> >         debug and special sections when no alloc sections in an object
> >         are kept.
> 
> This doesn't work on .note.gnu.property section since it has SEC_ALLOC:

True.  Let's omit notes too.  Committing.

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index a85199a..a5ec80a 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -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.
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 387c6fd..71da4c9 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -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;
 


-- 
Alan Modra
Australia Development Lab, IBM


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