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 collecting debug sections


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?

Regards
Senthil

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
+#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 ""


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