This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
garbage collect debug sections when no alloc sections are kept
- From: Alan Modra <amodra at gmail dot com>
- To: binutils at sourceware dot org
- Cc: Nick Clifton <nickc at redhat dot com>
- Date: Thu, 18 May 2017 23:06:05 +0930
- Subject: garbage collect debug sections when no alloc sections are kept
- Authentication-results: sourceware.org; auth=none
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.
Does this seem reasonable? I can think of situations where the
heuristic will fail, for instance when an object file has .text.foo
that isn't alloc due to a luser getting a .section directive wrong.
That text section would normally become part of the alloc .text
output, but we can't test the output because garbage collection runs
before mapping input sections to output. I'm not so worried about
that case but whether I might be overlooking some target wrinkle
regarding non-alloc sections and debug..
Will commit tomorrow if no one points out a problem. Cures all the
pr20882 fails except for crx and xgate, which have broken relocation
addend processing.
* elflink.c (_bfd_elf_gc_mark_extra_sections): Don't keep
debug and special sections when no alloc sections in an object
are kept.
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 387c6fd..b03dc47 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -12961,7 +12961,7 @@ _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)
some_kept = TRUE;
if (!debug_frag_seen
@@ -12970,7 +12970,7 @@ _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
+ /* If no 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