This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Garbage collecting debug sections
- From: Senthil Kumar Selvaraj <senthil_kumar dot selvaraj at atmel dot com>
- To: "H.J. Lu" <hjl dot tools at gmail dot com>
- Cc: Nicholas Clifton <nickc at redhat dot com>, Binutils <binutils at sourceware dot org>, Alan Modra <amodra at gmail dot com>
- Date: Tue, 24 Mar 2015 19:18:04 +0530
- Subject: Re: Garbage collecting debug sections
- Authentication-results: sourceware.org; auth=none
- References: <20150323140414 dot GA1921 at atmel dot com> <551028BB dot 3010804 at redhat dot com> <CAMe9rOoL7n8dEefRad+NKreZYAQSws7F9=p8u-yPQkm9iN79ww at mail dot gmail dot com> <20150324115556 dot GA18728 at atmel dot com>
On Tue, Mar 24, 2015 at 05:25:57PM +0530, Senthil Kumar Selvaraj wrote:
> On Mon, Mar 23, 2015 at 07:56:43AM -0700, H.J. Lu wrote:
> > On Mon, Mar 23, 2015 at 7:52 AM, Nicholas Clifton <nickc@redhat.com> wrote:
> > > Hi Senthil,
> > >
> > >> However, it bails out after finding one such section (see attached
> > >> patch). Is this intentional?
> > >
> > >
> > > No, it is a bug. :-(
> > >
> > > When I was writing this code I was only interested in fragmentary
> > > .debug_line sections, and I failed to take into account that their might be
> > > other partial debug sections.
> > >
> > > Please feel free to commit an "obvious" patch to remove the "break;" from
> > > that loop.
> >
> > Please also add a testcase to show it is handled properly.
> >
>
> Here's the patch with a testcase, tested with x86_64 and avr targets.
> The test defines symbols in debug sections and expects them to be
> eliminated if the corresponding code section is removed.
>
> I don't have commit access - could someone commit it for me please?
Missed out a minor detail in the original testcase (missing -e _start).
bfd/ChangeLog
2015-03-24 Senthil Kumar Selvaraj <senthil_kumar.selvaraj@atmel.com>
* elflink.c (_bfd_elf_gc_mark_extra_sections): Don't break on
first matching debug section.
ld/testsuite/ChangeLog
2015-03-24 Senthil Kumar Selvaraj <senthil_kumar.selvaraj@atmel.com>
* ld-gc/all-debug-sections.d: New file.
* ld-gc/all-debug-sections.s: Likewise.
* ld-gc/gc.exp: Execute new testcase.
diff --git a/bfd/elflink.c b/bfd/elflink.c
index f93293b..9ccad8c 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -12102,7 +12102,6 @@ _bfd_elf_gc_mark_extra_sections (struct bfd_link_info *info,
isec->name, ilen) == 0)
{
dsec->gc_mark = 0;
- break;
}
}
}
diff --git a/ld/testsuite/ld-gc/all-debug-sections.d b/ld/testsuite/ld-gc/all-debug-sections.d
new file mode 100644
index 0000000..4db8b48
--- /dev/null
+++ b/ld/testsuite/ld-gc/all-debug-sections.d
@@ -0,0 +1,10 @@
+#name: --gc-sections with multiple debug sections for a function section
+#as: -gdwarf-sections
+#ld: --gc-sections -e _start
+#PROG: nm
+
+#...
+[0-9a-f]+ N +debug_aranges_main
+[0-9a-f]+ N +debug_info_main
+[0-9a-f]+ N +debug_line_main
+#...
diff --git a/ld/testsuite/ld-gc/all-debug-sections.s b/ld/testsuite/ld-gc/all-debug-sections.s
new file mode 100644
index 0000000..437e68a
--- /dev/null
+++ b/ld/testsuite/ld-gc/all-debug-sections.s
@@ -0,0 +1,56 @@
+.section .text.useless,"ax",@progbits
+.globl useless
+.type useless, @function
+useless:
+ .long 1
+
+.section .text.main,"ax",@progbits
+.globl _start
+_start:
+.globl main
+.type main, @function
+main:
+ .long 2
+
+.section .text,"ax",@progbits
+.long main
+
+.section .debug_info.text.main,"",@progbits
+debug_info_main:
+.long 0x3c
+.long main
+
+.section .debug_info.text.useless,"",@progbits
+debug_info_useless:
+.long 0x38
+.long useless
+
+.section .debug_info,"",@progbits
+.long 0x49
+
+.section .debug_aranges,"",@progbits
+.long 0x3c
+
+.section .debug_aranges.text.main,"",@progbits
+debug_aranges_main:
+.long 0x2c
+.long main
+
+.section .debug_aranges.text.useless,"",@progbits
+debug_aranges_useless:
+.long 0x2c
+.long useless
+
+.section .debug_line,"",@progbits
+.long 0x3c
+
+.section .debug_line.text.main,"",@progbits
+debug_line_main:
+.long 0x2c
+.long main
+
+.section .debug_line.text.useless,"",@progbits
+debug_line_useless:
+.long 0x2c
+.long useless
+
diff --git a/ld/testsuite/ld-gc/gc.exp b/ld/testsuite/ld-gc/gc.exp
index 5ff6485..58f3a2a 100644
--- a/ld/testsuite/ld-gc/gc.exp
+++ b/ld/testsuite/ld-gc/gc.exp
@@ -101,6 +101,9 @@ test_gc "Check --gc-section/-r/-u" "gcrel" $ld "-r --gc-sections -u used_func"
run_dump_test "noent"
run_dump_test "abi-note"
run_dump_test "start"
+if { [is_elf_format] } then {
+ run_dump_test "all-debug-sections"
+}
if { [is_elf_format] && [check_shared_lib_support] } then {
set gasopt ""