public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PATCH: PR gas/10531: Strange assembler warning message on section  group
@ 2009-08-18  4:09 H.J. Lu
  2009-08-18  5:40 ` Alan Modra
  2009-08-19  3:08 ` Jim Wilson
  0 siblings, 2 replies; 20+ messages in thread
From: H.J. Lu @ 2009-08-18  4:09 UTC (permalink / raw)
  To: binutils

Hi,

We can't use bfd_get_section_by_name, subseg_new and subseg_get directly
in dwarf2dbg.c since they don't know ELF section groups.  This patch adds
obj_get_section_by_name, obj_subseg_new and obj_subseg_get.  Tested on
Linux/ia32, Linux/ia64 and Linux/Intel64.  OK to install?

Thanks.


H.J.
----
gas/

2009-08-18  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * dwarf2dbg.c (obj_get_section_by_name): New.
	 (obj_subseg_new): Likewise.
	 (obj_subseg_get): Likewise.
	 (emit_fixed_inc_line_addr): Use obj_subseg_get instead of
	 subseg_get.
	 (dwarf2_finish): Use obj_get_section_by_name instead of
	 bfd_get_section_by_name.  Use obj_subseg_new instead of
	 subseg_get.

	 * config/obj-elf.c (obj_elf_get_section_by_name): New.
	 (obj_elf_subseg_new): Likewise.
	 (obj_elf_subseg_get): Likewise.
	 * config/obj-elf.c (obj_get_section_by_name): Likewise.
	 (obj_subseg_new): Likewise.
	 (obj_subseg_get): Likewise.
	 (obj_elf_get_section_by_name): Likewise.
	 (obj_elf_subseg_new): Likewise.
	 (obj_elf_subseg_get): Likewise.

gas/testsuite/

2009-08-18  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * gas/elf/group2.d: New.
	 * gas/elf/group2.s: Likewise.
	 * gas/i386/debug1.d: Likewise.
	 * gas/i386/debug1.s: Likewise.

	* gas/elf/elf.exp: Run group2.

	* gas/i386/i386.exp: Run debug1 for both 32bit and 64bit.

--- gas/config/obj-elf.c.dw2	2009-08-17 14:03:39.000000000 -0700
+++ gas/config/obj-elf.c	2009-08-17 15:54:33.000000000 -0700
@@ -550,6 +550,43 @@ get_section (bfd *abfd ATTRIBUTE_UNUSED,
 	      && strcmp (group_name, gname) == 0));
 }
 
+/* Similar to bfd_get_section_by_name.  Don't return a section in a
+   section group.  */
+
+asection *
+obj_elf_get_section_by_name (bfd *abfd, const char *name)
+{
+  return bfd_get_section_by_name_if (abfd, name, get_section, NULL);
+}
+
+/* Similar to subseg_new.  Don't return a section in a section group.  */
+
+segT
+obj_elf_subseg_new (const char *segname, subsegT subseg)
+{
+  segT sec;
+
+  if (bfd_get_section_by_name_if (stdoutput, segname, get_section,
+				  NULL) != NULL)
+    sec = subseg_new (segname, subseg);
+  else
+    sec = subseg_force_new (segname, subseg);
+  return sec;
+}
+
+/* Similar to subseg_get.  Don't return a section in a section group.  */
+
+segT
+obj_elf_subseg_get (const char *segname, int force_new)
+{
+  return subseg_get (segname,
+		     (force_new
+		      || bfd_get_section_by_name_if (stdoutput,
+						     segname,
+						     get_section,
+						     NULL) == NULL));
+}
+
 /* Handle the .section pseudo-op.  This code supports two different
    syntaxes.
 
--- gas/config/obj-elf.h.dw2	2009-02-03 11:30:05.000000000 -0800
+++ gas/config/obj-elf.h	2009-08-17 15:32:10.000000000 -0700
@@ -249,4 +249,19 @@ extern asection *elf_com_section_ptr;
 extern symbolS * elf_common_parse (int ignore ATTRIBUTE_UNUSED, symbolS *symbolP,
 				   addressT size);
 
+#ifndef obj_get_section_by_name
+#define obj_get_section_by_name obj_elf_get_section_by_name
+#endif
+extern asection *obj_elf_get_section_by_name (bfd *, const char *);
+
+#ifndef obj_subseg_new
+#define obj_subseg_new	obj_elf_subseg_new
+#endif
+extern segT obj_elf_subseg_new (const char *, subsegT);
+
+#ifndef obj_subseg_get
+#define obj_subseg_get	obj_elf_subseg_get
+#endif
+extern segT obj_elf_subseg_get (const char *, subsegT);
+
 #endif /* _OBJ_ELF_H */
--- gas/dwarf2dbg.c.dw2	2009-07-29 19:45:04.000000000 -0700
+++ gas/dwarf2dbg.c	2009-08-17 15:31:23.000000000 -0700
@@ -46,6 +46,19 @@
 #include "dwarf2dbg.h"
 #include <filenames.h>
 
+
+#ifndef obj_get_section_by_name
+#define obj_get_section_by_name	bfd_get_section_by_name
+#endif
+
+#ifndef obj_subseg_new
+#define obj_subseg_new	subseg_new
+#endif
+
+#ifndef obj_subseg_get
+#define obj_subseg_get	subseg_get
+#endif
+
 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
 /* We need to decide which character to use as a directory separator.
    Just because HAVE_DOS_BASED_FILE_SYSTEM is defined, it does not
@@ -1062,7 +1075,7 @@ emit_fixed_inc_line_addr (int line_delta
     }
 
   exp = symbol_get_value_expression (frag->fr_symbol);
-  line_seg = subseg_get (".debug_line", 0);
+  line_seg = obj_subseg_get (".debug_line", 0);
 
   /* The DW_LNS_fixed_advance_pc opcode has a 2-byte operand so it can
      advance the address by at most 64K.  Linker relaxation (without
@@ -1718,7 +1731,7 @@ dwarf2_finish (void)
   segT info_seg;
   int emit_other_sections = 0;
 
-  info_seg = bfd_get_section_by_name (stdoutput, ".debug_info");
+  info_seg = obj_get_section_by_name (stdoutput, ".debug_info");
   emit_other_sections = info_seg == NULL || !seg_not_empty_p (info_seg);
 
   if (!all_segs && emit_other_sections)
@@ -1730,7 +1743,7 @@ dwarf2_finish (void)
   sizeof_address = DWARF2_ADDR_SIZE (stdoutput);
 
   /* Create and switch to the line number section.  */
-  line_seg = subseg_new (".debug_line", 0);
+  line_seg = obj_subseg_new (".debug_line", 0);
   bfd_set_section_flags (stdoutput, line_seg, SEC_READONLY | SEC_DEBUGGING);
 
   /* For each subsection, chain the debug entries together.  */
@@ -1759,9 +1772,9 @@ dwarf2_finish (void)
 
       gas_assert (all_segs);
 
-      info_seg = subseg_new (".debug_info", 0);
-      abbrev_seg = subseg_new (".debug_abbrev", 0);
-      aranges_seg = subseg_new (".debug_aranges", 0);
+      info_seg = obj_subseg_new (".debug_info", 0);
+      abbrev_seg = obj_subseg_new (".debug_abbrev", 0);
+      aranges_seg = obj_subseg_new (".debug_aranges", 0);
 
       bfd_set_section_flags (stdoutput, info_seg,
 			     SEC_READONLY | SEC_DEBUGGING);
@@ -1776,7 +1789,7 @@ dwarf2_finish (void)
 	ranges_seg = NULL;
       else
 	{
-	  ranges_seg = subseg_new (".debug_ranges", 0);
+	  ranges_seg = obj_subseg_new (".debug_ranges", 0);
 	  bfd_set_section_flags (stdoutput, ranges_seg,
 				 SEC_READONLY | SEC_DEBUGGING);
 	  record_alignment (ranges_seg, ffs (2 * sizeof_address) - 1);
--- gas/testsuite/gas/elf/elf.exp.dw2	2009-08-17 16:02:32.000000000 -0700
+++ gas/testsuite/gas/elf/elf.exp	2009-08-17 15:41:32.000000000 -0700
@@ -100,6 +100,7 @@ if { ([istarget "*-*-*elf*"]		
     run_dump_test "group0b" 
     run_dump_test "group1a" 
     run_dump_test "group1b" 
+    run_dump_test "group2" 
     case $target_triplet in {
 	{ alpha*-*-* } { }
 	{ cr16*-*-* } { }
--- gas/testsuite/gas/elf/group2.d.dw2	2009-08-17 15:41:27.000000000 -0700
+++ gas/testsuite/gas/elf/group2.d	2009-08-17 15:21:32.000000000 -0700
@@ -0,0 +1,16 @@
+#readelf: -SWg
+#name: group section with debug sections
+
+
+#...
+[ 	]*\[.*\][ 	]+foo[ 	]+GROUP.*
+#...
+[ 	]*\[.*\][ 	]+\.debug_info[ 	]+PROGBITS.*[ 	]+G[ 	]+.*
+[ 	]*\[.*\][ 	]+\.debug_line[ 	]+PROGBITS.*[ 	]+G[ 	]+.*
+[ 	]*\[.*\][ 	]+\.debug_line[ 	]+PROGBITS.*[ 	]+.*
+#...
+COMDAT group section \[    1\] `foo' \[foo\] contains 2 sections:
+[ 	]+\[Index\][ 	]+Name
+[ 	]+\[.*\][ 	]+.debug_info
+[ 	]+\[.*\][ 	]+.debug_line
+#pass
--- gas/testsuite/gas/elf/group2.s.dw2	2009-08-17 15:41:27.000000000 -0700
+++ gas/testsuite/gas/elf/group2.s	2009-08-17 15:22:25.000000000 -0700
@@ -0,0 +1,6 @@
+	.section .debug_info
+	.byte 0x0
+	.section .debug_info,"G",%progbits,foo,comdat
+	.byte 0x0
+	.section .debug_line,"G",%progbits,foo,comdat
+	.byte 0x0
--- gas/testsuite/gas/i386/debug1.d.dw2	2009-08-17 14:13:05.000000000 -0700
+++ gas/testsuite/gas/i386/debug1.d	2009-08-17 15:47:50.000000000 -0700
@@ -0,0 +1,19 @@
+#as: -g
+#readelf: -SWg
+#name: group section with debug sections
+
+
+#...
+[ 	]*\[.*\][ 	]+foo[ 	]+GROUP.*
+#...
+[ 	]*\[.*\][ 	]+\.debug_info[ 	]+PROGBITS.*[ 	]+G[ 	]+.*
+[ 	]*\[.*\][ 	]+\.debug_line[ 	]+PROGBITS.*[ 	]+G[ 	]+.*
+[ 	]*\[.*\][ 	]+\.debug_line[ 	]+PROGBITS.*[ 	]+.*
+#...
+[ 	]*\[.*\][ 	]+\.debug_info[ 	]+PROGBITS.*[ 	]+.*
+#...
+COMDAT group section \[    1\] `foo' \[foo\] contains 2 sections:
+[ 	]+\[Index\][ 	]+Name
+[ 	]+\[.*\][ 	]+.debug_info
+[ 	]+\[.*\][ 	]+.debug_line
+#pass
--- gas/testsuite/gas/i386/debug1.s.dw2	2009-08-17 14:13:08.000000000 -0700
+++ gas/testsuite/gas/i386/debug1.s	2009-08-17 15:40:48.000000000 -0700
@@ -0,0 +1,11 @@
+	.section .debug_info,"G",%progbits,foo,comdat
+	.byte 0x0
+	.section .debug_line,"G",%progbits,foo,comdat
+	.byte 0x0
+	.section .debug_info,"G",@progbits,foo,comdat
+	.byte 0x0
+	.section .debug_line,"G",@progbits,foo,comdat
+	.byte 0x0
+	.text
+	nop
+	nop
--- gas/testsuite/gas/i386/i386.exp.dw2	2009-07-29 19:45:07.000000000 -0700
+++ gas/testsuite/gas/i386/i386.exp	2009-08-17 15:58:49.000000000 -0700
@@ -190,6 +190,7 @@ if [expr ([istarget "i*86-*-*"] ||  [ist
 	run_list_test "inval-equ-2" "-al"
 	run_dump_test "ifunc"
 	run_list_test "l1om-inval" "-march=l1om --32"
+	run_dump_test "debug1"
     }
 
     # This is a PE specific test.
@@ -348,6 +349,7 @@ if [expr ([istarget "i*86-*-*"] || [ista
 	run_dump_test "mixed-mode-reloc64"
 	run_dump_test "x86-64-ifunc"
 	run_dump_test "l1om"
+	run_dump_test "debug1"
     }
 
     set ASFLAGS "$old_ASFLAGS"

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: PATCH: PR gas/10531: Strange assembler warning message on  section  group
  2009-08-18  4:09 PATCH: PR gas/10531: Strange assembler warning message on section group H.J. Lu
@ 2009-08-18  5:40 ` Alan Modra
  2009-08-18 16:41   ` H.J. Lu
  2009-08-19  3:08 ` Jim Wilson
  1 sibling, 1 reply; 20+ messages in thread
From: Alan Modra @ 2009-08-18  5:40 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

On Mon, Aug 17, 2009 at 04:07:21PM -0700, H.J. Lu wrote:
> We can't use bfd_get_section_by_name, subseg_new and subseg_get directly
> in dwarf2dbg.c since they don't know ELF section groups.  This patch adds
> obj_get_section_by_name, obj_subseg_new and obj_subseg_get.  Tested on
> Linux/ia32, Linux/ia64 and Linux/Intel64.  OK to install?

Have you tested this with a multi-obj assembler?  I suspect that
something like x86-as --em=i386coff --gdwarf-2 will attempt to
access elf-only data structures.  (That's a slightly ridiculous
set of command line options for x86, but we shouldn't have gas
segfault.)  I think the proper patch needs some new fields in
struct format_ops and defines in obj-multi.h.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: PATCH: PR gas/10531: Strange assembler warning message on section   group
  2009-08-18  5:40 ` Alan Modra
@ 2009-08-18 16:41   ` H.J. Lu
  2009-08-18 17:44     ` Daniel Jacobowitz
  0 siblings, 1 reply; 20+ messages in thread
From: H.J. Lu @ 2009-08-18 16:41 UTC (permalink / raw)
  To: H.J. Lu, binutils

[-- Attachment #1: Type: text/plain, Size: 1892 bytes --]

On Mon, Aug 17, 2009 at 8:12 PM, Alan Modra<amodra@bigpond.net.au> wrote:
> On Mon, Aug 17, 2009 at 04:07:21PM -0700, H.J. Lu wrote:
>> We can't use bfd_get_section_by_name, subseg_new and subseg_get directly
>> in dwarf2dbg.c since they don't know ELF section groups.  This patch adds
>> obj_get_section_by_name, obj_subseg_new and obj_subseg_get.  Tested on
>> Linux/ia32, Linux/ia64 and Linux/Intel64.  OK to install?
>
> Have you tested this with a multi-obj assembler?  I suspect that
> something like x86-as --em=i386coff --gdwarf-2 will attempt to
> access elf-only data structures.  (That's a slightly ridiculous
> set of command line options for x86, but we shouldn't have gas
> segfault.)  I think the proper patch needs some new fields in
> struct format_ops and defines in obj-multi.h.
>

strcmp can't be used to check if 2 ELF sections have the same name.
I added bfd_section_name_eq.  OK to install?

Thanks.

-- 
H.J.
---
bfd/

2009-08-18  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * section.c: Include "elf-bfd.h".
	 (bfd_section_name_eq): New.
	 (bfd_get_section_by_name): Don't use a section in a section
	 group.
	 (bfd_make_section_old_way): Likewise.

	* bfd-in2.h: Regenerated.

gas/

2009-08-18  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * ehopt.c (get_cie_info): Use bfd_section_name_eq to check if
	 section names are the same.
	 (check_eh_frame): Likewise.
	 * read.c (emit_expr): Likewise.
	 (stringer): Likewise.
	 * stabs.c (s_stab_generic): Likewise.
	 * subsegs.c (subseg_get): Likewise.

gas/testsuite/

2009-08-18  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * gas/elf/group2.d: New.
	 * gas/elf/group2.s: Likewise.
	 * gas/i386/debug1.d: Likewise.
	 * gas/i386/debug1.s: Likewise.

	* gas/elf/elf.exp: Run group2.

	* gas/i386/i386.exp: Run debug1 for both 32bit and 64bit.

[-- Attachment #2: binutils-group-1.patch --]
[-- Type: text/plain, Size: 11292 bytes --]

bfd/

2009-08-18  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * section.c: Include "elf-bfd.h".
	 (bfd_section_name_eq): New.
	 (bfd_get_section_by_name): Don't use a section in a section
	 group.
	 (bfd_make_section_old_way): Likewise.

	* bfd-in2.h: Regenerated.

gas/

2009-08-18  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * ehopt.c (get_cie_info): Use bfd_section_name_eq to check if
	 section name is the same.
	 (check_eh_frame): Likewise.
	 * read.c (emit_expr): Likewise.
	 (stringer): Likewise.
	 * stabs.c (s_stab_generic): Likewise.
	 * subsegs.c (subseg_get): Likewise.

gas/testsuite/

2009-08-18  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * gas/elf/group2.d: New.
	 * gas/elf/group2.s: Likewise.
	 * gas/i386/debug1.d: Likewise.
	 * gas/i386/debug1.s: Likewise.

	* gas/elf/elf.exp: Run group2.

	* gas/i386/i386.exp: Run debug1 for both 32bit and 64bit.

Index: gas/read.c
===================================================================
--- gas/read.c	(revision 6552)
+++ gas/read.c	(working copy)
@@ -3979,7 +3979,7 @@ emit_expr (expressionS *exp, unsigned in
   {
     static int dwarf_line = -1;
 
-    if (strcmp (segment_name (now_seg), ".line") != 0)
+    if (bfd_section_name_eq (stdoutput, now_seg, ".line"))
       dwarf_line = -1;
     else if (dwarf_line >= 0
 	     && nbytes == 2
@@ -4002,7 +4002,7 @@ emit_expr (expressionS *exp, unsigned in
   {
     static int dwarf_file = 0;
 
-    if (strcmp (segment_name (now_seg), ".debug") != 0)
+    if (bfd_section_name_eq (stdoutput, now_seg, ".debug"))
       dwarf_file = 0;
     else if (dwarf_file == 0
 	     && nbytes == 2
@@ -5144,7 +5144,7 @@ stringer (int bits_appendzero)
 	     emit_expr for the sequence.  emit_expr will set
 	     dwarf_file_string to non-zero if this string might be a
 	     source file name.  */
-	  if (strcmp (segment_name (now_seg), ".debug") != 0)
+	  if (bfd_section_name_eq (stdoutput, now_seg, ".debug"))
 	    dwarf_file_string = 0;
 	  else if (dwarf_file_string)
 	    {
Index: gas/testsuite/gas/i386/i386.exp
===================================================================
--- gas/testsuite/gas/i386/i386.exp	(revision 6552)
+++ gas/testsuite/gas/i386/i386.exp	(working copy)
@@ -190,6 +190,7 @@ if [expr ([istarget "i*86-*-*"] ||  [ist
 	run_list_test "inval-equ-2" "-al"
 	run_dump_test "ifunc"
 	run_list_test "l1om-inval" "-march=l1om --32"
+	run_dump_test "debug1"
     }
 
     # This is a PE specific test.
@@ -348,6 +349,7 @@ if [expr ([istarget "i*86-*-*"] || [ista
 	run_dump_test "mixed-mode-reloc64"
 	run_dump_test "x86-64-ifunc"
 	run_dump_test "l1om"
+	run_dump_test "debug1"
     }
 
     set ASFLAGS "$old_ASFLAGS"
Index: gas/testsuite/gas/i386/debug1.d
===================================================================
--- gas/testsuite/gas/i386/debug1.d	(revision 0)
+++ gas/testsuite/gas/i386/debug1.d	(revision 0)
@@ -0,0 +1,19 @@
+#as: -g
+#readelf: -SWg
+#name: group section with debug sections
+
+
+#...
+[ 	]*\[.*\][ 	]+foo[ 	]+GROUP.*
+#...
+[ 	]*\[.*\][ 	]+\.debug_info[ 	]+PROGBITS.*[ 	]+G[ 	]+.*
+[ 	]*\[.*\][ 	]+\.debug_line[ 	]+PROGBITS.*[ 	]+G[ 	]+.*
+[ 	]*\[.*\][ 	]+\.debug_line[ 	]+PROGBITS.*[ 	]+.*
+#...
+[ 	]*\[.*\][ 	]+\.debug_info[ 	]+PROGBITS.*[ 	]+.*
+#...
+COMDAT group section \[    1\] `foo' \[foo\] contains 2 sections:
+[ 	]+\[Index\][ 	]+Name
+[ 	]+\[.*\][ 	]+.debug_info
+[ 	]+\[.*\][ 	]+.debug_line
+#pass
Index: gas/testsuite/gas/i386/debug1.s
===================================================================
--- gas/testsuite/gas/i386/debug1.s	(revision 0)
+++ gas/testsuite/gas/i386/debug1.s	(revision 0)
@@ -0,0 +1,11 @@
+	.section .debug_info,"G",%progbits,foo,comdat
+	.byte 0x0
+	.section .debug_line,"G",%progbits,foo,comdat
+	.byte 0x0
+	.section .debug_info,"G",@progbits,foo,comdat
+	.byte 0x0
+	.section .debug_line,"G",@progbits,foo,comdat
+	.byte 0x0
+	.text
+	nop
+	nop
Index: gas/testsuite/gas/elf/group2.s
===================================================================
--- gas/testsuite/gas/elf/group2.s	(revision 0)
+++ gas/testsuite/gas/elf/group2.s	(revision 0)
@@ -0,0 +1,6 @@
+	.section .debug_info
+	.byte 0x0
+	.section .debug_info,"G",%progbits,foo,comdat
+	.byte 0x0
+	.section .debug_line,"G",%progbits,foo,comdat
+	.byte 0x0
Index: gas/testsuite/gas/elf/group2.d
===================================================================
--- gas/testsuite/gas/elf/group2.d	(revision 0)
+++ gas/testsuite/gas/elf/group2.d	(revision 0)
@@ -0,0 +1,16 @@
+#readelf: -SWg
+#name: group section with debug sections
+
+
+#...
+[ 	]*\[.*\][ 	]+foo[ 	]+GROUP.*
+#...
+[ 	]*\[.*\][ 	]+\.debug_info[ 	]+PROGBITS.*[ 	]+G[ 	]+.*
+[ 	]*\[.*\][ 	]+\.debug_line[ 	]+PROGBITS.*[ 	]+G[ 	]+.*
+[ 	]*\[.*\][ 	]+\.debug_line[ 	]+PROGBITS.*[ 	]+.*
+#...
+COMDAT group section \[    1\] `foo' \[foo\] contains 2 sections:
+[ 	]+\[Index\][ 	]+Name
+[ 	]+\[.*\][ 	]+.debug_info
+[ 	]+\[.*\][ 	]+.debug_line
+#pass
Index: gas/testsuite/gas/elf/elf.exp
===================================================================
--- gas/testsuite/gas/elf/elf.exp	(revision 6552)
+++ gas/testsuite/gas/elf/elf.exp	(working copy)
@@ -100,6 +100,7 @@ if { ([istarget "*-*-*elf*"]		
     run_dump_test "group0b" 
     run_dump_test "group1a" 
     run_dump_test "group1b" 
+    run_dump_test "group2" 
     case $target_triplet in {
 	{ alpha*-*-* } { }
 	{ cr16*-*-* } { }
Index: gas/stabs.c
===================================================================
--- gas/stabs.c	(revision 6552)
+++ gas/stabs.c	(working copy)
@@ -307,7 +307,6 @@ s_stab_generic (int what, char *stab_sec
       char *p;
 
       static segT cached_sec;
-      static char *cached_secname;
 
       dot = frag_now_fix ();
 
@@ -315,7 +314,8 @@ s_stab_generic (int what, char *stab_sec
       md_flush_pending_output ();
 #endif
 
-      if (cached_secname && !strcmp (cached_secname, stab_secname))
+      if (cached_sec
+	  && bfd_section_name_eq (stdoutput, cached_sec, stab_secname))
 	{
 	  seg = cached_sec;
 	  subseg_set (seg, 0);
@@ -323,9 +323,6 @@ s_stab_generic (int what, char *stab_sec
       else
 	{
 	  seg = subseg_new (stab_secname, 0);
-	  if (cached_secname)
-	    free (cached_secname);
-	  cached_secname = xstrdup (stab_secname);
 	  cached_sec = seg;
 	}
 
Index: gas/ehopt.c
===================================================================
--- gas/ehopt.c	(revision 6552)
+++ gas/ehopt.c	(working copy)
@@ -120,7 +120,7 @@ get_cie_info (struct cie_info *info)
 
   /* First make sure that the CIE Identifier Tag is 0/-1.  */
 
-  if (strcmp (segment_name (now_seg), ".debug_frame") == 0)
+  if (bfd_section_name_eq (stdoutput, now_seg, ".debug_frame"))
     CIE_id = (char)0xff;
   else
     CIE_id = 0;
@@ -283,9 +283,9 @@ check_eh_frame (expressionS *exp, unsign
 #endif
 
   /* Select the proper section data.  */
-  if (strcmp (segment_name (now_seg), ".eh_frame") == 0)
+  if (bfd_section_name_eq (stdoutput, now_seg, ".eh_frame"))
     d = &eh_frame_data;
-  else if (strcmp (segment_name (now_seg), ".debug_frame") == 0)
+  else if (bfd_section_name_eq (stdoutput, now_seg, ".debug_frame"))
     d = &debug_frame_data;
   else
     return 0;
Index: gas/subsegs.c
===================================================================
--- gas/subsegs.c	(revision 6552)
+++ gas/subsegs.c	(working copy)
@@ -148,14 +148,10 @@ subseg_get (const char *segname, int for
 {
   segT secptr;
   segment_info_type *seginfo;
-  const char *now_seg_name = (now_seg
-			      ? bfd_get_section_name (stdoutput, now_seg)
-			      : 0);
 
   if (!force_new
-      && now_seg_name
-      && (now_seg_name == segname
-	  || !strcmp (now_seg_name, segname)))
+      && now_seg
+      && bfd_section_name_eq (stdoutput, now_seg, segname))
     return now_seg;
 
   if (!force_new)
Index: bfd/section.c
===================================================================
--- bfd/section.c	(revision 6552)
+++ bfd/section.c	(working copy)
@@ -138,6 +138,7 @@ SUBSECTION
 #include "bfd.h"
 #include "libbfd.h"
 #include "bfdlink.h"
+#include "elf-bfd.h"
 
 /*
 DOCDD
@@ -834,6 +835,31 @@ bfd_section_list_clear (bfd *abfd)
 
 /*
 FUNCTION
+	bfd_section_name_eq
+
+SYNOPSIS
+	bfd_boolean bfd_section_name_eq
+	  (bfd *abfd, asection *sec, const char *name);
+
+DESCRIPTION
+	Return <<TRUE>> if the name of section @var{sec} is the same as
+	@var{name}, otherwise <<FALSE>>.
+*/
+
+bfd_boolean
+bfd_section_name_eq (bfd *abfd, asection *sec, const char *name)
+{
+  /* Return FALSE if SEC is a member of ELF section group. */
+  if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
+      && elf_section_data (sec) != NULL
+      && elf_group_name (sec) != NULL)
+    return FALSE;
+  else
+    return strcmp (bfd_section_name (abfd, sec), name) == 0;
+}
+
+/*
+FUNCTION
 	bfd_get_section_by_name
 
 SYNOPSIS
@@ -854,11 +880,31 @@ asection *
 bfd_get_section_by_name (bfd *abfd, const char *name)
 {
   struct section_hash_entry *sh;
+  unsigned long hash;
+  asection *sec;
 
   sh = section_hash_lookup (&abfd->section_htab, name, FALSE, FALSE);
-  if (sh != NULL)
+  if (sh == NULL)
+    return NULL;
+
+  /* Only ELF has section group. */
+  if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
     return &sh->section;
 
+  hash = sh->root.hash;
+  do
+    {
+      sec = &sh->section;
+      /* Don't return a section in a section group.  */
+      if (elf_section_data (sec) == NULL
+	  || elf_group_name (sec) == NULL)
+	return sec;
+      sh = (struct section_hash_entry *) sh->root.next;
+    }
+  while (sh != NULL
+	 && sh->root.hash == hash
+	 && strcmp (sh->root.string, name) == 0);
+
   return NULL;
 }
 
@@ -1011,7 +1057,43 @@ bfd_make_section_old_way (bfd *abfd, con
       if (sh == NULL)
 	return NULL;
 
-      newsect = &sh->section;
+      /* Only ELF has section group. */
+      if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+	{
+	  struct section_hash_entry *old_sh = sh;
+	  unsigned long hash = sh->root.hash;
+
+	  do
+	    {
+	      newsect = &sh->section;
+	      /* Don't use a section in a section group.  */
+	      if (elf_section_data (newsect) == NULL
+		  || elf_group_name (newsect) == NULL)
+		break;
+	      sh = (struct section_hash_entry *) sh->root.next;
+	    }
+	  while (sh != NULL
+		 && sh->root.hash == hash
+		 && strcmp (sh->root.string, name) == 0);
+
+	  if (sh == NULL)
+	    {
+	      /* Allocate a new one since existing sections are in
+		 section groups.  */
+	      struct section_hash_entry *new_sh;
+	      new_sh = (struct section_hash_entry *)
+		bfd_section_hash_newfunc (NULL, &abfd->section_htab, name);
+	      if (new_sh == NULL)
+		return NULL;
+
+	      new_sh->root = old_sh->root;
+	      old_sh->root.next = &new_sh->root;
+	      newsect = &new_sh->section;
+	    }
+	}
+      else
+	newsect = &sh->section;
+
       if (newsect->name != NULL)
 	{
 	  /* Section already exists.  */
Index: bfd/bfd-in2.h
===================================================================
--- bfd/bfd-in2.h	(revision 6552)
+++ bfd/bfd-in2.h	(working copy)
@@ -1674,6 +1674,9 @@ extern asection bfd_ind_section;
 
 void bfd_section_list_clear (bfd *);
 
+bfd_boolean bfd_section_name_eq
+   (bfd *abfd, asection *sec, const char *name);
+
 asection *bfd_get_section_by_name (bfd *abfd, const char *name);
 
 asection *bfd_get_section_by_name_if

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: PATCH: PR gas/10531: Strange assembler warning message on  section   group
  2009-08-18 16:41   ` H.J. Lu
@ 2009-08-18 17:44     ` Daniel Jacobowitz
  2009-08-18 17:52       ` H.J. Lu
  0 siblings, 1 reply; 20+ messages in thread
From: Daniel Jacobowitz @ 2009-08-18 17:44 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

On Tue, Aug 18, 2009 at 09:23:25AM -0700, H.J. Lu wrote:
> On Mon, Aug 17, 2009 at 8:12 PM, Alan Modra<amodra@bigpond.net.au> wrote:
> > On Mon, Aug 17, 2009 at 04:07:21PM -0700, H.J. Lu wrote:
> >> We can't use bfd_get_section_by_name, subseg_new and subseg_get directly
> >> in dwarf2dbg.c since they don't know ELF section groups.  This patch adds
> >> obj_get_section_by_name, obj_subseg_new and obj_subseg_get.  Tested on
> >> Linux/ia32, Linux/ia64 and Linux/Intel64.  OK to install?
> >
> > Have you tested this with a multi-obj assembler?  I suspect that
> > something like x86-as --em=i386coff --gdwarf-2 will attempt to
> > access elf-only data structures.  (That's a slightly ridiculous
> > set of command line options for x86, but we shouldn't have gas
> > segfault.)  I think the proper patch needs some new fields in
> > struct format_ops and defines in obj-multi.h.
> >
> 
> strcmp can't be used to check if 2 ELF sections have the same name.
> I added bfd_section_name_eq.  OK to install?

This is a weird definition of "the same name".  They have the same
name; they're just not the same section.  What predicate do you really
need here?

-- 
Daniel Jacobowitz
CodeSourcery

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: PATCH: PR gas/10531: Strange assembler warning message on section   group
  2009-08-18 17:44     ` Daniel Jacobowitz
@ 2009-08-18 17:52       ` H.J. Lu
  2009-08-18 18:20         ` Daniel Jacobowitz
  0 siblings, 1 reply; 20+ messages in thread
From: H.J. Lu @ 2009-08-18 17:52 UTC (permalink / raw)
  To: H.J. Lu, binutils

On Tue, Aug 18, 2009 at 10:11 AM, Daniel Jacobowitz<drow@false.org> wrote:
> On Tue, Aug 18, 2009 at 09:23:25AM -0700, H.J. Lu wrote:
>> On Mon, Aug 17, 2009 at 8:12 PM, Alan Modra<amodra@bigpond.net.au> wrote:
>> > On Mon, Aug 17, 2009 at 04:07:21PM -0700, H.J. Lu wrote:
>> >> We can't use bfd_get_section_by_name, subseg_new and subseg_get directly
>> >> in dwarf2dbg.c since they don't know ELF section groups.  This patch adds
>> >> obj_get_section_by_name, obj_subseg_new and obj_subseg_get.  Tested on
>> >> Linux/ia32, Linux/ia64 and Linux/Intel64.  OK to install?
>> >
>> > Have you tested this with a multi-obj assembler?  I suspect that
>> > something like x86-as --em=i386coff --gdwarf-2 will attempt to
>> > access elf-only data structures.  (That's a slightly ridiculous
>> > set of command line options for x86, but we shouldn't have gas
>> > segfault.)  I think the proper patch needs some new fields in
>> > struct format_ops and defines in obj-multi.h.
>> >
>>
>> strcmp can't be used to check if 2 ELF sections have the same name.
>> I added bfd_section_name_eq.  OK to install?
>
> This is a weird definition of "the same name".  They have the same
> name; they're just not the same section.  What predicate do you really
> need here?
>

Well, there is only a string to identify a section. For ELF, we also
need to check the group name. Do you have a better name for
the new function?

-- 
H.J.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: PATCH: PR gas/10531: Strange assembler warning message on  section   group
  2009-08-18 17:52       ` H.J. Lu
@ 2009-08-18 18:20         ` Daniel Jacobowitz
  2009-08-18 18:48           ` H.J. Lu
  0 siblings, 1 reply; 20+ messages in thread
From: Daniel Jacobowitz @ 2009-08-18 18:20 UTC (permalink / raw)
  To: binutils

On Tue, Aug 18, 2009 at 10:19:25AM -0700, H.J. Lu wrote:
> Well, there is only a string to identify a section. For ELF, we also
> need to check the group name. Do you have a better name for
> the new function?

Then either fix that (non-string way to represent the section), or
better explain what you actually need.  Do you need "the section named
.stab that is not in any group"?  Maybe that could be called the
'default section' for a given name.

-- 
Daniel Jacobowitz
CodeSourcery

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: PATCH: PR gas/10531: Strange assembler warning message on section   group
  2009-08-18 18:20         ` Daniel Jacobowitz
@ 2009-08-18 18:48           ` H.J. Lu
  0 siblings, 0 replies; 20+ messages in thread
From: H.J. Lu @ 2009-08-18 18:48 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 1313 bytes --]

On Tue, Aug 18, 2009 at 10:52 AM, Daniel Jacobowitz<drow@false.org> wrote:
> On Tue, Aug 18, 2009 at 10:19:25AM -0700, H.J. Lu wrote:
>> Well, there is only a string to identify a section. For ELF, we also
>> need to check the group name. Do you have a better name for
>> the new function?
>
> Then either fix that (non-string way to represent the section), or
> better explain what you actually need.  Do you need "the section named
> .stab that is not in any group"?  Maybe that could be called the
> 'default section' for a given name.
>

Here is an updated patch to avoid compare segment name in
subseg_get.

Thanks.


-- 
H.J.
bfd/

2009-08-18  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * section.c: Include "elf-bfd.h".
	 (bfd_get_section_by_name): Don't use a section in a section
	 group.
	 (bfd_make_section_old_way): Likewise.

gas/

2009-08-18  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * subsegs.c (subseg_get): Don't compare segment name.

gas/testsuite/

2009-08-18  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * gas/elf/group2.d: New.
	 * gas/elf/group2.s: Likewise.
	 * gas/i386/debug1.d: Likewise.
	 * gas/i386/debug1.s: Likewise.

	* gas/elf/elf.exp: Run group2.

	* gas/i386/i386.exp: Run debug1 for both 32bit and 64bit.

[-- Attachment #2: binutils-group-2.patch --]
[-- Type: text/plain, Size: 6924 bytes --]

bfd/

2009-08-18  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * section.c: Include "elf-bfd.h".
	 (bfd_get_section_by_name): Don't use a section in a section
	 group.
	 (bfd_make_section_old_way): Likewise.

gas/

2009-08-18  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * subsegs.c (subseg_get): Don't compare segment name.

gas/testsuite/

2009-08-18  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * gas/elf/group2.d: New.
	 * gas/elf/group2.s: Likewise.
	 * gas/i386/debug1.d: Likewise.
	 * gas/i386/debug1.s: Likewise.

	* gas/elf/elf.exp: Run group2.

	* gas/i386/i386.exp: Run debug1 for both 32bit and 64bit.

Index: gas/testsuite/gas/i386/i386.exp
===================================================================
--- gas/testsuite/gas/i386/i386.exp	(revision 6552)
+++ gas/testsuite/gas/i386/i386.exp	(working copy)
@@ -190,6 +190,7 @@ if [expr ([istarget "i*86-*-*"] ||  [ist
 	run_list_test "inval-equ-2" "-al"
 	run_dump_test "ifunc"
 	run_list_test "l1om-inval" "-march=l1om --32"
+	run_dump_test "debug1"
     }
 
     # This is a PE specific test.
@@ -348,6 +349,7 @@ if [expr ([istarget "i*86-*-*"] || [ista
 	run_dump_test "mixed-mode-reloc64"
 	run_dump_test "x86-64-ifunc"
 	run_dump_test "l1om"
+	run_dump_test "debug1"
     }
 
     set ASFLAGS "$old_ASFLAGS"
Index: gas/testsuite/gas/i386/debug1.d
===================================================================
--- gas/testsuite/gas/i386/debug1.d	(revision 0)
+++ gas/testsuite/gas/i386/debug1.d	(revision 0)
@@ -0,0 +1,19 @@
+#as: -g
+#readelf: -SWg
+#name: group section with debug sections
+
+
+#...
+[ 	]*\[.*\][ 	]+foo[ 	]+GROUP.*
+#...
+[ 	]*\[.*\][ 	]+\.debug_info[ 	]+PROGBITS.*[ 	]+G[ 	]+.*
+[ 	]*\[.*\][ 	]+\.debug_line[ 	]+PROGBITS.*[ 	]+G[ 	]+.*
+[ 	]*\[.*\][ 	]+\.debug_line[ 	]+PROGBITS.*[ 	]+.*
+#...
+[ 	]*\[.*\][ 	]+\.debug_info[ 	]+PROGBITS.*[ 	]+.*
+#...
+COMDAT group section \[    1\] `foo' \[foo\] contains 2 sections:
+[ 	]+\[Index\][ 	]+Name
+[ 	]+\[.*\][ 	]+.debug_info
+[ 	]+\[.*\][ 	]+.debug_line
+#pass
Index: gas/testsuite/gas/i386/debug1.s
===================================================================
--- gas/testsuite/gas/i386/debug1.s	(revision 0)
+++ gas/testsuite/gas/i386/debug1.s	(revision 0)
@@ -0,0 +1,11 @@
+	.section .debug_info,"G",%progbits,foo,comdat
+	.byte 0x0
+	.section .debug_line,"G",%progbits,foo,comdat
+	.byte 0x0
+	.section .debug_info,"G",@progbits,foo,comdat
+	.byte 0x0
+	.section .debug_line,"G",@progbits,foo,comdat
+	.byte 0x0
+	.text
+	nop
+	nop
Index: gas/testsuite/gas/elf/group2.s
===================================================================
--- gas/testsuite/gas/elf/group2.s	(revision 0)
+++ gas/testsuite/gas/elf/group2.s	(revision 0)
@@ -0,0 +1,6 @@
+	.section .debug_info
+	.byte 0x0
+	.section .debug_info,"G",%progbits,foo,comdat
+	.byte 0x0
+	.section .debug_line,"G",%progbits,foo,comdat
+	.byte 0x0
Index: gas/testsuite/gas/elf/group2.d
===================================================================
--- gas/testsuite/gas/elf/group2.d	(revision 0)
+++ gas/testsuite/gas/elf/group2.d	(revision 0)
@@ -0,0 +1,16 @@
+#readelf: -SWg
+#name: group section with debug sections
+
+
+#...
+[ 	]*\[.*\][ 	]+foo[ 	]+GROUP.*
+#...
+[ 	]*\[.*\][ 	]+\.debug_info[ 	]+PROGBITS.*[ 	]+G[ 	]+.*
+[ 	]*\[.*\][ 	]+\.debug_line[ 	]+PROGBITS.*[ 	]+G[ 	]+.*
+[ 	]*\[.*\][ 	]+\.debug_line[ 	]+PROGBITS.*[ 	]+.*
+#...
+COMDAT group section \[    1\] `foo' \[foo\] contains 2 sections:
+[ 	]+\[Index\][ 	]+Name
+[ 	]+\[.*\][ 	]+.debug_info
+[ 	]+\[.*\][ 	]+.debug_line
+#pass
Index: gas/testsuite/gas/elf/elf.exp
===================================================================
--- gas/testsuite/gas/elf/elf.exp	(revision 6552)
+++ gas/testsuite/gas/elf/elf.exp	(working copy)
@@ -100,6 +100,7 @@ if { ([istarget "*-*-*elf*"]		
     run_dump_test "group0b" 
     run_dump_test "group1a" 
     run_dump_test "group1b" 
+    run_dump_test "group2" 
     case $target_triplet in {
 	{ alpha*-*-* } { }
 	{ cr16*-*-* } { }
Index: gas/subsegs.c
===================================================================
--- gas/subsegs.c	(revision 6552)
+++ gas/subsegs.c	(working copy)
@@ -148,15 +148,6 @@ subseg_get (const char *segname, int for
 {
   segT secptr;
   segment_info_type *seginfo;
-  const char *now_seg_name = (now_seg
-			      ? bfd_get_section_name (stdoutput, now_seg)
-			      : 0);
-
-  if (!force_new
-      && now_seg_name
-      && (now_seg_name == segname
-	  || !strcmp (now_seg_name, segname)))
-    return now_seg;
 
   if (!force_new)
     secptr = bfd_make_section_old_way (stdoutput, segname);
Index: bfd/section.c
===================================================================
--- bfd/section.c	(revision 6552)
+++ bfd/section.c	(working copy)
@@ -138,6 +138,7 @@ SUBSECTION
 #include "bfd.h"
 #include "libbfd.h"
 #include "bfdlink.h"
+#include "elf-bfd.h"
 
 /*
 DOCDD
@@ -854,11 +855,31 @@ asection *
 bfd_get_section_by_name (bfd *abfd, const char *name)
 {
   struct section_hash_entry *sh;
+  unsigned long hash;
+  asection *sec;
 
   sh = section_hash_lookup (&abfd->section_htab, name, FALSE, FALSE);
-  if (sh != NULL)
+  if (sh == NULL)
+    return NULL;
+
+  /* Only ELF has section group. */
+  if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
     return &sh->section;
 
+  hash = sh->root.hash;
+  do
+    {
+      sec = &sh->section;
+      /* Don't return a section in a section group.  */
+      if (elf_section_data (sec) == NULL
+	  || elf_group_name (sec) == NULL)
+	return sec;
+      sh = (struct section_hash_entry *) sh->root.next;
+    }
+  while (sh != NULL
+	 && sh->root.hash == hash
+	 && strcmp (sh->root.string, name) == 0);
+
   return NULL;
 }
 
@@ -1011,7 +1032,43 @@ bfd_make_section_old_way (bfd *abfd, con
       if (sh == NULL)
 	return NULL;
 
-      newsect = &sh->section;
+      /* Only ELF has section group. */
+      if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+	{
+	  struct section_hash_entry *old_sh = sh;
+	  unsigned long hash = sh->root.hash;
+
+	  do
+	    {
+	      newsect = &sh->section;
+	      /* Don't use a section in a section group.  */
+	      if (elf_section_data (newsect) == NULL
+		  || elf_group_name (newsect) == NULL)
+		break;
+	      sh = (struct section_hash_entry *) sh->root.next;
+	    }
+	  while (sh != NULL
+		 && sh->root.hash == hash
+		 && strcmp (sh->root.string, name) == 0);
+
+	  if (sh == NULL)
+	    {
+	      /* Allocate a new one since existing sections are in
+		 section groups.  */
+	      struct section_hash_entry *new_sh;
+	      new_sh = (struct section_hash_entry *)
+		bfd_section_hash_newfunc (NULL, &abfd->section_htab, name);
+	      if (new_sh == NULL)
+		return NULL;
+
+	      new_sh->root = old_sh->root;
+	      old_sh->root.next = &new_sh->root;
+	      newsect = &new_sh->section;
+	    }
+	}
+      else
+	newsect = &sh->section;
+
       if (newsect->name != NULL)
 	{
 	  /* Section already exists.  */

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: PATCH: PR gas/10531: Strange assembler warning message on section   group
  2009-08-18  4:09 PATCH: PR gas/10531: Strange assembler warning message on section group H.J. Lu
  2009-08-18  5:40 ` Alan Modra
@ 2009-08-19  3:08 ` Jim Wilson
  2009-08-19  5:25   ` H.J. Lu
  1 sibling, 1 reply; 20+ messages in thread
From: Jim Wilson @ 2009-08-19  3:08 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 2196 bytes --]

On 08/17/2009 04:07 PM, H.J. Lu wrote:
> We can't use bfd_get_section_by_name, subseg_new and subseg_get directly
> in dwarf2dbg.c since they don't know ELF section groups.  This patch adds
> obj_get_section_by_name, obj_subseg_new and obj_subseg_get.  Tested on
> Linux/ia32, Linux/ia64 and Linux/Intel64.  OK to install?

The underlying problem here is that gas is emitting a spurious warning 
when fed assembly code generated by icc -g.  This causes gas to fail if 
using -Wa,--warn-fatal.

Gas handles the case where gas generates debug info itself, in which 
case gas must create both the debug_info and debug_line sections.  Gas 
handles the case where gcc generated the debug info, in which case gas 
must only create the debug_line section.  Gas does not correctly handle 
the case where the compiler (icc) generated both the debug_info and 
debug_line sections, in which case gas should do nothing.  Gas insists 
on creating and writing to the debug_line section even though it already 
exists.

This would be relatively harmless, except for the section name 
confusion.  icc creates comdat debug sections for comdat functions. 
When gas tries to create the debug_line section, it accidentally gets a 
comdat section instead.  And then because gas assumes it is creating a 
section, gas sets the section flags and now we have a comdat section 
with incorrect flags.

H.J.'s patch tries to fix this by resolving the section name/comdat 
group section confusion.  There is still a minor problem that we get 
unnecessary and useless bytes written to the end of the debug_line 
section, but this should be relatively harmless.

I've toyed with trying to fix it by changing the logic in dwarf2_finish 
so that we don't create the debug_line section if there already is one. 
  However, I have a lot of more important tasks on my list at the 
moment, and don't have a finished patch yet.  I'm not sure if my 
solution is safe, since it doesn't fix the section name/comdat group 
section confusion.  I'm not sure if my patch works everywhere, since I 
haven't done any serious testing of it.

Maybe what we need here is a combination of both H.J.'s patch and my 
patch to fix both issues.

Jim

[-- Attachment #2: icc-comdat-warning.patch --]
[-- Type: text/plain, Size: 2844 bytes --]

Index: dwarf2dbg.c
===================================================================
RCS file: /cvs/src/src/gas/dwarf2dbg.c,v
retrieving revision 1.103
diff -p -r1.103 dwarf2dbg.c
*** dwarf2dbg.c	10 Jul 2009 15:26:58 -0000	1.103
--- dwarf2dbg.c	19 Aug 2009 02:27:20 -0000
*************** out_debug_info (segT info_seg, segT abbr
*** 1704,1712 ****
  
  /* Finish the dwarf2 debug sections.  We emit .debug.line if there
     were any .file/.loc directives, or --gdwarf2 was given, or if the
!    file has a non-empty .debug_info section.  If we emit .debug_line,
!    and the .debug_info section is empty, we also emit .debug_info,
!    .debug_aranges and .debug_abbrev.  ALL_SEGS will be non-null if
     there were any .file/.loc directives, or --gdwarf2 was given and
     there were any located instructions emitted.  */
  
--- 1704,1712 ----
  
  /* Finish the dwarf2 debug sections.  We emit .debug.line if there
     were any .file/.loc directives, or --gdwarf2 was given, or if the
!    file has a non-empty .debug_info section and an empty .debug_line section.
!    If we emit .debug_line, and the .debug_info section is empty, we also emit
!    .debug_info, .debug_aranges and .debug_abbrev.  ALL_SEGS will be non-null if
     there were any .file/.loc directives, or --gdwarf2 was given and
     there were any located instructions emitted.  */
  
*************** dwarf2_finish (void)
*** 1717,1729 ****
    struct line_seg *s;
    segT info_seg;
    int emit_other_sections = 0;
  
    info_seg = bfd_get_section_by_name (stdoutput, ".debug_info");
    emit_other_sections = info_seg == NULL || !seg_not_empty_p (info_seg);
  
!   if (!all_segs && emit_other_sections)
!     /* There is no line information and no non-empty .debug_info
!        section.  */
      return;
  
    /* Calculate the size of an address for the target machine.  */
--- 1717,1740 ----
    struct line_seg *s;
    segT info_seg;
    int emit_other_sections = 0;
+   int empty_debug_line = 0;
  
    info_seg = bfd_get_section_by_name (stdoutput, ".debug_info");
    emit_other_sections = info_seg == NULL || !seg_not_empty_p (info_seg);
  
!   line_seg = bfd_get_section_by_name (stdoutput, ".debug_line");
!   empty_debug_line = line_seg == NULL || !seg_not_empty_p (line_seg);
! 
!   /* We can't construct a new debug_line section if we already have one.
!      Give an error.  */
!   if (all_segs && !empty_debug_line)
!     as_fatal ("duplicate .debug_line sections");
! 
!   if ((!all_segs && emit_other_sections)
!       || (!emit_other_sections && !empty_debug_line))
!     /* If there is no line information and no non-empty .debug_info
!        section, or if there is both a non-empty .debug_info and a non-empty
!        .debug_line, then we do nothing.  */
      return;
  
    /* Calculate the size of an address for the target machine.  */

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: PATCH: PR gas/10531: Strange assembler warning message on section   group
  2009-08-19  3:08 ` Jim Wilson
@ 2009-08-19  5:25   ` H.J. Lu
  2009-08-19 19:50     ` Jim Wilson
  0 siblings, 1 reply; 20+ messages in thread
From: H.J. Lu @ 2009-08-19  5:25 UTC (permalink / raw)
  To: Jim Wilson; +Cc: binutils

On Tue, Aug 18, 2009 at 7:38 PM, Jim Wilson<wilson@codesourcery.com> wrote:
> On 08/17/2009 04:07 PM, H.J. Lu wrote:
>>
>> We can't use bfd_get_section_by_name, subseg_new and subseg_get directly
>> in dwarf2dbg.c since they don't know ELF section groups.  This patch adds
>> obj_get_section_by_name, obj_subseg_new and obj_subseg_get.  Tested on
>> Linux/ia32, Linux/ia64 and Linux/Intel64.  OK to install?
>
> The underlying problem here is that gas is emitting a spurious warning when
> fed assembly code generated by icc -g.  This causes gas to fail if using
> -Wa,--warn-fatal.
>
> Gas handles the case where gas generates debug info itself, in which case
> gas must create both the debug_info and debug_line sections.  Gas handles
> the case where gcc generated the debug info, in which case gas must only
> create the debug_line section.  Gas does not correctly handle the case where
> the compiler (icc) generated both the debug_info and debug_line sections, in
> which case gas should do nothing.  Gas insists on creating and writing to
> the debug_line section even though it already exists.
>
> This would be relatively harmless, except for the section name confusion.
>  icc creates comdat debug sections for comdat functions. When gas tries to
> create the debug_line section, it accidentally gets a comdat section
> instead.  And then because gas assumes it is creating a section, gas sets
> the section flags and now we have a comdat section with incorrect flags.
>
> H.J.'s patch tries to fix this by resolving the section name/comdat group
> section confusion.  There is still a minor problem that we get unnecessary
> and useless bytes written to the end of the debug_line section, but this
> should be relatively harmless.
>
> I've toyed with trying to fix it by changing the logic in dwarf2_finish so
> that we don't create the debug_line section if there already is one.
>  However, I have a lot of more important tasks on my list at the moment, and
> don't have a finished patch yet.  I'm not sure if my solution is safe, since
> it doesn't fix the section name/comdat group section confusion.  I'm not
> sure if my patch works everywhere, since I haven't done any serious testing
> of it.
>
> Maybe what we need here is a combination of both H.J.'s patch and my patch
> to fix both issues.
>

Hi Jim.

Can you take a look at my new patch:

http://sourceware.org/ml/binutils/2009-08/msg00334.html

The main problem is we shouldn't identify a section just by section name only.

Thanks.



-- 
H.J.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: PATCH: PR gas/10531: Strange assembler warning message on  section  group
  2009-08-19  5:25   ` H.J. Lu
@ 2009-08-19 19:50     ` Jim Wilson
  2009-08-20  4:02       ` H.J. Lu
  0 siblings, 1 reply; 20+ messages in thread
From: Jim Wilson @ 2009-08-19 19:50 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

On Tue, 2009-08-18 at 20:08 -0700, H.J. Lu wrote:
> The main problem is we shouldn't identify a section just by section name only.

I don't think that you understand the complete problem here.  This patch
will make the spurious warning message go away.  This does not solve the
problem that gas is emitting bogus debug info into a file that already
contains debug info.

This is trivial to prove with a small example.  Put this into a C file
int main (void) { asm (""); return 0; }
Compile with "icc -c -g".  Run "readelf -wl" on the .o file, and you
will see that we have two directory tables, two file name tables, two
line number tables, etc.  The first set is OK, and was emitted by icc.
The second set is bogus, and was emitted by gas.

The reason that an unpatched gas can emit a bogus warning is that when
we have comdat sections, gas accidentally emits the bogus debug info
into a comdat section, corrupting the comdat section.  Your patch fixes
this by emitting the bogus debug info into a regular section.  This is
good, and necessary, but we are still emitting bogus debug info with
your patch.  I think this needs to be fixed also.  We can probably fix
this with a separate patch.

If you want an example that generates the bogus warning, then try this
inline int sub (void) { return 0; }
int main (void) { asm (""); return sub (); }
When I compile with "icc -O -g -c" I get a bogus warning.  And running
"readelf -wl" on the output shows again that we have bogus debug info
emitted by gas, except now it is in a comdat section.

Jim

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: PATCH: PR gas/10531: Strange assembler warning message on section   group
  2009-08-19 19:50     ` Jim Wilson
@ 2009-08-20  4:02       ` H.J. Lu
  2009-08-20  5:09         ` H.J. Lu
                           ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: H.J. Lu @ 2009-08-20  4:02 UTC (permalink / raw)
  To: Jim Wilson; +Cc: binutils

On Wed, Aug 19, 2009 at 10:59 AM, Jim Wilson<wilson@codesourcery.com> wrote:
> On Tue, 2009-08-18 at 20:08 -0700, H.J. Lu wrote:
>> The main problem is we shouldn't identify a section just by section name only.
>
> I don't think that you understand the complete problem here.  This patch
> will make the spurious warning message go away.  This does not solve the
> problem that gas is emitting bogus debug info into a file that already
> contains debug info.
>
> This is trivial to prove with a small example.  Put this into a C file
> int main (void) { asm (""); return 0; }
> Compile with "icc -c -g".  Run "readelf -wl" on the .o file, and you
> will see that we have two directory tables, two file name tables, two
> line number tables, etc.  The first set is OK, and was emitted by icc.
> The second set is bogus, and was emitted by gas.
>
> The reason that an unpatched gas can emit a bogus warning is that when
> we have comdat sections, gas accidentally emits the bogus debug info
> into a comdat section, corrupting the comdat section.  Your patch fixes
> this by emitting the bogus debug info into a regular section.  This is
> good, and necessary, but we are still emitting bogus debug info with
> your patch.  I think this needs to be fixed also.  We can probably fix
> this with a separate patch.
>
> If you want an example that generates the bogus warning, then try this
> inline int sub (void) { return 0; }
> int main (void) { asm (""); return sub (); }
> When I compile with "icc -O -g -c" I get a bogus warning.  And running
> "readelf -wl" on the output shows again that we have bogus debug info
> emitted by gas, except now it is in a comdat section.
>


I didn't see the problem with my icc, using the patched
assembler. Can you provide main.s compiled by your icc?

Thanks.


-- 
H.J.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: PATCH: PR gas/10531: Strange assembler warning message on section   group
  2009-08-20  4:02       ` H.J. Lu
@ 2009-08-20  5:09         ` H.J. Lu
  2009-08-20 21:08         ` Jim Wilson
  2009-08-21  3:49         ` Jim Wilson
  2 siblings, 0 replies; 20+ messages in thread
From: H.J. Lu @ 2009-08-20  5:09 UTC (permalink / raw)
  To: Jim Wilson; +Cc: binutils

On Wed, Aug 19, 2009 at 6:20 PM, H.J. Lu<hjl.tools@gmail.com> wrote:
> On Wed, Aug 19, 2009 at 10:59 AM, Jim Wilson<wilson@codesourcery.com> wrote:
>> On Tue, 2009-08-18 at 20:08 -0700, H.J. Lu wrote:
>>> The main problem is we shouldn't identify a section just by section name only.
>>
>> I don't think that you understand the complete problem here.  This patch
>> will make the spurious warning message go away.  This does not solve the
>> problem that gas is emitting bogus debug info into a file that already
>> contains debug info.
>>
>> This is trivial to prove with a small example.  Put this into a C file
>> int main (void) { asm (""); return 0; }
>> Compile with "icc -c -g".  Run "readelf -wl" on the .o file, and you
>> will see that we have two directory tables, two file name tables, two
>> line number tables, etc.  The first set is OK, and was emitted by icc.
>> The second set is bogus, and was emitted by gas.
>>
>> The reason that an unpatched gas can emit a bogus warning is that when
>> we have comdat sections, gas accidentally emits the bogus debug info
>> into a comdat section, corrupting the comdat section.  Your patch fixes
>> this by emitting the bogus debug info into a regular section.  This is
>> good, and necessary, but we are still emitting bogus debug info with
>> your patch.  I think this needs to be fixed also.  We can probably fix
>> this with a separate patch.
>>
>> If you want an example that generates the bogus warning, then try this
>> inline int sub (void) { return 0; }
>> int main (void) { asm (""); return sub (); }
>> When I compile with "icc -O -g -c" I get a bogus warning.  And running
>> "readelf -wl" on the output shows again that we have bogus debug info
>> emitted by gas, except now it is in a comdat section.
>>
>
>
> I didn't see the problem with my icc, using the patched
> assembler. Can you provide main.s compiled by your icc?
>
> Thanks.
>

BTW, readelf won't dump more than one set of debug sections:

http://www.sourceware.org/bugzilla/show_bug.cgi?id=3237


-- 
H.J.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: PATCH: PR gas/10531: Strange assembler warning message on  section  group
  2009-08-20  4:02       ` H.J. Lu
  2009-08-20  5:09         ` H.J. Lu
@ 2009-08-20 21:08         ` Jim Wilson
  2009-08-21  3:49         ` Jim Wilson
  2 siblings, 0 replies; 20+ messages in thread
From: Jim Wilson @ 2009-08-20 21:08 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

On Wed, 2009-08-19 at 18:20 -0700, H.J. Lu wrote:
> I didn't see the problem with my icc, using the patched
> assembler. Can you provide main.s compiled by your icc?

I haven't tried your patch yet, I will have to do that.  I don't see how
it fixes the problem of emitting unnecessary debug info though.  All it
seems to do is change what section the unnecessary debug info goes into.

In an unpatched assembler, when I step through dwarf2_finish, I see that
it calls out_debug_line to populate the debug_line section, except that
this .s file already has a fully populated debug_line section.  So we
end up with two copies of debug_line info in a single debug_line
section, which is not good.  The second copy seems to be harmless, in
that it doesn't seem to confuse the debugger because there is no
debug_info section pointing at it.  However, it does increase the size
of the debug info, and size of dwarf2 debug info is an issue in many
places, so we shouldn't be emitting useless debug info.

I can send you some files in private mail that demonstrate the problems
that I am seeing.

Jim


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: PATCH: PR gas/10531: Strange assembler warning message on  section  group
  2009-08-20  4:02       ` H.J. Lu
  2009-08-20  5:09         ` H.J. Lu
  2009-08-20 21:08         ` Jim Wilson
@ 2009-08-21  3:49         ` Jim Wilson
  2009-08-21  4:26           ` H.J. Lu
  2 siblings, 1 reply; 20+ messages in thread
From: Jim Wilson @ 2009-08-21  3:49 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

On Wed, 2009-08-19 at 18:20 -0700, H.J. Lu wrote:
> I didn't see the problem with my icc, using the patched
> assembler. Can you provide main.s compiled by your icc?

I tried your patch.  Gas isn't emitting a spurious warning anymore, but
it is still emitting bogus debug info, which is what I expected.

To see the problem, just put a breakpoint in the function
out_debug_line.  You will see that we hit the breakpoint, even though we
should not, because the input assembly file already has a fully
populated debug_line section.

You patch is doing something useful; it is making sure that gas picks up
up the correct (non-comdat) debug_line section.  But it doesn't stop gas
from emitting the bogus debug info.

Jim


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: PATCH: PR gas/10531: Strange assembler warning message on section   group
  2009-08-21  3:49         ` Jim Wilson
@ 2009-08-21  4:26           ` H.J. Lu
  2009-08-21 13:36             ` H.J. Lu
  0 siblings, 1 reply; 20+ messages in thread
From: H.J. Lu @ 2009-08-21  4:26 UTC (permalink / raw)
  To: Jim Wilson; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 1926 bytes --]

On Thu, Aug 20, 2009 at 2:08 PM, Jim Wilson<wilson@codesourcery.com> wrote:
> On Wed, 2009-08-19 at 18:20 -0700, H.J. Lu wrote:
>> I didn't see the problem with my icc, using the patched
>> assembler. Can you provide main.s compiled by your icc?
>
> I tried your patch.  Gas isn't emitting a spurious warning anymore, but
> it is still emitting bogus debug info, which is what I expected.
>
> To see the problem, just put a breakpoint in the function
> out_debug_line.  You will see that we hit the breakpoint, even though we
> should not, because the input assembly file already has a fully
> populated debug_line section.
>
> You patch is doing something useful; it is making sure that gas picks up
> up the correct (non-comdat) debug_line section.  But it doesn't stop gas
> from emitting the bogus debug info.
>
> Jim
>

Hi Jim,

I think we have been generate bogus debug line info forever when .loc
directive isn't used.  Does it patch make any senses?

Thanks.


-- 
H.J.
----
bfd/

2009-08-20  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * section.c: Include "elf-bfd.h".
	 (bfd_get_section_by_name): Don't use a section in a section
	 group.
	 (bfd_make_section_old_way): Likewise.

binutils/testsuite/

2009-08-20  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * binutils-all/objdump.W: Remove bogus line debug info.

gas/

2009-08-20  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * dwarf2dbg.c (dwarf2_loc_directive_used): New.
	 (dwarf2_directive_loc): Set dwarf2_loc_directive_used.
	 (dwarf2_loc_directive_used): Likewise.
	 (dwarf2_finish): Return if -g isn't passed nor any .loc
	 directive is used.

	 * subsegs.c (subseg_get): Don't compare segment name.

gas/testsuite/

2009-08-20  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * gas/elf/group2.d: New.
	 * gas/elf/group2.s: Likewise.

	* gas/elf/elf.exp: Run group2.

[-- Attachment #2: binutils-group-4.patch --]
[-- Type: text/plain, Size: 8012 bytes --]

bfd/

2009-08-20  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * section.c: Include "elf-bfd.h".
	 (bfd_get_section_by_name): Don't use a section in a section
	 group.
	 (bfd_make_section_old_way): Likewise.

binutils/testsuite/

2009-08-20  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * binutils-all/objdump.W: Remove bogus line debug info.

gas/

2009-08-20  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * dwarf2dbg.c (dwarf2_loc_directive_used): New.
	 (dwarf2_directive_loc): Set dwarf2_loc_directive_used.
	 (dwarf2_loc_directive_used): Likewise.
	 (dwarf2_finish): Return if -g isn't passed nor any .loc
	 directive is used.

	 * subsegs.c (subseg_get): Don't compare segment name.

gas/testsuite/

2009-08-20  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * gas/elf/group2.d: New.
	 * gas/elf/group2.s: Likewise.

	* gas/elf/elf.exp: Run group2.

Index: binutils/gas/dwarf2dbg.c
===================================================================
--- binutils/gas/dwarf2dbg.c	(revision 6552)
+++ binutils/gas/dwarf2dbg.c	(working copy)
@@ -188,6 +188,9 @@ static unsigned int dirs_allocated;
    doing work when there's nothing to do.  */
 bfd_boolean dwarf2_loc_directive_seen;
 
+/* TRUE when any .loc directive is used.  */
+static bfd_boolean dwarf2_loc_directive_used;
+
 /* TRUE when we're supposed to set the basic block mark whenever a
    label is seen.  */
 bfd_boolean dwarf2_loc_mark_labels;
@@ -688,6 +691,7 @@ dwarf2_directive_loc (int dummy ATTRIBUT
 
   demand_empty_rest_of_line ();
   dwarf2_loc_directive_seen = TRUE;
+  dwarf2_loc_directive_used = TRUE;
   debug_type = DEBUG_NONE;
 }
 
@@ -706,6 +710,8 @@ dwarf2_directive_loc_mark_labels (int du
       dwarf2_loc_mark_labels = value != 0;
       demand_empty_rest_of_line ();
     }
+
+  dwarf2_loc_directive_used = TRUE;
 }
 \f
 static struct frag *
@@ -1718,6 +1724,11 @@ dwarf2_finish (void)
   segT info_seg;
   int emit_other_sections = 0;
 
+  /* Return if -g isn't passed nor any .loc directive is used.  */
+  if (!dwarf2_loc_directive_used
+      && (debug_type == DEBUG_UNSPECIFIED || debug_type == DEBUG_NONE))
+    return;
+
   info_seg = bfd_get_section_by_name (stdoutput, ".debug_info");
   emit_other_sections = info_seg == NULL || !seg_not_empty_p (info_seg);
 
Index: binutils/gas/testsuite/gas/elf/group2.s
===================================================================
--- binutils/gas/testsuite/gas/elf/group2.s	(revision 0)
+++ binutils/gas/testsuite/gas/elf/group2.s	(revision 0)
@@ -0,0 +1,10 @@
+	.section .debug_info,"G",%progbits,foo,comdat
+	.byte 0x0
+	.section .debug_line,"G",%progbits,foo,comdat
+	.byte 0x0
+	.section .debug_abbrev,"G",@progbits,foo,comdat
+	.byte 0x0
+	.section .debug_ranges,"G",@progbits,foo,comdat
+	.byte 0x0
+	.section .gnu.linkonce.t.foo, "xaG",@progbits,foo,comdat
+	nop
Index: binutils/gas/testsuite/gas/elf/group2.d
===================================================================
--- binutils/gas/testsuite/gas/elf/group2.d	(revision 0)
+++ binutils/gas/testsuite/gas/elf/group2.d	(revision 0)
@@ -0,0 +1,14 @@
+#as:
+#readelf: -SWg
+#name: group section with debug sections
+
+
+#...
+COMDAT group section \[    1\] `foo' \[foo\] contains 5 sections:
+[ 	]+\[Index\][ 	]+Name
+[ 	]+\[.*\][ 	]+.debug_info
+[ 	]+\[.*\][ 	]+.debug_line
+[ 	]+\[.*\][ 	]+.debug_abbrev
+[ 	]+\[.*\][ 	]+.debug_ranges
+[ 	]+\[.*\][ 	]+.gnu.linkonce.t.foo
+#pass
Index: binutils/gas/testsuite/gas/elf/elf.exp
===================================================================
--- binutils/gas/testsuite/gas/elf/elf.exp	(revision 6552)
+++ binutils/gas/testsuite/gas/elf/elf.exp	(working copy)
@@ -100,6 +100,7 @@ if { ([istarget "*-*-*elf*"]		
     run_dump_test "group0b" 
     run_dump_test "group1a" 
     run_dump_test "group1b" 
+    run_dump_test "group2" 
     case $target_triplet in {
 	{ alpha*-*-* } { }
 	{ cr16*-*-* } { }
Index: binutils/gas/subsegs.c
===================================================================
--- binutils/gas/subsegs.c	(revision 6552)
+++ binutils/gas/subsegs.c	(working copy)
@@ -148,15 +148,6 @@ subseg_get (const char *segname, int for
 {
   segT secptr;
   segment_info_type *seginfo;
-  const char *now_seg_name = (now_seg
-			      ? bfd_get_section_name (stdoutput, now_seg)
-			      : 0);
-
-  if (!force_new
-      && now_seg_name
-      && (now_seg_name == segname
-	  || !strcmp (now_seg_name, segname)))
-    return now_seg;
 
   if (!force_new)
     secptr = bfd_make_section_old_way (stdoutput, segname);
Index: binutils/binutils/testsuite/binutils-all/objdump.W
===================================================================
--- binutils/binutils/testsuite/binutils-all/objdump.W	(revision 6552)
+++ binutils/binutils/testsuite/binutils-all/objdump.W	(working copy)
@@ -73,36 +73,6 @@ Raw dump of debug contents of section .d
   Extended opcode 1: End of Sequence
 
 
-  Offset:                      0x42
-  Length:                      25
-  DWARF Version:               2
-  Prologue Length:             19
-  Minimum Instruction Length:  [1248]
-  Initial value of 'is_stmt':  1
-  Line Base:                   -5
-  Line Range:                  14
-  Opcode Base:                 13
-
- Opcodes:
-  Opcode 1 has 0 args
-  Opcode 2 has 1 args
-  Opcode 3 has 1 args
-  Opcode 4 has 1 args
-  Opcode 5 has 1 args
-  Opcode 6 has 0 args
-  Opcode 7 has 0 args
-  Opcode 8 has 0 args
-  Opcode 9 has 1 args
-  Opcode 10 has 0 args
-  Opcode 11 has 0 args
-  Opcode 12 has 1 args
-
- The Directory Table is empty.
-
- The File Name Table is empty.
-
- Line Number Statements:
-
 Contents of the .zdebug_abbrev section:
 
   Number TAG
Index: binutils/bfd/section.c
===================================================================
--- binutils/bfd/section.c	(revision 6552)
+++ binutils/bfd/section.c	(working copy)
@@ -138,6 +138,7 @@ SUBSECTION
 #include "bfd.h"
 #include "libbfd.h"
 #include "bfdlink.h"
+#include "elf-bfd.h"
 
 /*
 DOCDD
@@ -854,11 +855,31 @@ asection *
 bfd_get_section_by_name (bfd *abfd, const char *name)
 {
   struct section_hash_entry *sh;
+  unsigned long hash;
+  asection *sec;
 
   sh = section_hash_lookup (&abfd->section_htab, name, FALSE, FALSE);
-  if (sh != NULL)
+  if (sh == NULL)
+    return NULL;
+
+  /* Only ELF has section group. */
+  if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
     return &sh->section;
 
+  hash = sh->root.hash;
+  do
+    {
+      sec = &sh->section;
+      /* Don't return a section in a section group.  */
+      if (elf_section_data (sec) == NULL
+	  || elf_group_name (sec) == NULL)
+	return sec;
+      sh = (struct section_hash_entry *) sh->root.next;
+    }
+  while (sh != NULL
+	 && sh->root.hash == hash
+	 && strcmp (sh->root.string, name) == 0);
+
   return NULL;
 }
 
@@ -1011,7 +1032,43 @@ bfd_make_section_old_way (bfd *abfd, con
       if (sh == NULL)
 	return NULL;
 
-      newsect = &sh->section;
+      /* Only ELF has section group. */
+      if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+	{
+	  struct section_hash_entry *old_sh = sh;
+	  unsigned long hash = sh->root.hash;
+
+	  do
+	    {
+	      newsect = &sh->section;
+	      /* Don't use a section in a section group.  */
+	      if (elf_section_data (newsect) == NULL
+		  || elf_group_name (newsect) == NULL)
+		break;
+	      sh = (struct section_hash_entry *) sh->root.next;
+	    }
+	  while (sh != NULL
+		 && sh->root.hash == hash
+		 && strcmp (sh->root.string, name) == 0);
+
+	  if (sh == NULL)
+	    {
+	      /* Allocate a new one since existing sections are in
+		 section groups.  */
+	      struct section_hash_entry *new_sh;
+	      new_sh = (struct section_hash_entry *)
+		bfd_section_hash_newfunc (NULL, &abfd->section_htab, name);
+	      if (new_sh == NULL)
+		return NULL;
+
+	      new_sh->root = old_sh->root;
+	      old_sh->root.next = &new_sh->root;
+	      newsect = &new_sh->section;
+	    }
+	}
+      else
+	newsect = &sh->section;
+
       if (newsect->name != NULL)
 	{
 	  /* Section already exists.  */

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: PATCH: PR gas/10531: Strange assembler warning message on section   group
  2009-08-21  4:26           ` H.J. Lu
@ 2009-08-21 13:36             ` H.J. Lu
  2009-08-22 19:10               ` H.J. Lu
  0 siblings, 1 reply; 20+ messages in thread
From: H.J. Lu @ 2009-08-21 13:36 UTC (permalink / raw)
  To: Jim Wilson; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 2364 bytes --]

On Thu, Aug 20, 2009 at 6:49 PM, H.J. Lu<hjl.tools@gmail.com> wrote:
> On Thu, Aug 20, 2009 at 2:08 PM, Jim Wilson<wilson@codesourcery.com> wrote:
>> On Wed, 2009-08-19 at 18:20 -0700, H.J. Lu wrote:
>>> I didn't see the problem with my icc, using the patched
>>> assembler. Can you provide main.s compiled by your icc?
>>
>> I tried your patch.  Gas isn't emitting a spurious warning anymore, but
>> it is still emitting bogus debug info, which is what I expected.
>>
>> To see the problem, just put a breakpoint in the function
>> out_debug_line.  You will see that we hit the breakpoint, even though we
>> should not, because the input assembly file already has a fully
>> populated debug_line section.
>>
>> You patch is doing something useful; it is making sure that gas picks up
>> up the correct (non-comdat) debug_line section.  But it doesn't stop gas
>> from emitting the bogus debug info.
>>
>> Jim
>>
>
> Hi Jim,
>
> I think we have been generate bogus debug line info forever when .loc
> directive isn't used.  Does it patch make any senses?
>

Here is the updated patch. We should generate DWARF info only
when -g or .loc directives are used.  OK to install?

Thanks.


-- 
H.J.
---
bfd/

2009-08-20  H.J. Lu  <hongjiu.lu@intel.com>

	PR gas/10531
	* section.c: Include "elf-bfd.h".
	(bfd_get_section_by_name): Don't use a section in a section
	group.
	(bfd_make_section_old_way): Likewise.

binutils/testsuite/

2009-08-20  H.J. Lu  <hongjiu.lu@intel.com>

	PR gas/10531
	* binutils-all/objdump.W: Remove bogus line debug info.

gas/

2009-08-20  H.J. Lu  <hongjiu.lu@intel.com>

	PR gas/10531
	* as.c (gen_debug): New.
	(parse_args): Set gen_debug to debug_type.

	* as.h (gen_debug): New.

	* dwarf2dbg.c (dwarf2_loc_directive_used): New.
	(dwarf2_directive_loc): Set dwarf2_loc_directive_used.
	(dwarf2_loc_directive_used): Likewise.
	(dwarf2_finish): Return if -g isn't passed nor any .loc
	directive is used.

	* subsegs.c (subseg_get): Don't compare segment name.

gas/testsuite/

2009-08-20  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * gas/elf/group2.d: New.
	 * gas/elf/group2.s: Likewise.
	 * gas/i386/debug1.d: Likewise.
	 * gas/i386/debug1.s: Likewise.

	* gas/elf/elf.exp: Run group2.

	* gas/i386/i386.exp: Run debug1 for both 32bit and 64bit.

[-- Attachment #2: binutils-group-5.patch --]
[-- Type: application/octet-stream, Size: 11657 bytes --]

bfd/

2009-08-20  H.J. Lu  <hongjiu.lu@intel.com>

	PR gas/10531
	* section.c: Include "elf-bfd.h".
	(bfd_get_section_by_name): Don't use a section in a section
	group.
	(bfd_make_section_old_way): Likewise.

binutils/testsuite/

2009-08-20  H.J. Lu  <hongjiu.lu@intel.com>

	PR gas/10531
	* binutils-all/objdump.W: Remove bogus line debug info.

gas/

2009-08-20  H.J. Lu  <hongjiu.lu@intel.com>

	PR gas/10531
	* as.c (gen_debug): New.
	(parse_args): Set gen_debug to debug_type.

	* as.h (gen_debug): New.

	* dwarf2dbg.c (dwarf2_loc_directive_used): New.
	(dwarf2_directive_loc): Set dwarf2_loc_directive_used.
	(dwarf2_loc_directive_used): Likewise.
	(dwarf2_finish): Return if -g isn't passed nor any .loc
	directive is used.

	* subsegs.c (subseg_get): Don't compare segment name.

gas/testsuite/

2009-08-20  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * gas/elf/group2.d: New.
	 * gas/elf/group2.s: Likewise.
	 * gas/i386/debug1.d: Likewise.
	 * gas/i386/debug1.s: Likewise.

	* gas/elf/elf.exp: Run group2.

	* gas/i386/i386.exp: Run debug1 for both 32bit and 64bit.

Index: binutils/gas/dwarf2dbg.c
===================================================================
--- binutils/gas/dwarf2dbg.c	(revision 6552)
+++ binutils/gas/dwarf2dbg.c	(working copy)
@@ -188,6 +188,9 @@ static unsigned int dirs_allocated;
    doing work when there's nothing to do.  */
 bfd_boolean dwarf2_loc_directive_seen;
 
+/* TRUE when any .loc directive is used.  */
+static bfd_boolean dwarf2_loc_directive_used;
+
 /* TRUE when we're supposed to set the basic block mark whenever a
    label is seen.  */
 bfd_boolean dwarf2_loc_mark_labels;
@@ -688,6 +691,7 @@ dwarf2_directive_loc (int dummy ATTRIBUT
 
   demand_empty_rest_of_line ();
   dwarf2_loc_directive_seen = TRUE;
+  dwarf2_loc_directive_used = TRUE;
   debug_type = DEBUG_NONE;
 }
 
@@ -706,6 +710,8 @@ dwarf2_directive_loc_mark_labels (int du
       dwarf2_loc_mark_labels = value != 0;
       demand_empty_rest_of_line ();
     }
+
+  dwarf2_loc_directive_used = TRUE;
 }
 \f
 static struct frag *
@@ -1718,6 +1724,10 @@ dwarf2_finish (void)
   segT info_seg;
   int emit_other_sections = 0;
 
+  /* Return if -g isn't passed nor any .loc directive is used.  */
+  if (!dwarf2_loc_directive_used && gen_debug == DEBUG_UNSPECIFIED)
+    return;
+
   info_seg = bfd_get_section_by_name (stdoutput, ".debug_info");
   emit_other_sections = info_seg == NULL || !seg_not_empty_p (info_seg);
 
Index: binutils/gas/testsuite/gas/i386/i386.exp
===================================================================
--- binutils/gas/testsuite/gas/i386/i386.exp	(revision 6552)
+++ binutils/gas/testsuite/gas/i386/i386.exp	(working copy)
@@ -190,6 +190,7 @@ if [expr ([istarget "i*86-*-*"] ||  [ist
 	run_list_test "inval-equ-2" "-al"
 	run_dump_test "ifunc"
 	run_list_test "l1om-inval" "-march=l1om --32"
+	run_dump_test "debug1"
     }
 
     # This is a PE specific test.
@@ -348,6 +349,7 @@ if [expr ([istarget "i*86-*-*"] || [ista
 	run_dump_test "mixed-mode-reloc64"
 	run_dump_test "x86-64-ifunc"
 	run_dump_test "l1om"
+	run_dump_test "debug1"
     }
 
     set ASFLAGS "$old_ASFLAGS"
Index: binutils/gas/testsuite/gas/i386/debug1.d
===================================================================
--- binutils/gas/testsuite/gas/i386/debug1.d	(revision 0)
+++ binutils/gas/testsuite/gas/i386/debug1.d	(revision 0)
@@ -0,0 +1,46 @@
+#as: --gdwarf-2
+#readelf: -wl
+#name: DWARF2 debugging information 1
+
+Raw dump of debug contents of section .debug_line:
+
+  Offset:                      0x0
+  Length:                      12.
+  DWARF Version:               2
+  Prologue Length:             101
+  Minimum Instruction Length:  1
+  Initial value of 'is_stmt':  1
+  Line Base:                   -5
+  Line Range:                  14
+  Opcode Base:                 13
+
+ Opcodes:
+  Opcode 1 has 0 args
+  Opcode 2 has 1 args
+  Opcode 3 has 1 args
+  Opcode 4 has 1 args
+  Opcode 5 has 1 args
+  Opcode 6 has 0 args
+  Opcode 7 has 0 args
+  Opcode 8 has 0 args
+  Opcode 9 has 1 args
+  Opcode 10 has 0 args
+  Opcode 11 has 0 args
+  Opcode 12 has 1 args
+
+ The Directory Table:
+  /export/gnu/import/svn/binutils-group/binutils/gas/testsuite/gas/i386
+
+ The File Name Table:
+  Entry	Dir	Time	Size	Name
+  1	1	0	0	debug1.s
+
+ Line Number Statements:
+  Extended opcode 2: set Address to 0x0
+  Special opcode 7: advance Address by 0 to 0x0 and Line by 2 to 3
+  Special opcode 20: advance Address by 1 to 0x1 and Line by 1 to 4
+  Special opcode 20: advance Address by 1 to 0x2 and Line by 1 to 5
+  Advance PC by 1 to 0x3
+  Extended opcode 1: End of Sequence
+
+
Index: binutils/gas/testsuite/gas/i386/debug1.s
===================================================================
--- binutils/gas/testsuite/gas/i386/debug1.s	(revision 0)
+++ binutils/gas/testsuite/gas/i386/debug1.s	(revision 0)
@@ -0,0 +1,5 @@
+	.file "debug1.s"
+	.text
+	nop
+	nop
+	nop
Index: binutils/gas/testsuite/gas/elf/group2.s
===================================================================
--- binutils/gas/testsuite/gas/elf/group2.s	(revision 0)
+++ binutils/gas/testsuite/gas/elf/group2.s	(revision 0)
@@ -0,0 +1,10 @@
+	.section .debug_info,"G",%progbits,foo,comdat
+	.byte 0x0
+	.section .debug_line,"G",%progbits,foo,comdat
+	.byte 0x0
+	.section .debug_abbrev,"G",@progbits,foo,comdat
+	.byte 0x0
+	.section .debug_ranges,"G",@progbits,foo,comdat
+	.byte 0x0
+	.section .gnu.linkonce.t.foo, "xaG",@progbits,foo,comdat
+	nop
Index: binutils/gas/testsuite/gas/elf/group2.d
===================================================================
--- binutils/gas/testsuite/gas/elf/group2.d	(revision 0)
+++ binutils/gas/testsuite/gas/elf/group2.d	(revision 0)
@@ -0,0 +1,14 @@
+#as:
+#readelf: -SWg
+#name: group section with debug sections
+
+
+#...
+COMDAT group section \[    1\] `foo' \[foo\] contains 5 sections:
+[ 	]+\[Index\][ 	]+Name
+[ 	]+\[.*\][ 	]+.debug_info
+[ 	]+\[.*\][ 	]+.debug_line
+[ 	]+\[.*\][ 	]+.debug_abbrev
+[ 	]+\[.*\][ 	]+.debug_ranges
+[ 	]+\[.*\][ 	]+.gnu.linkonce.t.foo
+#pass
Index: binutils/gas/testsuite/gas/elf/elf.exp
===================================================================
--- binutils/gas/testsuite/gas/elf/elf.exp	(revision 6552)
+++ binutils/gas/testsuite/gas/elf/elf.exp	(working copy)
@@ -100,6 +100,7 @@ if { ([istarget "*-*-*elf*"]		
     run_dump_test "group0b" 
     run_dump_test "group1a" 
     run_dump_test "group1b" 
+    run_dump_test "group2" 
     case $target_triplet in {
 	{ alpha*-*-* } { }
 	{ cr16*-*-* } { }
Index: binutils/gas/as.c
===================================================================
--- binutils/gas/as.c	(revision 6552)
+++ binutils/gas/as.c	(working copy)
@@ -72,6 +72,9 @@ struct defsym_list
 /* True if a listing is wanted.  */
 int listing;
 
+/* If assembler shiuld debug info.  */
+enum debug_info_type gen_debug = DEBUG_UNSPECIFIED;
+
 /* Type of debugging to generate.  */
 enum debug_info_type debug_type = DEBUG_UNSPECIFIED;
 int use_gnu_debug_info_extensions = 0;
@@ -908,6 +911,8 @@ This program has absolutely no warranty.
 	}
     }
 
+  gen_debug = debug_type;
+
   free (shortopts);
   free (longopts);
 
Index: binutils/gas/as.h
===================================================================
--- binutils/gas/as.h	(revision 6552)
+++ binutils/gas/as.h	(working copy)
@@ -429,6 +429,7 @@ enum debug_info_type
   DEBUG_DWARF2
 };
 
+extern enum debug_info_type gen_debug;
 extern enum debug_info_type debug_type;
 extern int use_gnu_debug_info_extensions;
 \f
Index: binutils/gas/subsegs.c
===================================================================
--- binutils/gas/subsegs.c	(revision 6552)
+++ binutils/gas/subsegs.c	(working copy)
@@ -148,15 +148,6 @@ subseg_get (const char *segname, int for
 {
   segT secptr;
   segment_info_type *seginfo;
-  const char *now_seg_name = (now_seg
-			      ? bfd_get_section_name (stdoutput, now_seg)
-			      : 0);
-
-  if (!force_new
-      && now_seg_name
-      && (now_seg_name == segname
-	  || !strcmp (now_seg_name, segname)))
-    return now_seg;
 
   if (!force_new)
     secptr = bfd_make_section_old_way (stdoutput, segname);
Index: binutils/binutils/testsuite/binutils-all/objdump.W
===================================================================
--- binutils/binutils/testsuite/binutils-all/objdump.W	(revision 6552)
+++ binutils/binutils/testsuite/binutils-all/objdump.W	(working copy)
@@ -73,36 +73,6 @@ Raw dump of debug contents of section .d
   Extended opcode 1: End of Sequence
 
 
-  Offset:                      0x42
-  Length:                      25
-  DWARF Version:               2
-  Prologue Length:             19
-  Minimum Instruction Length:  [1248]
-  Initial value of 'is_stmt':  1
-  Line Base:                   -5
-  Line Range:                  14
-  Opcode Base:                 13
-
- Opcodes:
-  Opcode 1 has 0 args
-  Opcode 2 has 1 args
-  Opcode 3 has 1 args
-  Opcode 4 has 1 args
-  Opcode 5 has 1 args
-  Opcode 6 has 0 args
-  Opcode 7 has 0 args
-  Opcode 8 has 0 args
-  Opcode 9 has 1 args
-  Opcode 10 has 0 args
-  Opcode 11 has 0 args
-  Opcode 12 has 1 args
-
- The Directory Table is empty.
-
- The File Name Table is empty.
-
- Line Number Statements:
-
 Contents of the .zdebug_abbrev section:
 
   Number TAG
Index: binutils/bfd/section.c
===================================================================
--- binutils/bfd/section.c	(revision 6552)
+++ binutils/bfd/section.c	(working copy)
@@ -138,6 +138,7 @@ SUBSECTION
 #include "bfd.h"
 #include "libbfd.h"
 #include "bfdlink.h"
+#include "elf-bfd.h"
 
 /*
 DOCDD
@@ -854,11 +855,31 @@ asection *
 bfd_get_section_by_name (bfd *abfd, const char *name)
 {
   struct section_hash_entry *sh;
+  unsigned long hash;
+  asection *sec;
 
   sh = section_hash_lookup (&abfd->section_htab, name, FALSE, FALSE);
-  if (sh != NULL)
+  if (sh == NULL)
+    return NULL;
+
+  /* Only ELF has section group. */
+  if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
     return &sh->section;
 
+  hash = sh->root.hash;
+  do
+    {
+      sec = &sh->section;
+      /* Don't return a section in a section group.  */
+      if (elf_section_data (sec) == NULL
+	  || elf_group_name (sec) == NULL)
+	return sec;
+      sh = (struct section_hash_entry *) sh->root.next;
+    }
+  while (sh != NULL
+	 && sh->root.hash == hash
+	 && strcmp (sh->root.string, name) == 0);
+
   return NULL;
 }
 
@@ -1011,7 +1032,43 @@ bfd_make_section_old_way (bfd *abfd, con
       if (sh == NULL)
 	return NULL;
 
-      newsect = &sh->section;
+      /* Only ELF has section group. */
+      if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+	{
+	  struct section_hash_entry *old_sh = sh;
+	  unsigned long hash = sh->root.hash;
+
+	  do
+	    {
+	      newsect = &sh->section;
+	      /* Don't use a section in a section group.  */
+	      if (elf_section_data (newsect) == NULL
+		  || elf_group_name (newsect) == NULL)
+		break;
+	      sh = (struct section_hash_entry *) sh->root.next;
+	    }
+	  while (sh != NULL
+		 && sh->root.hash == hash
+		 && strcmp (sh->root.string, name) == 0);
+
+	  if (sh == NULL)
+	    {
+	      /* Allocate a new one since existing sections are in
+		 section groups.  */
+	      struct section_hash_entry *new_sh;
+	      new_sh = (struct section_hash_entry *)
+		bfd_section_hash_newfunc (NULL, &abfd->section_htab, name);
+	      if (new_sh == NULL)
+		return NULL;
+
+	      new_sh->root = old_sh->root;
+	      old_sh->root.next = &new_sh->root;
+	      newsect = &new_sh->section;
+	    }
+	}
+      else
+	newsect = &sh->section;
+
       if (newsect->name != NULL)
 	{
 	  /* Section already exists.  */

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: PATCH: PR gas/10531: Strange assembler warning message on section   group
  2009-08-21 13:36             ` H.J. Lu
@ 2009-08-22 19:10               ` H.J. Lu
  2009-08-23  7:28                 ` H.J. Lu
  0 siblings, 1 reply; 20+ messages in thread
From: H.J. Lu @ 2009-08-22 19:10 UTC (permalink / raw)
  To: Jim Wilson; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 2634 bytes --]

On Thu, Aug 20, 2009 at 9:26 PM, H.J. Lu<hjl.tools@gmail.com> wrote:
> On Thu, Aug 20, 2009 at 6:49 PM, H.J. Lu<hjl.tools@gmail.com> wrote:
>> On Thu, Aug 20, 2009 at 2:08 PM, Jim Wilson<wilson@codesourcery.com> wrote:
>>> On Wed, 2009-08-19 at 18:20 -0700, H.J. Lu wrote:
>>>> I didn't see the problem with my icc, using the patched
>>>> assembler. Can you provide main.s compiled by your icc?
>>>
>>> I tried your patch.  Gas isn't emitting a spurious warning anymore, but
>>> it is still emitting bogus debug info, which is what I expected.
>>>
>>> To see the problem, just put a breakpoint in the function
>>> out_debug_line.  You will see that we hit the breakpoint, even though we
>>> should not, because the input assembly file already has a fully
>>> populated debug_line section.
>>>
>>> You patch is doing something useful; it is making sure that gas picks up
>>> up the correct (non-comdat) debug_line section.  But it doesn't stop gas
>>> from emitting the bogus debug info.
>>>
>>> Jim
>>>
>>
>> Hi Jim,
>>
>> I think we have been generate bogus debug line info forever when .loc
>> directive isn't used.  Does it patch make any senses?
>>
>
> Here is the updated patch. We should generate DWARF info only
> when -g or .loc directives are used.  OK to install?
>
> Thanks.
>
>

Here is a new patch with updated testcases. OK to install?

Thanks.

-- 
H.J.
--
bfd/

2009-08-22  H.J. Lu  <hongjiu.lu@intel.com>

	PR gas/10531
	* section.c: Include "elf-bfd.h".
	(bfd_get_section_by_name): Don't use a section in a section
	group.
	(bfd_make_section_old_way): Likewise.

binutils/testsuite/

2009-08-22  H.J. Lu  <hongjiu.lu@intel.com>

	PR gas/10531
	* binutils-all/objdump.W: Remove bogus line debug info.

gas/

2009-08-22  H.J. Lu  <hongjiu.lu@intel.com>

	PR gas/10531
	* as.c (gen_debug): New.
	(parse_args): Set gen_debug to debug_type.

	* as.h (gen_debug): New.

	* dwarf2dbg.c (dwarf2_loc_directive_used): New.
	(dwarf2_directive_loc): Set dwarf2_loc_directive_used.
	(dwarf2_loc_directive_used): Likewise.
	(dwarf2_finish): Return if -g isn't passed nor any .loc
	directive is used.

	* subsegs.c (subseg_get): Don't compare segment name.

gas/testsuite/

2009-08-22  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * gas/elf/dwarf2-1.d: New.
	 * gas/elf/dwarf2-1.s: Likewise.
	 * gas/elf/dwarf2-1.d: Likewise.
	 * gas/elf/dwarf2-1.2: Likewise.
	 * gas/i386/debug1.d: Likewise.
	 * gas/i386/debug1.s: Likewise.

	* gas/elf/elf.exp: Run dwarf2-1 and dwarf2-2.

	* gas/i386/i386.exp: Run debug1 for both 32bit and 64bit.

[-- Attachment #2: binutils-group-6.patch --]
[-- Type: application/octet-stream, Size: 26919 bytes --]

bfd/

2009-08-22  H.J. Lu  <hongjiu.lu@intel.com>

	PR gas/10531
	* section.c: Include "elf-bfd.h".
	(bfd_get_section_by_name): Don't use a section in a section
	group.
	(bfd_make_section_old_way): Likewise.

binutils/testsuite/

2009-08-22  H.J. Lu  <hongjiu.lu@intel.com>

	PR gas/10531
	* binutils-all/objdump.W: Remove bogus line debug info.

gas/

2009-08-22  H.J. Lu  <hongjiu.lu@intel.com>

	PR gas/10531
	* as.c (gen_debug): New.
	(parse_args): Set gen_debug to debug_type.

	* as.h (gen_debug): New.

	* dwarf2dbg.c (dwarf2_loc_directive_used): New.
	(dwarf2_directive_loc): Set dwarf2_loc_directive_used.
	(dwarf2_loc_directive_used): Likewise.
	(dwarf2_finish): Return if -g isn't passed nor any .loc
	directive is used.

	* subsegs.c (subseg_get): Don't compare segment name.

gas/testsuite/

2009-08-22  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * gas/elf/dwarf2-1.d: New.
	 * gas/elf/dwarf2-1.s: Likewise.
	 * gas/elf/dwarf2-1.d: Likewise.
	 * gas/elf/dwarf2-1.2: Likewise.
	 * gas/i386/debug1.d: Likewise.
	 * gas/i386/debug1.s: Likewise.

	* gas/elf/elf.exp: Run dwarf2-1 and dwarf2-2.

	* gas/i386/i386.exp: Run debug1 for both 32bit and 64bit.

Index: binutils/gas/dwarf2dbg.c
===================================================================
--- binutils/gas/dwarf2dbg.c	(revision 6552)
+++ binutils/gas/dwarf2dbg.c	(working copy)
@@ -188,6 +188,9 @@ static unsigned int dirs_allocated;
    doing work when there's nothing to do.  */
 bfd_boolean dwarf2_loc_directive_seen;
 
+/* TRUE when any .loc directive is used.  */
+static bfd_boolean dwarf2_loc_directive_used;
+
 /* TRUE when we're supposed to set the basic block mark whenever a
    label is seen.  */
 bfd_boolean dwarf2_loc_mark_labels;
@@ -688,6 +691,7 @@ dwarf2_directive_loc (int dummy ATTRIBUT
 
   demand_empty_rest_of_line ();
   dwarf2_loc_directive_seen = TRUE;
+  dwarf2_loc_directive_used = TRUE;
   debug_type = DEBUG_NONE;
 }
 
@@ -706,6 +710,8 @@ dwarf2_directive_loc_mark_labels (int du
       dwarf2_loc_mark_labels = value != 0;
       demand_empty_rest_of_line ();
     }
+
+  dwarf2_loc_directive_used = TRUE;
 }
 \f
 static struct frag *
@@ -1718,6 +1724,10 @@ dwarf2_finish (void)
   segT info_seg;
   int emit_other_sections = 0;
 
+  /* Return if -g isn't passed nor any .loc directive is used.  */
+  if (!dwarf2_loc_directive_used && gen_debug == DEBUG_UNSPECIFIED)
+    return;
+
   info_seg = bfd_get_section_by_name (stdoutput, ".debug_info");
   emit_other_sections = info_seg == NULL || !seg_not_empty_p (info_seg);
 
Index: binutils/gas/testsuite/gas/i386/i386.exp
===================================================================
--- binutils/gas/testsuite/gas/i386/i386.exp	(revision 6552)
+++ binutils/gas/testsuite/gas/i386/i386.exp	(working copy)
@@ -190,6 +190,7 @@ if [expr ([istarget "i*86-*-*"] ||  [ist
 	run_list_test "inval-equ-2" "-al"
 	run_dump_test "ifunc"
 	run_list_test "l1om-inval" "-march=l1om --32"
+	run_dump_test "debug1"
     }
 
     # This is a PE specific test.
@@ -348,6 +349,7 @@ if [expr ([istarget "i*86-*-*"] || [ista
 	run_dump_test "mixed-mode-reloc64"
 	run_dump_test "x86-64-ifunc"
 	run_dump_test "l1om"
+	run_dump_test "debug1"
     }
 
     set ASFLAGS "$old_ASFLAGS"
Index: binutils/gas/testsuite/gas/i386/debug1.d
===================================================================
--- binutils/gas/testsuite/gas/i386/debug1.d	(revision 0)
+++ binutils/gas/testsuite/gas/i386/debug1.d	(revision 0)
@@ -0,0 +1,46 @@
+#as: --gdwarf-2
+#readelf: -wl
+#name: DWARF2 debugging information 1
+
+Raw dump of debug contents of section .debug_line:
+
+  Offset:                      0x0
+  Length:                      .*
+  DWARF Version:               2
+  Prologue Length:             .*
+  Minimum Instruction Length:  1
+  Initial value of 'is_stmt':  1
+  Line Base:                   -5
+  Line Range:                  14
+  Opcode Base:                 13
+
+ Opcodes:
+  Opcode 1 has 0 args
+  Opcode 2 has 1 args
+  Opcode 3 has 1 args
+  Opcode 4 has 1 args
+  Opcode 5 has 1 args
+  Opcode 6 has 0 args
+  Opcode 7 has 0 args
+  Opcode 8 has 0 args
+  Opcode 9 has 1 args
+  Opcode 10 has 0 args
+  Opcode 11 has 0 args
+  Opcode 12 has 1 args
+
+ The Directory Table:
+  .*
+
+ The File Name Table:
+  Entry	Dir	Time	Size	Name
+  1	1	0	0	debug1.s
+
+ Line Number Statements:
+  Extended opcode 2: set Address to 0x0
+  Special opcode 7: advance Address by 0 to 0x0 and Line by 2 to 3
+  Special opcode 20: advance Address by 1 to 0x1 and Line by 1 to 4
+  Special opcode 20: advance Address by 1 to 0x2 and Line by 1 to 5
+  Advance PC by 1 to 0x3
+  Extended opcode 1: End of Sequence
+
+
Index: binutils/gas/testsuite/gas/i386/debug1.s
===================================================================
--- binutils/gas/testsuite/gas/i386/debug1.s	(revision 0)
+++ binutils/gas/testsuite/gas/i386/debug1.s	(revision 0)
@@ -0,0 +1,5 @@
+	.file "debug1.s"
+	.text
+	nop
+	nop
+	nop
Index: binutils/gas/testsuite/gas/elf/dwarf2-1.s
===================================================================
--- binutils/gas/testsuite/gas/elf/dwarf2-1.s	(revision 0)
+++ binutils/gas/testsuite/gas/elf/dwarf2-1.s	(revision 0)
@@ -0,0 +1,218 @@
+/* This testcase is derived from a similar test in GDB.
+
+   Copyright 2009 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* This tests that gdb can read compressed sections.  The contents
+   are a basic assembly file, but the .debug_abbrev section has been
+   comrpessed using zlib.  */
+
+/* Dummy function to provide debug information for.  */
+
+	.text
+	.globl _start
+_start:
+	.int 0
+.Lbegin_text1:
+	.globl func_cu1
+	.type func_cu1, %function
+func_cu1:
+.Lbegin_func_cu1:
+	.int 0
+.Lend_func_cu1:
+	.size func_cu1, .-func_cu1
+.Lend_text1:
+
+/* Debug information */
+
+	.section .debug_info
+.Lcu1_begin:
+	/* CU header */
+	.4byte	.Lcu1_end - .Lcu1_start		/* Length of Compilation Unit */
+.Lcu1_start:
+	.2byte	2				/* DWARF Version */
+	.4byte	.Labbrev1_begin			/* Offset into abbrev section */
+	.byte	4				/* Pointer size */
+
+	/* CU die */
+	.uleb128 1				/* Abbrev: DW_TAG_compile_unit */
+	.4byte	.Lline1_begin			/* DW_AT_stmt_list */
+	.4byte	.Lend_text1			/* DW_AT_high_pc */
+	.4byte	.Lbegin_text1			/* DW_AT_low_pc */
+	.ascii	"file1.txt\0"			/* DW_AT_name */
+	.ascii	"GNU C 3.3.3\0"			/* DW_AT_producer */
+	.byte	1				/* DW_AT_language (C) */
+
+	/* func_cu1 */
+	.uleb128	2			/* Abbrev: DW_TAG_subprogram */
+	.byte		1			/* DW_AT_external */
+	.byte		1			/* DW_AT_decl_file */
+	.byte		2			/* DW_AT_decl_line */
+	.ascii		"func_cu1\0"		/* DW_AT_name */
+	.4byte		.Ltype_int-.Lcu1_begin	/* DW_AT_type */
+	.4byte		.Lbegin_func_cu1	/* DW_AT_low_pc */
+	.4byte		.Lend_func_cu1		/* DW_AT_high_pc */
+	.byte		1			/* DW_AT_frame_base: length */
+	.byte		0x55			/* DW_AT_frame_base: DW_OP_reg5 */
+
+.Ltype_int:
+	.uleb128	3			/* Abbrev: DW_TAG_base_type */
+	.ascii		"int\0"			/* DW_AT_name */
+	.byte		4			/* DW_AT_byte_size */
+	.byte		5			/* DW_AT_encoding */
+
+	.byte		0			/* End of children of CU */
+
+.Lcu1_end:
+
+/* Line table */
+	.section .debug_line
+.Lline1_begin:
+	.4byte		.Lline1_end - .Lline1_start	/* Initial length */
+.Lline1_start:
+	.2byte		2			/* Version */
+	.4byte		.Lline1_lines - .Lline1_hdr	/* header_length */
+.Lline1_hdr:
+	.byte		1			/* Minimum insn length */
+	.byte		1			/* default_is_stmt */
+	.byte		1			/* line_base */
+ 	.byte		1			/* line_range */
+	.byte		0x10			/* opcode_base */
+
+	/* Standard lengths */
+	.byte		0
+	.byte		1
+	.byte		1
+	.byte		1
+	.byte		1
+	.byte		0
+	.byte		0
+	.byte		0
+	.byte		1
+	.byte		0
+	.byte		0
+	.byte		1
+	.byte		0
+	.byte		0
+	.byte		0
+
+	/* Include directories */
+	.byte		0
+
+	/* File names */
+	.ascii		"file1.txt\0"
+	.uleb128	0
+	.uleb128	0
+	.uleb128	0
+
+	.byte		0
+
+.Lline1_lines:
+	.byte		0	/* DW_LNE_set_address */
+	.uleb128	5
+	.byte		2
+	.4byte		.Lbegin_func_cu1
+
+	.byte		3	/* DW_LNS_advance_line */
+	.sleb128	3	/* ... to 4 */
+
+	.byte		1	/* DW_LNS_copy */
+
+	.byte		1	/* DW_LNS_copy (second time as an end-of-prologue marker) */
+
+	.byte		0	/* DW_LNE_set_address */
+	.uleb128	5
+	.byte		2
+	.4byte		.Lend_func_cu1
+
+	.byte		0	/* DW_LNE_end_of_sequence */
+	.uleb128	1
+	.byte		1
+
+.Lline1_end:
+
+/* Abbrev table -- compressed */
+	.section .zdebug_abbrev
+.Labbrev1_begin:
+	.ascii		"ZLIB"
+	.4byte		0
+	.2byte		0
+	.byte		0
+	.byte		51
+	.byte		0x78
+	.byte		0x5e
+	.byte		0x63
+	.byte		0x14
+	.byte		0x64
+	.byte		0x14
+	.byte		0x60
+	.byte		0x13
+	.byte		0x62
+	.byte		0x14
+	.byte		0x64
+	.byte		0x64
+	.byte		0xe6
+	.byte		0x50
+	.byte		0xe5
+	.byte		0x10
+	.byte		0xe6
+	.byte		0x66
+	.byte		0x60
+	.byte		0x60
+	.byte		0xd2
+	.byte		0x63
+	.byte		0xb0
+	.byte		0xe7
+	.byte		0xb1
+	.byte		0xe2
+	.byte		0xb6
+	.byte		0xe6
+	.byte		0x66
+	.byte		0xe6
+	.byte		0xf0
+	.byte		0x14
+	.byte		0x16
+	.byte		0x64
+	.byte		0x14
+	.byte		0x62
+	.byte		0x74
+	.byte		0xe0
+	.byte		0x02
+	.byte		0x00
+	.byte		0x25
+	.byte		0x78
+	.byte		0x02
+	.byte		0x81
+	.byte		0x78
+	.byte		0x9c
+	.byte		0x63
+	.byte		0x60
+	.byte		0x60
+	.byte		0x56
+	.byte		0x61
+	.byte		0x60
+	.byte		0xe6
+	.byte		0xe0
+	.byte		0xe6
+	.byte		0xb6
+	.byte		0xe3
+	.byte		0x66
+	.byte		0x00
+	.byte		0x02
+	.byte		0x00
+	.byte		0x04
+	.byte		0x9c
+	.byte		0x00
+	.byte		0x92
Index: binutils/gas/testsuite/gas/elf/dwarf2-2.s
===================================================================
--- binutils/gas/testsuite/gas/elf/dwarf2-2.s	(revision 0)
+++ binutils/gas/testsuite/gas/elf/dwarf2-2.s	(revision 0)
@@ -0,0 +1,218 @@
+/* This testcase is derived from a similar test in GDB.
+
+   Copyright 2009 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* This tests that gdb can read compressed sections.  The contents
+   are a basic assembly file, but the .debug_abbrev section has been
+   comrpessed using zlib.  */
+
+/* Dummy function to provide debug information for.  */
+
+	.section .gnu.linkonce.t.foo,"axG",%progbits,foo,comdat
+	.globl _start
+_start:
+	.int 0
+.Lbegin_text1:
+	.globl func_cu1
+	.type func_cu1, %function
+func_cu1:
+.Lbegin_func_cu1:
+	.int 0
+.Lend_func_cu1:
+	.size func_cu1, .-func_cu1
+.Lend_text1:
+
+/* Debug information */
+
+	.section .debug_info,"G",%progbits,foo,comdat
+.Lcu1_begin:
+	/* CU header */
+	.4byte	.Lcu1_end - .Lcu1_start		/* Length of Compilation Unit */
+.Lcu1_start:
+	.2byte	2				/* DWARF Version */
+	.4byte	.Labbrev1_begin			/* Offset into abbrev section */
+	.byte	4				/* Pointer size */
+
+	/* CU die */
+	.uleb128 1				/* Abbrev: DW_TAG_compile_unit */
+	.4byte	.Lline1_begin			/* DW_AT_stmt_list */
+	.4byte	.Lend_text1			/* DW_AT_high_pc */
+	.4byte	.Lbegin_text1			/* DW_AT_low_pc */
+	.ascii	"file1.txt\0"			/* DW_AT_name */
+	.ascii	"GNU C 3.3.3\0"			/* DW_AT_producer */
+	.byte	1				/* DW_AT_language (C) */
+
+	/* func_cu1 */
+	.uleb128	2			/* Abbrev: DW_TAG_subprogram */
+	.byte		1			/* DW_AT_external */
+	.byte		1			/* DW_AT_decl_file */
+	.byte		2			/* DW_AT_decl_line */
+	.ascii		"func_cu1\0"		/* DW_AT_name */
+	.4byte		.Ltype_int-.Lcu1_begin	/* DW_AT_type */
+	.4byte		.Lbegin_func_cu1	/* DW_AT_low_pc */
+	.4byte		.Lend_func_cu1		/* DW_AT_high_pc */
+	.byte		1			/* DW_AT_frame_base: length */
+	.byte		0x55			/* DW_AT_frame_base: DW_OP_reg5 */
+
+.Ltype_int:
+	.uleb128	3			/* Abbrev: DW_TAG_base_type */
+	.ascii		"int\0"			/* DW_AT_name */
+	.byte		4			/* DW_AT_byte_size */
+	.byte		5			/* DW_AT_encoding */
+
+	.byte		0			/* End of children of CU */
+
+.Lcu1_end:
+
+/* Line table */
+	.section .debug_line,"G",%progbits,foo,comdat
+.Lline1_begin:
+	.4byte		.Lline1_end - .Lline1_start	/* Initial length */
+.Lline1_start:
+	.2byte		2			/* Version */
+	.4byte		.Lline1_lines - .Lline1_hdr	/* header_length */
+.Lline1_hdr:
+	.byte		1			/* Minimum insn length */
+	.byte		1			/* default_is_stmt */
+	.byte		1			/* line_base */
+ 	.byte		1			/* line_range */
+	.byte		0x10			/* opcode_base */
+
+	/* Standard lengths */
+	.byte		0
+	.byte		1
+	.byte		1
+	.byte		1
+	.byte		1
+	.byte		0
+	.byte		0
+	.byte		0
+	.byte		1
+	.byte		0
+	.byte		0
+	.byte		1
+	.byte		0
+	.byte		0
+	.byte		0
+
+	/* Include directories */
+	.byte		0
+
+	/* File names */
+	.ascii		"file1.txt\0"
+	.uleb128	0
+	.uleb128	0
+	.uleb128	0
+
+	.byte		0
+
+.Lline1_lines:
+	.byte		0	/* DW_LNE_set_address */
+	.uleb128	5
+	.byte		2
+	.4byte		.Lbegin_func_cu1
+
+	.byte		3	/* DW_LNS_advance_line */
+	.sleb128	3	/* ... to 4 */
+
+	.byte		1	/* DW_LNS_copy */
+
+	.byte		1	/* DW_LNS_copy (second time as an end-of-prologue marker) */
+
+	.byte		0	/* DW_LNE_set_address */
+	.uleb128	5
+	.byte		2
+	.4byte		.Lend_func_cu1
+
+	.byte		0	/* DW_LNE_end_of_sequence */
+	.uleb128	1
+	.byte		1
+
+.Lline1_end:
+
+/* Abbrev table -- compressed */
+	.section .zdebug_abbrev,"G",%progbits,foo,comdat
+.Labbrev1_begin:
+	.ascii		"ZLIB"
+	.4byte		0
+	.2byte		0
+	.byte		0
+	.byte		51
+	.byte		0x78
+	.byte		0x5e
+	.byte		0x63
+	.byte		0x14
+	.byte		0x64
+	.byte		0x14
+	.byte		0x60
+	.byte		0x13
+	.byte		0x62
+	.byte		0x14
+	.byte		0x64
+	.byte		0x64
+	.byte		0xe6
+	.byte		0x50
+	.byte		0xe5
+	.byte		0x10
+	.byte		0xe6
+	.byte		0x66
+	.byte		0x60
+	.byte		0x60
+	.byte		0xd2
+	.byte		0x63
+	.byte		0xb0
+	.byte		0xe7
+	.byte		0xb1
+	.byte		0xe2
+	.byte		0xb6
+	.byte		0xe6
+	.byte		0x66
+	.byte		0xe6
+	.byte		0xf0
+	.byte		0x14
+	.byte		0x16
+	.byte		0x64
+	.byte		0x14
+	.byte		0x62
+	.byte		0x74
+	.byte		0xe0
+	.byte		0x02
+	.byte		0x00
+	.byte		0x25
+	.byte		0x78
+	.byte		0x02
+	.byte		0x81
+	.byte		0x78
+	.byte		0x9c
+	.byte		0x63
+	.byte		0x60
+	.byte		0x60
+	.byte		0x56
+	.byte		0x61
+	.byte		0x60
+	.byte		0xe6
+	.byte		0xe0
+	.byte		0xe6
+	.byte		0xb6
+	.byte		0xe3
+	.byte		0x66
+	.byte		0x00
+	.byte		0x02
+	.byte		0x00
+	.byte		0x04
+	.byte		0x9c
+	.byte		0x00
+	.byte		0x92
Index: binutils/gas/testsuite/gas/elf/elf.exp
===================================================================
--- binutils/gas/testsuite/gas/elf/elf.exp	(revision 6552)
+++ binutils/gas/testsuite/gas/elf/elf.exp	(working copy)
@@ -145,4 +145,6 @@ if { ([istarget "*-*-*elf*"]		
 
     run_dump_test "section6" 
     run_dump_test "section7" 
+    run_dump_test "dwarf2-1" 
+    run_dump_test "dwarf2-2" 
 }
Index: binutils/gas/testsuite/gas/elf/dwarf2-1.d
===================================================================
--- binutils/gas/testsuite/gas/elf/dwarf2-1.d	(revision 0)
+++ binutils/gas/testsuite/gas/elf/dwarf2-1.d	(revision 0)
@@ -0,0 +1,99 @@
+#readelf: -w
+#name: DWARF2 1
+
+Contents of the .debug_info section:
+
+  Compilation Unit @ offset 0x0:
+   Length:        0x4e \(32-bit\)
+   Version:       2
+   Abbrev Offset: 0
+   Pointer Size:  4
+ <0><b>: Abbrev Number: 1 \(DW_TAG_compile_unit\)
+    < c>   DW_AT_stmt_list   : 0x0	
+    <10>   DW_AT_high_pc     : 0x.	
+    <14>   DW_AT_low_pc      : 0x.	
+    <18>   DW_AT_name        : file1.txt	
+    <22>   DW_AT_producer    : GNU C 3.3.3	
+    <2e>   DW_AT_language    : 1	\(ANSI C\)
+ <1><2f>: Abbrev Number: 2 \(DW_TAG_subprogram\)
+    <30>   DW_AT_external    : 1	
+    <31>   DW_AT_decl_file   : 1	
+    <32>   DW_AT_decl_line   : 2	
+    <33>   DW_AT_name        : func_cu1	
+    <3c>   DW_AT_type        : <0x4a>	
+    <40>   DW_AT_low_pc      : 0x.	
+    <44>   DW_AT_high_pc     : 0x.	
+    <48>   DW_AT_frame_base  : 1 byte block: 55 	\(DW_OP_reg5\)
+ <1><4a>: Abbrev Number: 3 \(DW_TAG_base_type\)
+    <4b>   DW_AT_name        : int	
+    <4f>   DW_AT_byte_size   : 4	
+    <50>   DW_AT_encoding    : 5	\(signed\)
+
+Raw dump of debug contents of section .debug_line:
+
+  Offset:                      0x0
+  Length:                      62
+  DWARF Version:               2
+  Prologue Length:             35
+  Minimum Instruction Length:  1
+  Initial value of 'is_stmt':  1
+  Line Base:                   1
+  Line Range:                  1
+  Opcode Base:                 16
+
+ Opcodes:
+  Opcode 1 has 0 args
+  Opcode 2 has 1 args
+  Opcode 3 has 1 args
+  Opcode 4 has 1 args
+  Opcode 5 has 1 args
+  Opcode 6 has 0 args
+  Opcode 7 has 0 args
+  Opcode 8 has 0 args
+  Opcode 9 has 1 args
+  Opcode 10 has 0 args
+  Opcode 11 has 0 args
+  Opcode 12 has 1 args
+  Opcode 13 has 0 args
+  Opcode 14 has 0 args
+  Opcode 15 has 0 args
+
+ The Directory Table is empty.
+
+ The File Name Table:
+  Entry	Dir	Time	Size	Name
+  1	0	0	0	file1.txt
+
+ Line Number Statements:
+  Extended opcode 2: set Address to .*
+  Advance Line by 3 to 4
+  Copy
+  Copy
+  Extended opcode 2: set Address to .*
+  Extended opcode 1: End of Sequence
+
+
+Contents of the .zdebug_abbrev section:
+
+  Number TAG
+   1      DW_TAG_compile_unit    \[has children\]
+    DW_AT_stmt_list    DW_FORM_data4
+    DW_AT_high_pc      DW_FORM_addr
+    DW_AT_low_pc       DW_FORM_addr
+    DW_AT_name         DW_FORM_string
+    DW_AT_producer     DW_FORM_string
+    DW_AT_language     DW_FORM_data1
+   2      DW_TAG_subprogram    \[no children\]
+    DW_AT_external     DW_FORM_flag
+    DW_AT_decl_file    DW_FORM_data1
+    DW_AT_decl_line    DW_FORM_data1
+    DW_AT_name         DW_FORM_string
+    DW_AT_type         DW_FORM_ref4
+    DW_AT_low_pc       DW_FORM_addr
+    DW_AT_high_pc      DW_FORM_addr
+    DW_AT_frame_base   DW_FORM_block1
+   3      DW_TAG_base_type    \[no children\]
+    DW_AT_name         DW_FORM_string
+    DW_AT_byte_size    DW_FORM_data1
+    DW_AT_encoding     DW_FORM_data1
+
Index: binutils/gas/testsuite/gas/elf/dwarf2-2.d
===================================================================
--- binutils/gas/testsuite/gas/elf/dwarf2-2.d	(revision 0)
+++ binutils/gas/testsuite/gas/elf/dwarf2-2.d	(revision 0)
@@ -0,0 +1,99 @@
+#readelf: -w
+#name: DWARF2 2
+
+Contents of the .debug_info section:
+
+  Compilation Unit @ offset 0x0:
+   Length:        0x4e \(32-bit\)
+   Version:       2
+   Abbrev Offset: 0
+   Pointer Size:  4
+ <0><b>: Abbrev Number: 1 \(DW_TAG_compile_unit\)
+    < c>   DW_AT_stmt_list   : 0x0	
+    <10>   DW_AT_high_pc     : 0x.	
+    <14>   DW_AT_low_pc      : 0x.	
+    <18>   DW_AT_name        : file1.txt	
+    <22>   DW_AT_producer    : GNU C 3.3.3	
+    <2e>   DW_AT_language    : 1	\(ANSI C\)
+ <1><2f>: Abbrev Number: 2 \(DW_TAG_subprogram\)
+    <30>   DW_AT_external    : 1	
+    <31>   DW_AT_decl_file   : 1	
+    <32>   DW_AT_decl_line   : 2	
+    <33>   DW_AT_name        : func_cu1	
+    <3c>   DW_AT_type        : <0x4a>	
+    <40>   DW_AT_low_pc      : 0x.	
+    <44>   DW_AT_high_pc     : 0x.	
+    <48>   DW_AT_frame_base  : 1 byte block: 55 	\(DW_OP_reg5\)
+ <1><4a>: Abbrev Number: 3 \(DW_TAG_base_type\)
+    <4b>   DW_AT_name        : int	
+    <4f>   DW_AT_byte_size   : 4	
+    <50>   DW_AT_encoding    : 5	\(signed\)
+
+Raw dump of debug contents of section .debug_line:
+
+  Offset:                      0x0
+  Length:                      62
+  DWARF Version:               2
+  Prologue Length:             35
+  Minimum Instruction Length:  1
+  Initial value of 'is_stmt':  1
+  Line Base:                   1
+  Line Range:                  1
+  Opcode Base:                 16
+
+ Opcodes:
+  Opcode 1 has 0 args
+  Opcode 2 has 1 args
+  Opcode 3 has 1 args
+  Opcode 4 has 1 args
+  Opcode 5 has 1 args
+  Opcode 6 has 0 args
+  Opcode 7 has 0 args
+  Opcode 8 has 0 args
+  Opcode 9 has 1 args
+  Opcode 10 has 0 args
+  Opcode 11 has 0 args
+  Opcode 12 has 1 args
+  Opcode 13 has 0 args
+  Opcode 14 has 0 args
+  Opcode 15 has 0 args
+
+ The Directory Table is empty.
+
+ The File Name Table:
+  Entry	Dir	Time	Size	Name
+  1	0	0	0	file1.txt
+
+ Line Number Statements:
+  Extended opcode 2: set Address to .*
+  Advance Line by 3 to 4
+  Copy
+  Copy
+  Extended opcode 2: set Address to .*
+  Extended opcode 1: End of Sequence
+
+
+Contents of the .zdebug_abbrev section:
+
+  Number TAG
+   1      DW_TAG_compile_unit    \[has children\]
+    DW_AT_stmt_list    DW_FORM_data4
+    DW_AT_high_pc      DW_FORM_addr
+    DW_AT_low_pc       DW_FORM_addr
+    DW_AT_name         DW_FORM_string
+    DW_AT_producer     DW_FORM_string
+    DW_AT_language     DW_FORM_data1
+   2      DW_TAG_subprogram    \[no children\]
+    DW_AT_external     DW_FORM_flag
+    DW_AT_decl_file    DW_FORM_data1
+    DW_AT_decl_line    DW_FORM_data1
+    DW_AT_name         DW_FORM_string
+    DW_AT_type         DW_FORM_ref4
+    DW_AT_low_pc       DW_FORM_addr
+    DW_AT_high_pc      DW_FORM_addr
+    DW_AT_frame_base   DW_FORM_block1
+   3      DW_TAG_base_type    \[no children\]
+    DW_AT_name         DW_FORM_string
+    DW_AT_byte_size    DW_FORM_data1
+    DW_AT_encoding     DW_FORM_data1
+
Index: binutils/gas/as.c
===================================================================
--- binutils/gas/as.c	(revision 6552)
+++ binutils/gas/as.c	(working copy)
@@ -72,6 +72,9 @@ struct defsym_list
 /* True if a listing is wanted.  */
 int listing;
 
+/* If assembler shiuld debug info.  */
+enum debug_info_type gen_debug = DEBUG_UNSPECIFIED;
+
 /* Type of debugging to generate.  */
 enum debug_info_type debug_type = DEBUG_UNSPECIFIED;
 int use_gnu_debug_info_extensions = 0;
@@ -908,6 +911,8 @@ This program has absolutely no warranty.
 	}
     }
 
+  gen_debug = debug_type;
+
   free (shortopts);
   free (longopts);
 
Index: binutils/gas/as.h
===================================================================
--- binutils/gas/as.h	(revision 6552)
+++ binutils/gas/as.h	(working copy)
@@ -429,6 +429,7 @@ enum debug_info_type
   DEBUG_DWARF2
 };
 
+extern enum debug_info_type gen_debug;
 extern enum debug_info_type debug_type;
 extern int use_gnu_debug_info_extensions;
 \f
Index: binutils/gas/subsegs.c
===================================================================
--- binutils/gas/subsegs.c	(revision 6552)
+++ binutils/gas/subsegs.c	(working copy)
@@ -148,15 +148,6 @@ subseg_get (const char *segname, int for
 {
   segT secptr;
   segment_info_type *seginfo;
-  const char *now_seg_name = (now_seg
-			      ? bfd_get_section_name (stdoutput, now_seg)
-			      : 0);
-
-  if (!force_new
-      && now_seg_name
-      && (now_seg_name == segname
-	  || !strcmp (now_seg_name, segname)))
-    return now_seg;
 
   if (!force_new)
     secptr = bfd_make_section_old_way (stdoutput, segname);
Index: binutils/binutils/testsuite/binutils-all/objdump.W
===================================================================
--- binutils/binutils/testsuite/binutils-all/objdump.W	(revision 6552)
+++ binutils/binutils/testsuite/binutils-all/objdump.W	(working copy)
@@ -73,36 +73,6 @@ Raw dump of debug contents of section .d
   Extended opcode 1: End of Sequence
 
 
-  Offset:                      0x42
-  Length:                      25
-  DWARF Version:               2
-  Prologue Length:             19
-  Minimum Instruction Length:  [1248]
-  Initial value of 'is_stmt':  1
-  Line Base:                   -5
-  Line Range:                  14
-  Opcode Base:                 13
-
- Opcodes:
-  Opcode 1 has 0 args
-  Opcode 2 has 1 args
-  Opcode 3 has 1 args
-  Opcode 4 has 1 args
-  Opcode 5 has 1 args
-  Opcode 6 has 0 args
-  Opcode 7 has 0 args
-  Opcode 8 has 0 args
-  Opcode 9 has 1 args
-  Opcode 10 has 0 args
-  Opcode 11 has 0 args
-  Opcode 12 has 1 args
-
- The Directory Table is empty.
-
- The File Name Table is empty.
-
- Line Number Statements:
-
 Contents of the .zdebug_abbrev section:
 
   Number TAG
Index: binutils/bfd/section.c
===================================================================
--- binutils/bfd/section.c	(revision 6552)
+++ binutils/bfd/section.c	(working copy)
@@ -138,6 +138,7 @@ SUBSECTION
 #include "bfd.h"
 #include "libbfd.h"
 #include "bfdlink.h"
+#include "elf-bfd.h"
 
 /*
 DOCDD
@@ -854,11 +855,31 @@ asection *
 bfd_get_section_by_name (bfd *abfd, const char *name)
 {
   struct section_hash_entry *sh;
+  unsigned long hash;
+  asection *sec;
 
   sh = section_hash_lookup (&abfd->section_htab, name, FALSE, FALSE);
-  if (sh != NULL)
+  if (sh == NULL)
+    return NULL;
+
+  /* Only ELF has section group. */
+  if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
     return &sh->section;
 
+  hash = sh->root.hash;
+  do
+    {
+      sec = &sh->section;
+      /* Don't return a section in a section group.  */
+      if (elf_section_data (sec) == NULL
+	  || elf_group_name (sec) == NULL)
+	return sec;
+      sh = (struct section_hash_entry *) sh->root.next;
+    }
+  while (sh != NULL
+	 && sh->root.hash == hash
+	 && strcmp (sh->root.string, name) == 0);
+
   return NULL;
 }
 
@@ -1011,7 +1032,43 @@ bfd_make_section_old_way (bfd *abfd, con
       if (sh == NULL)
 	return NULL;
 
-      newsect = &sh->section;
+      /* Only ELF has section group. */
+      if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+	{
+	  struct section_hash_entry *old_sh = sh;
+	  unsigned long hash = sh->root.hash;
+
+	  do
+	    {
+	      newsect = &sh->section;
+	      /* Don't use a section in a section group.  */
+	      if (elf_section_data (newsect) == NULL
+		  || elf_group_name (newsect) == NULL)
+		break;
+	      sh = (struct section_hash_entry *) sh->root.next;
+	    }
+	  while (sh != NULL
+		 && sh->root.hash == hash
+		 && strcmp (sh->root.string, name) == 0);
+
+	  if (sh == NULL)
+	    {
+	      /* Allocate a new one since existing sections are in
+		 section groups.  */
+	      struct section_hash_entry *new_sh;
+	      new_sh = (struct section_hash_entry *)
+		bfd_section_hash_newfunc (NULL, &abfd->section_htab, name);
+	      if (new_sh == NULL)
+		return NULL;
+
+	      new_sh->root = old_sh->root;
+	      old_sh->root.next = &new_sh->root;
+	      newsect = &new_sh->section;
+	    }
+	}
+      else
+	newsect = &sh->section;
+
       if (newsect->name != NULL)
 	{
 	  /* Section already exists.  */

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: PATCH: PR gas/10531: Strange assembler warning message on section   group
  2009-08-22 19:10               ` H.J. Lu
@ 2009-08-23  7:28                 ` H.J. Lu
  2009-10-26 22:11                   ` Jim Wilson
  0 siblings, 1 reply; 20+ messages in thread
From: H.J. Lu @ 2009-08-23  7:28 UTC (permalink / raw)
  To: Jim Wilson; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 2958 bytes --]

On Sat, Aug 22, 2009 at 10:32 AM, H.J. Lu<hjl.tools@gmail.com> wrote:
> On Thu, Aug 20, 2009 at 9:26 PM, H.J. Lu<hjl.tools@gmail.com> wrote:
>> On Thu, Aug 20, 2009 at 6:49 PM, H.J. Lu<hjl.tools@gmail.com> wrote:
>>> On Thu, Aug 20, 2009 at 2:08 PM, Jim Wilson<wilson@codesourcery.com> wrote:
>>>> On Wed, 2009-08-19 at 18:20 -0700, H.J. Lu wrote:
>>>>> I didn't see the problem with my icc, using the patched
>>>>> assembler. Can you provide main.s compiled by your icc?
>>>>
>>>> I tried your patch.  Gas isn't emitting a spurious warning anymore, but
>>>> it is still emitting bogus debug info, which is what I expected.
>>>>
>>>> To see the problem, just put a breakpoint in the function
>>>> out_debug_line.  You will see that we hit the breakpoint, even though we
>>>> should not, because the input assembly file already has a fully
>>>> populated debug_line section.
>>>>
>>>> You patch is doing something useful; it is making sure that gas picks up
>>>> up the correct (non-comdat) debug_line section.  But it doesn't stop gas
>>>> from emitting the bogus debug info.
>>>>
>>>> Jim
>>>>
>>>
>>> Hi Jim,
>>>
>>> I think we have been generate bogus debug line info forever when .loc
>>> directive isn't used.  Does it patch make any senses?
>>>
>>
>> Here is the updated patch. We should generate DWARF info only
>> when -g or .loc directives are used.  OK to install?
>>
>> Thanks.
>>
>>
>
> Here is a new patch with updated testcases. OK to install?
>

Hi,

This patch hadles ".file" directives properly with a new testcase from gcc 3.4.
OK to install?

Thanks.

H.J.
--
bfd/

2009-08-22  H.J. Lu  <hongjiu.lu@intel.com>

	PR gas/10531
	* section.c: Include "elf-bfd.h".
	(bfd_get_section_by_name): Don't use a section in a section
	group.
	(bfd_make_section_old_way): Likewise.

binutils/testsuite/

2009-08-22  H.J. Lu  <hongjiu.lu@intel.com>

	PR gas/10531
	* binutils-all/objdump.W: Remove bogus line debug info.

gas/

2009-08-22  H.J. Lu  <hongjiu.lu@intel.com>

	PR gas/10531
	* as.c (gen_debug): New.
	(parse_args): Set gen_debug to debug_type.

	* as.h (gen_debug): New.

	* dwarf2dbg.c (dwarf2_directive_used): New.
	(dwarf2_directive_file): Set dwarf2_directive_used.
	(dwarf2_directive_loc): Likewise.
	(dwarf2_directive_used): Likewise.
	(dwarf2_finish): Return if -g isn't passed nor any .file/.loc
	directive is used.

	* subsegs.c (subseg_get): Don't compare segment name.

gas/testsuite/

2009-08-22  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * gas/elf/dwarf2-1.d: New.
	 * gas/elf/dwarf2-1.s: Likewise.
	 * gas/elf/dwarf2-2.d: Likewise.
	 * gas/elf/dwarf2-2.s: Likewise.
	 * gas/elf/dwarf2-3.d: Likewise.
	 * gas/elf/dwarf2-3.s: Likewise.
	 * gas/i386/debug1.d: Likewise.
	 * gas/i386/debug1.s: Likewise.

	* gas/elf/elf.exp: Run dwarf2-1, dwarf2-2 and dwarf2-3.

	* gas/i386/i386.exp: Run debug1 for both 32bit and 64bit.

[-- Attachment #2: binutils-group-7.patch --]
[-- Type: application/octet-stream, Size: 31616 bytes --]

bfd/

2009-08-22  H.J. Lu  <hongjiu.lu@intel.com>

	PR gas/10531
	* section.c: Include "elf-bfd.h".
	(bfd_get_section_by_name): Don't use a section in a section
	group.
	(bfd_make_section_old_way): Likewise.

binutils/testsuite/

2009-08-22  H.J. Lu  <hongjiu.lu@intel.com>

	PR gas/10531
	* binutils-all/objdump.W: Remove bogus line debug info.

gas/

2009-08-22  H.J. Lu  <hongjiu.lu@intel.com>

	PR gas/10531
	* as.c (gen_debug): New.
	(parse_args): Set gen_debug to debug_type.

	* as.h (gen_debug): New.

	* dwarf2dbg.c (dwarf2_directive_used): New.
	(dwarf2_directive_file): Set dwarf2_directive_used.
	(dwarf2_directive_loc): Likewise.
	(dwarf2_directive_used): Likewise.
	(dwarf2_finish): Return if -g isn't passed nor any .file/.loc
	directive is used.

	* subsegs.c (subseg_get): Don't compare segment name.

gas/testsuite/

2009-08-22  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * gas/elf/dwarf2-1.d: New.
	 * gas/elf/dwarf2-1.s: Likewise.
	 * gas/elf/dwarf2-2.d: Likewise.
	 * gas/elf/dwarf2-2.s: Likewise.
	 * gas/elf/dwarf2-3.d: Likewise.
	 * gas/elf/dwarf2-3.s: Likewise.
	 * gas/i386/debug1.d: Likewise.
	 * gas/i386/debug1.s: Likewise.

	* gas/elf/elf.exp: Run dwarf2-1, dwarf2-2 and dwarf2-3.

	* gas/i386/i386.exp: Run debug1 for both 32bit and 64bit.

Index: binutils/gas/dwarf2dbg.c
===================================================================
--- binutils/gas/dwarf2dbg.c	(revision 6552)
+++ binutils/gas/dwarf2dbg.c	(working copy)
@@ -188,6 +188,9 @@ static unsigned int dirs_allocated;
    doing work when there's nothing to do.  */
 bfd_boolean dwarf2_loc_directive_seen;
 
+/* TRUE when any .file/.loc directive is used.  */
+static bfd_boolean dwarf2_directive_used;
+
 /* TRUE when we're supposed to set the basic block mark whenever a
    label is seen.  */
 bfd_boolean dwarf2_loc_mark_labels;
@@ -555,6 +558,8 @@ dwarf2_directive_file (int dummy ATTRIBU
 
   get_filenum (filename, num);
 
+  dwarf2_directive_used = TRUE;
+
   return filename;
 }
 
@@ -688,6 +693,7 @@ dwarf2_directive_loc (int dummy ATTRIBUT
 
   demand_empty_rest_of_line ();
   dwarf2_loc_directive_seen = TRUE;
+  dwarf2_directive_used = TRUE;
   debug_type = DEBUG_NONE;
 }
 
@@ -706,6 +712,8 @@ dwarf2_directive_loc_mark_labels (int du
       dwarf2_loc_mark_labels = value != 0;
       demand_empty_rest_of_line ();
     }
+
+  dwarf2_directive_used = TRUE;
 }
 \f
 static struct frag *
@@ -1718,6 +1726,10 @@ dwarf2_finish (void)
   segT info_seg;
   int emit_other_sections = 0;
 
+  /* Return if -g isn't passed nor any .file/.loc directive is used.  */
+  if (!dwarf2_directive_used && gen_debug == DEBUG_UNSPECIFIED)
+    return;
+
   info_seg = bfd_get_section_by_name (stdoutput, ".debug_info");
   emit_other_sections = info_seg == NULL || !seg_not_empty_p (info_seg);
 
Index: binutils/gas/testsuite/gas/i386/i386.exp
===================================================================
--- binutils/gas/testsuite/gas/i386/i386.exp	(revision 6552)
+++ binutils/gas/testsuite/gas/i386/i386.exp	(working copy)
@@ -190,6 +190,7 @@ if [expr ([istarget "i*86-*-*"] ||  [ist
 	run_list_test "inval-equ-2" "-al"
 	run_dump_test "ifunc"
 	run_list_test "l1om-inval" "-march=l1om --32"
+	run_dump_test "debug1"
     }
 
     # This is a PE specific test.
@@ -348,6 +349,7 @@ if [expr ([istarget "i*86-*-*"] || [ista
 	run_dump_test "mixed-mode-reloc64"
 	run_dump_test "x86-64-ifunc"
 	run_dump_test "l1om"
+	run_dump_test "debug1"
     }
 
     set ASFLAGS "$old_ASFLAGS"
Index: binutils/gas/testsuite/gas/i386/debug1.d
===================================================================
--- binutils/gas/testsuite/gas/i386/debug1.d	(revision 0)
+++ binutils/gas/testsuite/gas/i386/debug1.d	(revision 0)
@@ -0,0 +1,46 @@
+#as: --gdwarf-2
+#readelf: -wl
+#name: DWARF2 debugging information 1
+
+Raw dump of debug contents of section .debug_line:
+
+  Offset:                      0x0
+  Length:                      .*
+  DWARF Version:               2
+  Prologue Length:             .*
+  Minimum Instruction Length:  1
+  Initial value of 'is_stmt':  1
+  Line Base:                   -5
+  Line Range:                  14
+  Opcode Base:                 13
+
+ Opcodes:
+  Opcode 1 has 0 args
+  Opcode 2 has 1 args
+  Opcode 3 has 1 args
+  Opcode 4 has 1 args
+  Opcode 5 has 1 args
+  Opcode 6 has 0 args
+  Opcode 7 has 0 args
+  Opcode 8 has 0 args
+  Opcode 9 has 1 args
+  Opcode 10 has 0 args
+  Opcode 11 has 0 args
+  Opcode 12 has 1 args
+
+ The Directory Table:
+  .*
+
+ The File Name Table:
+  Entry	Dir	Time	Size	Name
+  1	1	0	0	debug1.s
+
+ Line Number Statements:
+  Extended opcode 2: set Address to 0x0
+  Special opcode 7: advance Address by 0 to 0x0 and Line by 2 to 3
+  Special opcode 20: advance Address by 1 to 0x1 and Line by 1 to 4
+  Special opcode 20: advance Address by 1 to 0x2 and Line by 1 to 5
+  Advance PC by 1 to 0x3
+  Extended opcode 1: End of Sequence
+
+
Index: binutils/gas/testsuite/gas/i386/debug1.s
===================================================================
--- binutils/gas/testsuite/gas/i386/debug1.s	(revision 0)
+++ binutils/gas/testsuite/gas/i386/debug1.s	(revision 0)
@@ -0,0 +1,5 @@
+	.file "debug1.s"
+	.text
+	nop
+	nop
+	nop
Index: binutils/gas/testsuite/gas/elf/dwarf2-1.s
===================================================================
--- binutils/gas/testsuite/gas/elf/dwarf2-1.s	(revision 0)
+++ binutils/gas/testsuite/gas/elf/dwarf2-1.s	(revision 0)
@@ -0,0 +1,219 @@
+/* This testcase is derived from a similar test in GDB.
+
+   Copyright 2009 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* This tests that gdb can read compressed sections.  The contents
+   are a basic assembly file, but the .debug_abbrev section has been
+   comrpessed using zlib.  */
+
+/* Dummy function to provide debug information for.  */
+
+	.file "dwarf2-1.c"
+	.text
+	.globl _start
+_start:
+	.int 0
+.Lbegin_text1:
+	.globl func_cu1
+	.type func_cu1, %function
+func_cu1:
+.Lbegin_func_cu1:
+	.int 0
+.Lend_func_cu1:
+	.size func_cu1, .-func_cu1
+.Lend_text1:
+
+/* Debug information */
+
+	.section .debug_info
+.Lcu1_begin:
+	/* CU header */
+	.4byte	.Lcu1_end - .Lcu1_start		/* Length of Compilation Unit */
+.Lcu1_start:
+	.2byte	2				/* DWARF Version */
+	.4byte	.Labbrev1_begin			/* Offset into abbrev section */
+	.byte	4				/* Pointer size */
+
+	/* CU die */
+	.uleb128 1				/* Abbrev: DW_TAG_compile_unit */
+	.4byte	.Lline1_begin			/* DW_AT_stmt_list */
+	.4byte	.Lend_text1			/* DW_AT_high_pc */
+	.4byte	.Lbegin_text1			/* DW_AT_low_pc */
+	.ascii	"file1.txt\0"			/* DW_AT_name */
+	.ascii	"GNU C 3.3.3\0"			/* DW_AT_producer */
+	.byte	1				/* DW_AT_language (C) */
+
+	/* func_cu1 */
+	.uleb128	2			/* Abbrev: DW_TAG_subprogram */
+	.byte		1			/* DW_AT_external */
+	.byte		1			/* DW_AT_decl_file */
+	.byte		2			/* DW_AT_decl_line */
+	.ascii		"func_cu1\0"		/* DW_AT_name */
+	.4byte		.Ltype_int-.Lcu1_begin	/* DW_AT_type */
+	.4byte		.Lbegin_func_cu1	/* DW_AT_low_pc */
+	.4byte		.Lend_func_cu1		/* DW_AT_high_pc */
+	.byte		1			/* DW_AT_frame_base: length */
+	.byte		0x55			/* DW_AT_frame_base: DW_OP_reg5 */
+
+.Ltype_int:
+	.uleb128	3			/* Abbrev: DW_TAG_base_type */
+	.ascii		"int\0"			/* DW_AT_name */
+	.byte		4			/* DW_AT_byte_size */
+	.byte		5			/* DW_AT_encoding */
+
+	.byte		0			/* End of children of CU */
+
+.Lcu1_end:
+
+/* Line table */
+	.section .debug_line
+.Lline1_begin:
+	.4byte		.Lline1_end - .Lline1_start	/* Initial length */
+.Lline1_start:
+	.2byte		2			/* Version */
+	.4byte		.Lline1_lines - .Lline1_hdr	/* header_length */
+.Lline1_hdr:
+	.byte		1			/* Minimum insn length */
+	.byte		1			/* default_is_stmt */
+	.byte		1			/* line_base */
+ 	.byte		1			/* line_range */
+	.byte		0x10			/* opcode_base */
+
+	/* Standard lengths */
+	.byte		0
+	.byte		1
+	.byte		1
+	.byte		1
+	.byte		1
+	.byte		0
+	.byte		0
+	.byte		0
+	.byte		1
+	.byte		0
+	.byte		0
+	.byte		1
+	.byte		0
+	.byte		0
+	.byte		0
+
+	/* Include directories */
+	.byte		0
+
+	/* File names */
+	.ascii		"file1.txt\0"
+	.uleb128	0
+	.uleb128	0
+	.uleb128	0
+
+	.byte		0
+
+.Lline1_lines:
+	.byte		0	/* DW_LNE_set_address */
+	.uleb128	5
+	.byte		2
+	.4byte		.Lbegin_func_cu1
+
+	.byte		3	/* DW_LNS_advance_line */
+	.sleb128	3	/* ... to 4 */
+
+	.byte		1	/* DW_LNS_copy */
+
+	.byte		1	/* DW_LNS_copy (second time as an end-of-prologue marker) */
+
+	.byte		0	/* DW_LNE_set_address */
+	.uleb128	5
+	.byte		2
+	.4byte		.Lend_func_cu1
+
+	.byte		0	/* DW_LNE_end_of_sequence */
+	.uleb128	1
+	.byte		1
+
+.Lline1_end:
+
+/* Abbrev table -- compressed */
+	.section .zdebug_abbrev
+.Labbrev1_begin:
+	.ascii		"ZLIB"
+	.4byte		0
+	.2byte		0
+	.byte		0
+	.byte		51
+	.byte		0x78
+	.byte		0x5e
+	.byte		0x63
+	.byte		0x14
+	.byte		0x64
+	.byte		0x14
+	.byte		0x60
+	.byte		0x13
+	.byte		0x62
+	.byte		0x14
+	.byte		0x64
+	.byte		0x64
+	.byte		0xe6
+	.byte		0x50
+	.byte		0xe5
+	.byte		0x10
+	.byte		0xe6
+	.byte		0x66
+	.byte		0x60
+	.byte		0x60
+	.byte		0xd2
+	.byte		0x63
+	.byte		0xb0
+	.byte		0xe7
+	.byte		0xb1
+	.byte		0xe2
+	.byte		0xb6
+	.byte		0xe6
+	.byte		0x66
+	.byte		0xe6
+	.byte		0xf0
+	.byte		0x14
+	.byte		0x16
+	.byte		0x64
+	.byte		0x14
+	.byte		0x62
+	.byte		0x74
+	.byte		0xe0
+	.byte		0x02
+	.byte		0x00
+	.byte		0x25
+	.byte		0x78
+	.byte		0x02
+	.byte		0x81
+	.byte		0x78
+	.byte		0x9c
+	.byte		0x63
+	.byte		0x60
+	.byte		0x60
+	.byte		0x56
+	.byte		0x61
+	.byte		0x60
+	.byte		0xe6
+	.byte		0xe0
+	.byte		0xe6
+	.byte		0xb6
+	.byte		0xe3
+	.byte		0x66
+	.byte		0x00
+	.byte		0x02
+	.byte		0x00
+	.byte		0x04
+	.byte		0x9c
+	.byte		0x00
+	.byte		0x92
Index: binutils/gas/testsuite/gas/elf/dwarf2-2.s
===================================================================
--- binutils/gas/testsuite/gas/elf/dwarf2-2.s	(revision 0)
+++ binutils/gas/testsuite/gas/elf/dwarf2-2.s	(revision 0)
@@ -0,0 +1,219 @@
+/* This testcase is derived from a similar test in GDB.
+
+   Copyright 2009 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* This tests that gdb can read compressed sections.  The contents
+   are a basic assembly file, but the .debug_abbrev section has been
+   comrpessed using zlib.  */
+
+/* Dummy function to provide debug information for.  */
+
+	.file "dwarf2-2.c"
+	.section .gnu.linkonce.t.foo,"axG",%progbits,foo,comdat
+	.globl _start
+_start:
+	.int 0
+.Lbegin_text1:
+	.globl func_cu1
+	.type func_cu1, %function
+func_cu1:
+.Lbegin_func_cu1:
+	.int 0
+.Lend_func_cu1:
+	.size func_cu1, .-func_cu1
+.Lend_text1:
+
+/* Debug information */
+
+	.section .debug_info,"G",%progbits,foo,comdat
+.Lcu1_begin:
+	/* CU header */
+	.4byte	.Lcu1_end - .Lcu1_start		/* Length of Compilation Unit */
+.Lcu1_start:
+	.2byte	2				/* DWARF Version */
+	.4byte	.Labbrev1_begin			/* Offset into abbrev section */
+	.byte	4				/* Pointer size */
+
+	/* CU die */
+	.uleb128 1				/* Abbrev: DW_TAG_compile_unit */
+	.4byte	.Lline1_begin			/* DW_AT_stmt_list */
+	.4byte	.Lend_text1			/* DW_AT_high_pc */
+	.4byte	.Lbegin_text1			/* DW_AT_low_pc */
+	.ascii	"file1.txt\0"			/* DW_AT_name */
+	.ascii	"GNU C 3.3.3\0"			/* DW_AT_producer */
+	.byte	1				/* DW_AT_language (C) */
+
+	/* func_cu1 */
+	.uleb128	2			/* Abbrev: DW_TAG_subprogram */
+	.byte		1			/* DW_AT_external */
+	.byte		1			/* DW_AT_decl_file */
+	.byte		2			/* DW_AT_decl_line */
+	.ascii		"func_cu1\0"		/* DW_AT_name */
+	.4byte		.Ltype_int-.Lcu1_begin	/* DW_AT_type */
+	.4byte		.Lbegin_func_cu1	/* DW_AT_low_pc */
+	.4byte		.Lend_func_cu1		/* DW_AT_high_pc */
+	.byte		1			/* DW_AT_frame_base: length */
+	.byte		0x55			/* DW_AT_frame_base: DW_OP_reg5 */
+
+.Ltype_int:
+	.uleb128	3			/* Abbrev: DW_TAG_base_type */
+	.ascii		"int\0"			/* DW_AT_name */
+	.byte		4			/* DW_AT_byte_size */
+	.byte		5			/* DW_AT_encoding */
+
+	.byte		0			/* End of children of CU */
+
+.Lcu1_end:
+
+/* Line table */
+	.section .debug_line,"G",%progbits,foo,comdat
+.Lline1_begin:
+	.4byte		.Lline1_end - .Lline1_start	/* Initial length */
+.Lline1_start:
+	.2byte		2			/* Version */
+	.4byte		.Lline1_lines - .Lline1_hdr	/* header_length */
+.Lline1_hdr:
+	.byte		1			/* Minimum insn length */
+	.byte		1			/* default_is_stmt */
+	.byte		1			/* line_base */
+ 	.byte		1			/* line_range */
+	.byte		0x10			/* opcode_base */
+
+	/* Standard lengths */
+	.byte		0
+	.byte		1
+	.byte		1
+	.byte		1
+	.byte		1
+	.byte		0
+	.byte		0
+	.byte		0
+	.byte		1
+	.byte		0
+	.byte		0
+	.byte		1
+	.byte		0
+	.byte		0
+	.byte		0
+
+	/* Include directories */
+	.byte		0
+
+	/* File names */
+	.ascii		"file1.txt\0"
+	.uleb128	0
+	.uleb128	0
+	.uleb128	0
+
+	.byte		0
+
+.Lline1_lines:
+	.byte		0	/* DW_LNE_set_address */
+	.uleb128	5
+	.byte		2
+	.4byte		.Lbegin_func_cu1
+
+	.byte		3	/* DW_LNS_advance_line */
+	.sleb128	3	/* ... to 4 */
+
+	.byte		1	/* DW_LNS_copy */
+
+	.byte		1	/* DW_LNS_copy (second time as an end-of-prologue marker) */
+
+	.byte		0	/* DW_LNE_set_address */
+	.uleb128	5
+	.byte		2
+	.4byte		.Lend_func_cu1
+
+	.byte		0	/* DW_LNE_end_of_sequence */
+	.uleb128	1
+	.byte		1
+
+.Lline1_end:
+
+/* Abbrev table -- compressed */
+	.section .zdebug_abbrev,"G",%progbits,foo,comdat
+.Labbrev1_begin:
+	.ascii		"ZLIB"
+	.4byte		0
+	.2byte		0
+	.byte		0
+	.byte		51
+	.byte		0x78
+	.byte		0x5e
+	.byte		0x63
+	.byte		0x14
+	.byte		0x64
+	.byte		0x14
+	.byte		0x60
+	.byte		0x13
+	.byte		0x62
+	.byte		0x14
+	.byte		0x64
+	.byte		0x64
+	.byte		0xe6
+	.byte		0x50
+	.byte		0xe5
+	.byte		0x10
+	.byte		0xe6
+	.byte		0x66
+	.byte		0x60
+	.byte		0x60
+	.byte		0xd2
+	.byte		0x63
+	.byte		0xb0
+	.byte		0xe7
+	.byte		0xb1
+	.byte		0xe2
+	.byte		0xb6
+	.byte		0xe6
+	.byte		0x66
+	.byte		0xe6
+	.byte		0xf0
+	.byte		0x14
+	.byte		0x16
+	.byte		0x64
+	.byte		0x14
+	.byte		0x62
+	.byte		0x74
+	.byte		0xe0
+	.byte		0x02
+	.byte		0x00
+	.byte		0x25
+	.byte		0x78
+	.byte		0x02
+	.byte		0x81
+	.byte		0x78
+	.byte		0x9c
+	.byte		0x63
+	.byte		0x60
+	.byte		0x60
+	.byte		0x56
+	.byte		0x61
+	.byte		0x60
+	.byte		0xe6
+	.byte		0xe0
+	.byte		0xe6
+	.byte		0xb6
+	.byte		0xe3
+	.byte		0x66
+	.byte		0x00
+	.byte		0x02
+	.byte		0x00
+	.byte		0x04
+	.byte		0x9c
+	.byte		0x00
+	.byte		0x92
Index: binutils/gas/testsuite/gas/elf/dwarf2-3.s
===================================================================
--- binutils/gas/testsuite/gas/elf/dwarf2-3.s	(revision 0)
+++ binutils/gas/testsuite/gas/elf/dwarf2-3.s	(revision 0)
@@ -0,0 +1,186 @@
+	.file	"beginwarn.c"
+	.section	.debug_abbrev,"",@progbits
+.Ldebug_abbrev0:
+	.section	.debug_info,"",@progbits
+.Ldebug_info0:
+	.section	.debug_line,"",@progbits
+.Ldebug_line0:
+	.text
+.Ltext0:
+	.section	.init_array,"aw"
+	.align 4
+	.type	init_array, @object
+	.size	init_array, 4
+init_array:
+	.long	foo
+	.section	.gnu.warning.foo,"a",@progbits
+	.type	_evoke_link_warning_foo, @object
+	.size	_evoke_link_warning_foo, 27
+_evoke_link_warning_foo:
+	.string	"function foo is deprecated"
+	.file 1 "/beginwarn.c"
+	.text
+.Letext0:
+	.section	.debug_info
+	.long	0x8a
+	.value	0x2
+	.long	.Ldebug_abbrev0
+	.byte	0x4
+	.uleb128 0x1
+	.long	.Ldebug_line0
+	.long	.Letext0
+	.long	.Ltext0
+	.long	.LASF4
+	.byte	0x1
+	.long	.LASF5
+	.uleb128 0x2
+	.long	0x31
+	.long	0x38
+	.uleb128 0x3
+	.long	0x31
+	.byte	0x1a
+	.byte	0x0
+	.uleb128 0x4
+	.long	.LASF0
+	.byte	0x4
+	.byte	0x7
+	.uleb128 0x5
+	.long	0x3d
+	.uleb128 0x4
+	.long	.LASF1
+	.byte	0x1
+	.byte	0x6
+	.uleb128 0x6
+	.long	.LASF2
+	.byte	0x1
+	.byte	0x3
+	.long	0x55
+	.byte	0x5
+	.byte	0x3
+	.long	_evoke_link_warning_foo
+	.uleb128 0x5
+	.long	0x21
+	.uleb128 0x2
+	.long	0x6a
+	.long	0x6c
+	.uleb128 0x3
+	.long	0x31
+	.byte	0x0
+	.byte	0x0
+	.uleb128 0x7
+	.byte	0x1
+	.uleb128 0x5
+	.long	0x71
+	.uleb128 0x8
+	.byte	0x4
+	.long	0x6a
+	.uleb128 0x6
+	.long	.LASF3
+	.byte	0x1
+	.byte	0x9
+	.long	0x88
+	.byte	0x5
+	.byte	0x3
+	.long	init_array
+	.uleb128 0x5
+	.long	0x5a
+	.byte	0x0
+	.section	.debug_abbrev
+	.uleb128 0x1
+	.uleb128 0x11
+	.byte	0x1
+	.uleb128 0x10
+	.uleb128 0x6
+	.uleb128 0x12
+	.uleb128 0x1
+	.uleb128 0x11
+	.uleb128 0x1
+	.uleb128 0x25
+	.uleb128 0xe
+	.uleb128 0x13
+	.uleb128 0xb
+	.uleb128 0x3
+	.uleb128 0xe
+	.byte	0x0
+	.byte	0x0
+	.uleb128 0x2
+	.uleb128 0x1
+	.byte	0x1
+	.uleb128 0x1
+	.uleb128 0x13
+	.uleb128 0x49
+	.uleb128 0x13
+	.byte	0x0
+	.byte	0x0
+	.uleb128 0x3
+	.uleb128 0x21
+	.byte	0x0
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x2f
+	.uleb128 0xb
+	.byte	0x0
+	.byte	0x0
+	.uleb128 0x4
+	.uleb128 0x24
+	.byte	0x0
+	.uleb128 0x3
+	.uleb128 0xe
+	.uleb128 0xb
+	.uleb128 0xb
+	.uleb128 0x3e
+	.uleb128 0xb
+	.byte	0x0
+	.byte	0x0
+	.uleb128 0x5
+	.uleb128 0x26
+	.byte	0x0
+	.uleb128 0x49
+	.uleb128 0x13
+	.byte	0x0
+	.byte	0x0
+	.uleb128 0x6
+	.uleb128 0x34
+	.byte	0x0
+	.uleb128 0x3
+	.uleb128 0xe
+	.uleb128 0x3a
+	.uleb128 0xb
+	.uleb128 0x3b
+	.uleb128 0xb
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x2
+	.uleb128 0xa
+	.byte	0x0
+	.byte	0x0
+	.uleb128 0x7
+	.uleb128 0x15
+	.byte	0x0
+	.uleb128 0x27
+	.uleb128 0xc
+	.byte	0x0
+	.byte	0x0
+	.uleb128 0x8
+	.uleb128 0xf
+	.byte	0x0
+	.uleb128 0xb
+	.uleb128 0xb
+	.uleb128 0x49
+	.uleb128 0x13
+	.byte	0x0
+	.byte	0x0
+	.byte	0x0
+	.section	.debug_str,"MS",@progbits,1
+.LASF5:
+	.string	"/beginwarn.c"
+.LASF0:
+	.string	"unsigned int"
+.LASF3:
+	.string	"init_array"
+.LASF2:
+	.string	"_evoke_link_warning_foo"
+.LASF4:
+	.string	"GNU C 3.4.6"
+.LASF1:
+	.string	"char"
Index: binutils/gas/testsuite/gas/elf/elf.exp
===================================================================
--- binutils/gas/testsuite/gas/elf/elf.exp	(revision 6552)
+++ binutils/gas/testsuite/gas/elf/elf.exp	(working copy)
@@ -145,4 +145,7 @@ if { ([istarget "*-*-*elf*"]		
 
     run_dump_test "section6" 
     run_dump_test "section7" 
+    run_dump_test "dwarf2-1" 
+    run_dump_test "dwarf2-2" 
+    run_dump_test "dwarf2-3" 
 }
Index: binutils/gas/testsuite/gas/elf/dwarf2-1.d
===================================================================
--- binutils/gas/testsuite/gas/elf/dwarf2-1.d	(revision 0)
+++ binutils/gas/testsuite/gas/elf/dwarf2-1.d	(revision 0)
@@ -0,0 +1,100 @@
+#readelf: -w
+#name: DWARF2 1
+#not-target: ia64-*-*
+
+Contents of the .debug_info section:
+
+  Compilation Unit @ offset 0x0:
+   Length:        0x4e \(32-bit\)
+   Version:       2
+   Abbrev Offset: 0
+   Pointer Size:  4
+ <0><b>: Abbrev Number: 1 \(DW_TAG_compile_unit\)
+    < c>   DW_AT_stmt_list   : 0x0	
+    <10>   DW_AT_high_pc     : 0x.	
+    <14>   DW_AT_low_pc      : 0x.	
+    <18>   DW_AT_name        : file1.txt	
+    <22>   DW_AT_producer    : GNU C 3.3.3	
+    <2e>   DW_AT_language    : 1	\(ANSI C\)
+ <1><2f>: Abbrev Number: 2 \(DW_TAG_subprogram\)
+    <30>   DW_AT_external    : 1	
+    <31>   DW_AT_decl_file   : 1	
+    <32>   DW_AT_decl_line   : 2	
+    <33>   DW_AT_name        : func_cu1	
+    <3c>   DW_AT_type        : <0x4a>	
+    <40>   DW_AT_low_pc      : 0x.	
+    <44>   DW_AT_high_pc     : 0x.	
+    <48>   DW_AT_frame_base  : 1 byte block: 55 	\(DW_OP_reg5\)
+ <1><4a>: Abbrev Number: 3 \(DW_TAG_base_type\)
+    <4b>   DW_AT_name        : int	
+    <4f>   DW_AT_byte_size   : 4	
+    <50>   DW_AT_encoding    : 5	\(signed\)
+
+Raw dump of debug contents of section .debug_line:
+
+  Offset:                      0x0
+  Length:                      62
+  DWARF Version:               2
+  Prologue Length:             35
+  Minimum Instruction Length:  1
+  Initial value of 'is_stmt':  1
+  Line Base:                   1
+  Line Range:                  1
+  Opcode Base:                 16
+
+ Opcodes:
+  Opcode 1 has 0 args
+  Opcode 2 has 1 args
+  Opcode 3 has 1 args
+  Opcode 4 has 1 args
+  Opcode 5 has 1 args
+  Opcode 6 has 0 args
+  Opcode 7 has 0 args
+  Opcode 8 has 0 args
+  Opcode 9 has 1 args
+  Opcode 10 has 0 args
+  Opcode 11 has 0 args
+  Opcode 12 has 1 args
+  Opcode 13 has 0 args
+  Opcode 14 has 0 args
+  Opcode 15 has 0 args
+
+ The Directory Table is empty.
+
+ The File Name Table:
+  Entry	Dir	Time	Size	Name
+  1	0	0	0	file1.txt
+
+ Line Number Statements:
+  Extended opcode 2: set Address to .*
+  Advance Line by 3 to 4
+  Copy
+  Copy
+  Extended opcode 2: set Address to .*
+  Extended opcode 1: End of Sequence
+
+
+Contents of the .zdebug_abbrev section:
+
+  Number TAG
+   1      DW_TAG_compile_unit    \[has children\]
+    DW_AT_stmt_list    DW_FORM_data4
+    DW_AT_high_pc      DW_FORM_addr
+    DW_AT_low_pc       DW_FORM_addr
+    DW_AT_name         DW_FORM_string
+    DW_AT_producer     DW_FORM_string
+    DW_AT_language     DW_FORM_data1
+   2      DW_TAG_subprogram    \[no children\]
+    DW_AT_external     DW_FORM_flag
+    DW_AT_decl_file    DW_FORM_data1
+    DW_AT_decl_line    DW_FORM_data1
+    DW_AT_name         DW_FORM_string
+    DW_AT_type         DW_FORM_ref4
+    DW_AT_low_pc       DW_FORM_addr
+    DW_AT_high_pc      DW_FORM_addr
+    DW_AT_frame_base   DW_FORM_block1
+   3      DW_TAG_base_type    \[no children\]
+    DW_AT_name         DW_FORM_string
+    DW_AT_byte_size    DW_FORM_data1
+    DW_AT_encoding     DW_FORM_data1
+
Index: binutils/gas/testsuite/gas/elf/dwarf2-2.d
===================================================================
--- binutils/gas/testsuite/gas/elf/dwarf2-2.d	(revision 0)
+++ binutils/gas/testsuite/gas/elf/dwarf2-2.d	(revision 0)
@@ -0,0 +1,100 @@
+#readelf: -w
+#name: DWARF2 2
+#not-target: ia64-*-*
+
+Contents of the .debug_info section:
+
+  Compilation Unit @ offset 0x0:
+   Length:        0x4e \(32-bit\)
+   Version:       2
+   Abbrev Offset: 0
+   Pointer Size:  4
+ <0><b>: Abbrev Number: 1 \(DW_TAG_compile_unit\)
+    < c>   DW_AT_stmt_list   : 0x0	
+    <10>   DW_AT_high_pc     : 0x.	
+    <14>   DW_AT_low_pc      : 0x.	
+    <18>   DW_AT_name        : file1.txt	
+    <22>   DW_AT_producer    : GNU C 3.3.3	
+    <2e>   DW_AT_language    : 1	\(ANSI C\)
+ <1><2f>: Abbrev Number: 2 \(DW_TAG_subprogram\)
+    <30>   DW_AT_external    : 1	
+    <31>   DW_AT_decl_file   : 1	
+    <32>   DW_AT_decl_line   : 2	
+    <33>   DW_AT_name        : func_cu1	
+    <3c>   DW_AT_type        : <0x4a>	
+    <40>   DW_AT_low_pc      : 0x.	
+    <44>   DW_AT_high_pc     : 0x.	
+    <48>   DW_AT_frame_base  : 1 byte block: 55 	\(DW_OP_reg5\)
+ <1><4a>: Abbrev Number: 3 \(DW_TAG_base_type\)
+    <4b>   DW_AT_name        : int	
+    <4f>   DW_AT_byte_size   : 4	
+    <50>   DW_AT_encoding    : 5	\(signed\)
+
+Raw dump of debug contents of section .debug_line:
+
+  Offset:                      0x0
+  Length:                      62
+  DWARF Version:               2
+  Prologue Length:             35
+  Minimum Instruction Length:  1
+  Initial value of 'is_stmt':  1
+  Line Base:                   1
+  Line Range:                  1
+  Opcode Base:                 16
+
+ Opcodes:
+  Opcode 1 has 0 args
+  Opcode 2 has 1 args
+  Opcode 3 has 1 args
+  Opcode 4 has 1 args
+  Opcode 5 has 1 args
+  Opcode 6 has 0 args
+  Opcode 7 has 0 args
+  Opcode 8 has 0 args
+  Opcode 9 has 1 args
+  Opcode 10 has 0 args
+  Opcode 11 has 0 args
+  Opcode 12 has 1 args
+  Opcode 13 has 0 args
+  Opcode 14 has 0 args
+  Opcode 15 has 0 args
+
+ The Directory Table is empty.
+
+ The File Name Table:
+  Entry	Dir	Time	Size	Name
+  1	0	0	0	file1.txt
+
+ Line Number Statements:
+  Extended opcode 2: set Address to .*
+  Advance Line by 3 to 4
+  Copy
+  Copy
+  Extended opcode 2: set Address to .*
+  Extended opcode 1: End of Sequence
+
+
+Contents of the .zdebug_abbrev section:
+
+  Number TAG
+   1      DW_TAG_compile_unit    \[has children\]
+    DW_AT_stmt_list    DW_FORM_data4
+    DW_AT_high_pc      DW_FORM_addr
+    DW_AT_low_pc       DW_FORM_addr
+    DW_AT_name         DW_FORM_string
+    DW_AT_producer     DW_FORM_string
+    DW_AT_language     DW_FORM_data1
+   2      DW_TAG_subprogram    \[no children\]
+    DW_AT_external     DW_FORM_flag
+    DW_AT_decl_file    DW_FORM_data1
+    DW_AT_decl_line    DW_FORM_data1
+    DW_AT_name         DW_FORM_string
+    DW_AT_type         DW_FORM_ref4
+    DW_AT_low_pc       DW_FORM_addr
+    DW_AT_high_pc      DW_FORM_addr
+    DW_AT_frame_base   DW_FORM_block1
+   3      DW_TAG_base_type    \[no children\]
+    DW_AT_name         DW_FORM_string
+    DW_AT_byte_size    DW_FORM_data1
+    DW_AT_encoding     DW_FORM_data1
+
Index: binutils/gas/testsuite/gas/elf/dwarf2-3.d
===================================================================
--- binutils/gas/testsuite/gas/elf/dwarf2-3.d	(revision 0)
+++ binutils/gas/testsuite/gas/elf/dwarf2-3.d	(revision 0)
@@ -0,0 +1,38 @@
+#readelf: -wl
+#name: DWARF2 3
+#not-target: ia64-*-*
+
+Raw dump of debug contents of section .debug_line:
+
+  Offset:                      0x0
+  Length:                      41
+  DWARF Version:               2
+  Prologue Length:             35
+  Minimum Instruction Length:  1
+  Initial value of 'is_stmt':  1
+  Line Base:                   -5
+  Line Range:                  14
+  Opcode Base:                 13
+
+ Opcodes:
+  Opcode 1 has 0 args
+  Opcode 2 has 1 args
+  Opcode 3 has 1 args
+  Opcode 4 has 1 args
+  Opcode 5 has 1 args
+  Opcode 6 has 0 args
+  Opcode 7 has 0 args
+  Opcode 8 has 0 args
+  Opcode 9 has 1 args
+  Opcode 10 has 0 args
+  Opcode 11 has 0 args
+  Opcode 12 has 1 args
+
+ The Directory Table is empty.
+
+ The File Name Table:
+  Entry	Dir	Time	Size	Name
+  1	0	0	0	/beginwarn.c
+
+ Line Number Statements:
+
Index: binutils/gas/as.c
===================================================================
--- binutils/gas/as.c	(revision 6552)
+++ binutils/gas/as.c	(working copy)
@@ -72,6 +72,9 @@ struct defsym_list
 /* True if a listing is wanted.  */
 int listing;
 
+/* If assembler shiuld debug info.  */
+enum debug_info_type gen_debug = DEBUG_UNSPECIFIED;
+
 /* Type of debugging to generate.  */
 enum debug_info_type debug_type = DEBUG_UNSPECIFIED;
 int use_gnu_debug_info_extensions = 0;
@@ -908,6 +911,8 @@ This program has absolutely no warranty.
 	}
     }
 
+  gen_debug = debug_type;
+
   free (shortopts);
   free (longopts);
 
Index: binutils/gas/as.h
===================================================================
--- binutils/gas/as.h	(revision 6552)
+++ binutils/gas/as.h	(working copy)
@@ -429,6 +429,7 @@ enum debug_info_type
   DEBUG_DWARF2
 };
 
+extern enum debug_info_type gen_debug;
 extern enum debug_info_type debug_type;
 extern int use_gnu_debug_info_extensions;
 \f
Index: binutils/gas/subsegs.c
===================================================================
--- binutils/gas/subsegs.c	(revision 6552)
+++ binutils/gas/subsegs.c	(working copy)
@@ -148,15 +148,6 @@ subseg_get (const char *segname, int for
 {
   segT secptr;
   segment_info_type *seginfo;
-  const char *now_seg_name = (now_seg
-			      ? bfd_get_section_name (stdoutput, now_seg)
-			      : 0);
-
-  if (!force_new
-      && now_seg_name
-      && (now_seg_name == segname
-	  || !strcmp (now_seg_name, segname)))
-    return now_seg;
 
   if (!force_new)
     secptr = bfd_make_section_old_way (stdoutput, segname);
Index: binutils/binutils/testsuite/binutils-all/objdump.W
===================================================================
--- binutils/binutils/testsuite/binutils-all/objdump.W	(revision 6552)
+++ binutils/binutils/testsuite/binutils-all/objdump.W	(working copy)
@@ -73,36 +73,6 @@ Raw dump of debug contents of section .d
   Extended opcode 1: End of Sequence
 
 
-  Offset:                      0x42
-  Length:                      25
-  DWARF Version:               2
-  Prologue Length:             19
-  Minimum Instruction Length:  [1248]
-  Initial value of 'is_stmt':  1
-  Line Base:                   -5
-  Line Range:                  14
-  Opcode Base:                 13
-
- Opcodes:
-  Opcode 1 has 0 args
-  Opcode 2 has 1 args
-  Opcode 3 has 1 args
-  Opcode 4 has 1 args
-  Opcode 5 has 1 args
-  Opcode 6 has 0 args
-  Opcode 7 has 0 args
-  Opcode 8 has 0 args
-  Opcode 9 has 1 args
-  Opcode 10 has 0 args
-  Opcode 11 has 0 args
-  Opcode 12 has 1 args
-
- The Directory Table is empty.
-
- The File Name Table is empty.
-
- Line Number Statements:
-
 Contents of the .zdebug_abbrev section:
 
   Number TAG
Index: binutils/bfd/section.c
===================================================================
--- binutils/bfd/section.c	(revision 6552)
+++ binutils/bfd/section.c	(working copy)
@@ -138,6 +138,7 @@ SUBSECTION
 #include "bfd.h"
 #include "libbfd.h"
 #include "bfdlink.h"
+#include "elf-bfd.h"
 
 /*
 DOCDD
@@ -854,11 +855,31 @@ asection *
 bfd_get_section_by_name (bfd *abfd, const char *name)
 {
   struct section_hash_entry *sh;
+  unsigned long hash;
+  asection *sec;
 
   sh = section_hash_lookup (&abfd->section_htab, name, FALSE, FALSE);
-  if (sh != NULL)
+  if (sh == NULL)
+    return NULL;
+
+  /* Only ELF has section group. */
+  if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
     return &sh->section;
 
+  hash = sh->root.hash;
+  do
+    {
+      sec = &sh->section;
+      /* Don't return a section in a section group.  */
+      if (elf_section_data (sec) == NULL
+	  || elf_group_name (sec) == NULL)
+	return sec;
+      sh = (struct section_hash_entry *) sh->root.next;
+    }
+  while (sh != NULL
+	 && sh->root.hash == hash
+	 && strcmp (sh->root.string, name) == 0);
+
   return NULL;
 }
 
@@ -1011,7 +1032,43 @@ bfd_make_section_old_way (bfd *abfd, con
       if (sh == NULL)
 	return NULL;
 
-      newsect = &sh->section;
+      /* Only ELF has section group. */
+      if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+	{
+	  struct section_hash_entry *old_sh = sh;
+	  unsigned long hash = sh->root.hash;
+
+	  do
+	    {
+	      newsect = &sh->section;
+	      /* Don't use a section in a section group.  */
+	      if (elf_section_data (newsect) == NULL
+		  || elf_group_name (newsect) == NULL)
+		break;
+	      sh = (struct section_hash_entry *) sh->root.next;
+	    }
+	  while (sh != NULL
+		 && sh->root.hash == hash
+		 && strcmp (sh->root.string, name) == 0);
+
+	  if (sh == NULL)
+	    {
+	      /* Allocate a new one since existing sections are in
+		 section groups.  */
+	      struct section_hash_entry *new_sh;
+	      new_sh = (struct section_hash_entry *)
+		bfd_section_hash_newfunc (NULL, &abfd->section_htab, name);
+	      if (new_sh == NULL)
+		return NULL;
+
+	      new_sh->root = old_sh->root;
+	      old_sh->root.next = &new_sh->root;
+	      newsect = &new_sh->section;
+	    }
+	}
+      else
+	newsect = &sh->section;
+
       if (newsect->name != NULL)
 	{
 	  /* Section already exists.  */

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: PATCH: PR gas/10531: Strange assembler warning message on section    group
  2009-08-23  7:28                 ` H.J. Lu
@ 2009-10-26 22:11                   ` Jim Wilson
  2009-10-27 17:32                     ` H.J. Lu
  0 siblings, 1 reply; 20+ messages in thread
From: Jim Wilson @ 2009-10-26 22:11 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

On 08/22/2009 04:53 PM, H.J. Lu wrote:
> This patch hadles ".file" directives properly with a new testcase from gcc 3.4.
> OK to install?

Now that I have time to properly review this...

The stuff for excluding group sections from simple section name string 
searches looks mostly OK.

I see that bfd_make_section_old_way contains the entire contents of the 
function bfd_get_section_by_name.  This was OK when the latter was a 
5-line function, but now that it is a 20-line function, maybe it is 
better to have bfd_make_section_old_way call bfd_get_section_by_name 
instead of duplicating all 20 lines?  Except that would require some 
interface changes, because bfd_get_section_by_name can return NULL for 
two different things, one which bfd_make_section_old_way ignores, and 
one which needs special handling.  So it is a little harder, but it 
still seems potentially worthwhile.  Maybe part of this can be split out 
to its own function or macro?

I see that you only fixed those two functions, but you left similar 
functions like bfd_make_section and bfd_make_section_with_flags unfixed. 
  Maybe because these aren't called from gas/dwarf2dbg.c?  Shouldn't we 
be fixing all of the functions?  If we do need to fix more functions, 
then that means more copies of the same 20-lines of code, which makes it 
more important to avoid duplication of this code.

I think the stuff for deciding whether to emit a debug_line section has 
more problems.

There are some minor issues.  For instance in as.c you added a comment
> /* If assembler shiuld debug info.  */
which needs to be fixed.  Need to change "shiuld" to "should generate".

You changed the behaviour of the dwarf2_finish function, but you didn't 
update the comment before the function start which is now wrong with 
your patch.

You added two variables gen_debug and dwarf2_directive_used, and a test 
for them
> +  if (!dwarf2_directive_used && gen_debug == DEBUG_UNSPECIFIED)
But this test seems to be equivalent to "if (!all_segs)" so there is no 
need for these two new variables.

The bigger problem here is that with your patch dwarf2_finish now does
   if (!all_segs) return;
   ...
   if (!all_segs && emit_other_sections) return;
which doesn't make a lot of sense.  The current code handles the case 
where the compiler emits a debug_info section, but does not emit any 
.file or .loc directives.  .loc will only be emitted if there is code. 
It will not be emitted for an input file that contains only variables. 
GCC will always emit .file if the assembler supports it, but it is 
possible that it might be missing if someone configured gcc wrong.  It 
isn't obvious whether we need to handle this case, it is probably safer 
if we do.

This is why my suggested solution takes a slightly different tack here. 
  Instead of checking for -g or .file/.loc, I check for a non-empty 
debug_line section.  If there is one, then it should be safe to assume 
that the compiler emitted a correct debug_line section, and the 
assembler should not emit one.  My suggested patch can be found here
   http://sourceware.org/ml/binutils/2009-08/msg00358.html

Jim

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: PATCH: PR gas/10531: Strange assembler warning message on section   group
  2009-10-26 22:11                   ` Jim Wilson
@ 2009-10-27 17:32                     ` H.J. Lu
  0 siblings, 0 replies; 20+ messages in thread
From: H.J. Lu @ 2009-10-27 17:32 UTC (permalink / raw)
  To: Jim Wilson; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 4095 bytes --]

On Mon, Oct 26, 2009 at 3:11 PM, Jim Wilson <wilson@codesourcery.com> wrote:
> On 08/22/2009 04:53 PM, H.J. Lu wrote:
>>
>> This patch hadles ".file" directives properly with a new testcase from gcc
>> 3.4.
>> OK to install?
>
> Now that I have time to properly review this...
>
> The stuff for excluding group sections from simple section name string
> searches looks mostly OK.
>
> I see that bfd_make_section_old_way contains the entire contents of the
> function bfd_get_section_by_name.  This was OK when the latter was a 5-line
> function, but now that it is a 20-line function, maybe it is better to have
> bfd_make_section_old_way call bfd_get_section_by_name instead of duplicating
> all 20 lines?  Except that would require some interface changes, because
> bfd_get_section_by_name can return NULL for two different things, one which
> bfd_make_section_old_way ignores, and one which needs special handling.  So
> it is a little harder, but it still seems potentially worthwhile.  Maybe
> part of this can be split out to its own function or macro?
>
> I see that you only fixed those two functions, but you left similar
> functions like bfd_make_section and bfd_make_section_with_flags unfixed.
>  Maybe because these aren't called from gas/dwarf2dbg.c?  Shouldn't we be
> fixing all of the functions?  If we do need to fix more functions, then that
> means more copies of the same 20-lines of code, which makes it more
> important to avoid duplication of this code.
>
> I think the stuff for deciding whether to emit a debug_line section has more
> problems.
>
> There are some minor issues.  For instance in as.c you added a comment
>>
>> /* If assembler shiuld debug info.  */
>
> which needs to be fixed.  Need to change "shiuld" to "should generate".
>
> You changed the behaviour of the dwarf2_finish function, but you didn't
> update the comment before the function start which is now wrong with your
> patch.
>
> You added two variables gen_debug and dwarf2_directive_used, and a test for
> them
>>
>> +  if (!dwarf2_directive_used && gen_debug == DEBUG_UNSPECIFIED)
>
> But this test seems to be equivalent to "if (!all_segs)" so there is no need
> for these two new variables.
>
> The bigger problem here is that with your patch dwarf2_finish now does
>  if (!all_segs) return;
>  ...
>  if (!all_segs && emit_other_sections) return;
> which doesn't make a lot of sense.  The current code handles the case where
> the compiler emits a debug_info section, but does not emit any .file or .loc
> directives.  .loc will only be emitted if there is code. It will not be
> emitted for an input file that contains only variables. GCC will always emit
> .file if the assembler supports it, but it is possible that it might be
> missing if someone configured gcc wrong.  It isn't obvious whether we need
> to handle this case, it is probably safer if we do.
>
> This is why my suggested solution takes a slightly different tack here.
>  Instead of checking for -g or .file/.loc, I check for a non-empty
> debug_line section.  If there is one, then it should be safe to assume that
> the compiler emitted a correct debug_line section, and the assembler should
> not emit one.  My suggested patch can be found here
>  http://sourceware.org/ml/binutils/2009-08/msg00358.html
>

Here is the updated patch. OK to install?

Thanks.

-- 
H.J.
---
binutils/testsuite/

2009-10-27  H.J. Lu  <hongjiu.lu@intel.com>

	PR gas/10531
	* binutils-all/objdump.W: Remove bogus line debug info.

gas/

2009-10-27  Jim Wilson  <wilson@codesourcery.com>

	PR gas/10531
	* dwarf2dbg.c (dwarf2_finish): Don't generate .debug_line section
	if it isn't empty.

gas/testsuite/

2009-10-27  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * gas/elf/dwarf2-1.d: New.
	 * gas/elf/dwarf2-1.s: Likewise.
	 * gas/elf/dwarf2-2.d: Likewise.
	 * gas/elf/dwarf2-2.s: Likewise.
	 * gas/elf/dwarf2-3.d: Likewise.
	 * gas/elf/dwarf2-3.s: Likewise.
	 * gas/i386/debug1.d: Likewise.
	 * gas/i386/debug1.s: Likewise.

[-- Attachment #2: binutils-group-10.patch --]
[-- Type: text/plain, Size: 27213 bytes --]

binutils/testsuite/

2009-10-27  H.J. Lu  <hongjiu.lu@intel.com>

	PR gas/10531
	* binutils-all/objdump.W: Remove bogus line debug info.

gas/

2009-10-27  Jim Wilson  <wilson@codesourcery.com>

	PR gas/10531
	* dwarf2dbg.c (dwarf2_finish): Don't generate .debug_line section
	if it isn't empty.

gas/testsuite/

2009-10-27  H.J. Lu  <hongjiu.lu@intel.com>

	 PR gas/10531
	 * gas/elf/dwarf2-1.d: New.
	 * gas/elf/dwarf2-1.s: Likewise.
	 * gas/elf/dwarf2-2.d: Likewise.
	 * gas/elf/dwarf2-2.s: Likewise.
	 * gas/elf/dwarf2-3.d: Likewise.
	 * gas/elf/dwarf2-3.s: Likewise.
	 * gas/i386/debug1.d: Likewise.
	 * gas/i386/debug1.s: Likewise.

diff --git a/binutils/testsuite/binutils-all/objdump.W b/binutils/testsuite/binutils-all/objdump.W
index aa1bd2c..5f65063 100644
--- a/binutils/testsuite/binutils-all/objdump.W
+++ b/binutils/testsuite/binutils-all/objdump.W
@@ -73,36 +73,6 @@ Raw dump of debug contents of section .debug_line:
   Extended opcode 1: End of Sequence
 
 
-  Offset:                      0x42
-  Length:                      25
-  DWARF Version:               2
-  Prologue Length:             19
-  Minimum Instruction Length:  [1248]
-  Initial value of 'is_stmt':  1
-  Line Base:                   -5
-  Line Range:                  14
-  Opcode Base:                 13
-
- Opcodes:
-  Opcode 1 has 0 args
-  Opcode 2 has 1 args
-  Opcode 3 has 1 args
-  Opcode 4 has 1 args
-  Opcode 5 has 1 args
-  Opcode 6 has 0 args
-  Opcode 7 has 0 args
-  Opcode 8 has 0 args
-  Opcode 9 has 1 args
-  Opcode 10 has 0 args
-  Opcode 11 has 0 args
-  Opcode 12 has 1 args
-
- The Directory Table is empty.
-
- The File Name Table is empty.
-
- Line Number Statements:
-
 Contents of the .zdebug_abbrev section:
 
   Number TAG
diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index 42d7267..ba479ee 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -1718,11 +1718,12 @@ dwarf2_init (void)
 
 /* Finish the dwarf2 debug sections.  We emit .debug.line if there
    were any .file/.loc directives, or --gdwarf2 was given, or if the
-   file has a non-empty .debug_info section.  If we emit .debug_line,
-   and the .debug_info section is empty, we also emit .debug_info,
-   .debug_aranges and .debug_abbrev.  ALL_SEGS will be non-null if
-   there were any .file/.loc directives, or --gdwarf2 was given and
-   there were any located instructions emitted.  */
+   file has a non-empty .debug_info section and an empty .debug_line
+   section.  If we emit .debug_line, and the .debug_info section is
+   empty, we also emit .debug_info, .debug_aranges and .debug_abbrev.
+   ALL_SEGS will be non-null if there were any .file/.loc directives,
+   or --gdwarf2 was given and there were any located instructions
+   emitted.  */
 
 void
 dwarf2_finish (void)
@@ -1731,13 +1732,24 @@ dwarf2_finish (void)
   struct line_seg *s;
   segT info_seg;
   int emit_other_sections = 0;
+  int empty_debug_line = 0;
 
   info_seg = bfd_get_section_by_name (stdoutput, ".debug_info");
   emit_other_sections = info_seg == NULL || !seg_not_empty_p (info_seg);
 
-  if (!all_segs && emit_other_sections)
-    /* There is no line information and no non-empty .debug_info
-       section.  */
+  line_seg = bfd_get_section_by_name (stdoutput, ".debug_line");
+  empty_debug_line = line_seg == NULL || !seg_not_empty_p (line_seg);
+
+  /* We can't construct a new debug_line section if we already have one.
+     Give an error.  */
+  if (all_segs && !empty_debug_line)
+    as_fatal ("duplicate .debug_line sections");
+
+  if ((!all_segs && emit_other_sections)
+      || (!emit_other_sections && !empty_debug_line))
+    /* If there is no line information and no non-empty .debug_info
+       section, or if there is both a non-empty .debug_info and a non-empty
+       .debug_line, then we do nothing.  */
     return;
 
   /* Calculate the size of an address for the target machine.  */
diff --git a/gas/testsuite/gas/elf/dwarf2-1.d b/gas/testsuite/gas/elf/dwarf2-1.d
new file mode 100644
index 0000000..f09d230
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-1.d
@@ -0,0 +1,100 @@
+#readelf: -w
+#name: DWARF2 1
+#not-target: ia64-*-*
+
+Contents of the .debug_info section:
+
+  Compilation Unit @ offset 0x0:
+   Length:        0x4e \(32-bit\)
+   Version:       2
+   Abbrev Offset: 0
+   Pointer Size:  4
+ <0><b>: Abbrev Number: 1 \(DW_TAG_compile_unit\)
+    < c>   DW_AT_stmt_list   : 0x0	
+    <10>   DW_AT_high_pc     : 0x.	
+    <14>   DW_AT_low_pc      : 0x.	
+    <18>   DW_AT_name        : file1.txt	
+    <22>   DW_AT_producer    : GNU C 3.3.3	
+    <2e>   DW_AT_language    : 1	\(ANSI C\)
+ <1><2f>: Abbrev Number: 2 \(DW_TAG_subprogram\)
+    <30>   DW_AT_external    : 1	
+    <31>   DW_AT_decl_file   : 1	
+    <32>   DW_AT_decl_line   : 2	
+    <33>   DW_AT_name        : func_cu1	
+    <3c>   DW_AT_type        : <0x4a>	
+    <40>   DW_AT_low_pc      : 0x.	
+    <44>   DW_AT_high_pc     : 0x.	
+    <48>   DW_AT_frame_base  : 1 byte block: 55 	\(DW_OP_reg5\)
+ <1><4a>: Abbrev Number: 3 \(DW_TAG_base_type\)
+    <4b>   DW_AT_name        : int	
+    <4f>   DW_AT_byte_size   : 4	
+    <50>   DW_AT_encoding    : 5	\(signed\)
+
+Raw dump of debug contents of section .debug_line:
+
+  Offset:                      0x0
+  Length:                      62
+  DWARF Version:               2
+  Prologue Length:             35
+  Minimum Instruction Length:  1
+  Initial value of 'is_stmt':  1
+  Line Base:                   1
+  Line Range:                  1
+  Opcode Base:                 16
+
+ Opcodes:
+  Opcode 1 has 0 args
+  Opcode 2 has 1 args
+  Opcode 3 has 1 args
+  Opcode 4 has 1 args
+  Opcode 5 has 1 args
+  Opcode 6 has 0 args
+  Opcode 7 has 0 args
+  Opcode 8 has 0 args
+  Opcode 9 has 1 args
+  Opcode 10 has 0 args
+  Opcode 11 has 0 args
+  Opcode 12 has 1 args
+  Opcode 13 has 0 args
+  Opcode 14 has 0 args
+  Opcode 15 has 0 args
+
+ The Directory Table is empty.
+
+ The File Name Table:
+  Entry	Dir	Time	Size	Name
+  1	0	0	0	file1.txt
+
+ Line Number Statements:
+  Extended opcode 2: set Address to .*
+  Advance Line by 3 to 4
+  Copy
+  Copy
+  Extended opcode 2: set Address to .*
+  Extended opcode 1: End of Sequence
+
+
+Contents of the .zdebug_abbrev section:
+
+  Number TAG
+   1      DW_TAG_compile_unit    \[has children\]
+    DW_AT_stmt_list    DW_FORM_data4
+    DW_AT_high_pc      DW_FORM_addr
+    DW_AT_low_pc       DW_FORM_addr
+    DW_AT_name         DW_FORM_string
+    DW_AT_producer     DW_FORM_string
+    DW_AT_language     DW_FORM_data1
+   2      DW_TAG_subprogram    \[no children\]
+    DW_AT_external     DW_FORM_flag
+    DW_AT_decl_file    DW_FORM_data1
+    DW_AT_decl_line    DW_FORM_data1
+    DW_AT_name         DW_FORM_string
+    DW_AT_type         DW_FORM_ref4
+    DW_AT_low_pc       DW_FORM_addr
+    DW_AT_high_pc      DW_FORM_addr
+    DW_AT_frame_base   DW_FORM_block1
+   3      DW_TAG_base_type    \[no children\]
+    DW_AT_name         DW_FORM_string
+    DW_AT_byte_size    DW_FORM_data1
+    DW_AT_encoding     DW_FORM_data1
+
diff --git a/gas/testsuite/gas/elf/dwarf2-1.s b/gas/testsuite/gas/elf/dwarf2-1.s
new file mode 100644
index 0000000..0310079
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-1.s
@@ -0,0 +1,219 @@
+/* This testcase is derived from a similar test in GDB.
+
+   Copyright 2009 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* This tests that gdb can read compressed sections.  The contents
+   are a basic assembly file, but the .debug_abbrev section has been
+   comrpessed using zlib.  */
+
+/* Dummy function to provide debug information for.  */
+
+	.file "dwarf2-1.c"
+	.text
+	.globl _start
+_start:
+	.int 0
+.Lbegin_text1:
+	.globl func_cu1
+	.type func_cu1, %function
+func_cu1:
+.Lbegin_func_cu1:
+	.int 0
+.Lend_func_cu1:
+	.size func_cu1, .-func_cu1
+.Lend_text1:
+
+/* Debug information */
+
+	.section .debug_info
+.Lcu1_begin:
+	/* CU header */
+	.4byte	.Lcu1_end - .Lcu1_start		/* Length of Compilation Unit */
+.Lcu1_start:
+	.2byte	2				/* DWARF Version */
+	.4byte	.Labbrev1_begin			/* Offset into abbrev section */
+	.byte	4				/* Pointer size */
+
+	/* CU die */
+	.uleb128 1				/* Abbrev: DW_TAG_compile_unit */
+	.4byte	.Lline1_begin			/* DW_AT_stmt_list */
+	.4byte	.Lend_text1			/* DW_AT_high_pc */
+	.4byte	.Lbegin_text1			/* DW_AT_low_pc */
+	.ascii	"file1.txt\0"			/* DW_AT_name */
+	.ascii	"GNU C 3.3.3\0"			/* DW_AT_producer */
+	.byte	1				/* DW_AT_language (C) */
+
+	/* func_cu1 */
+	.uleb128	2			/* Abbrev: DW_TAG_subprogram */
+	.byte		1			/* DW_AT_external */
+	.byte		1			/* DW_AT_decl_file */
+	.byte		2			/* DW_AT_decl_line */
+	.ascii		"func_cu1\0"		/* DW_AT_name */
+	.4byte		.Ltype_int-.Lcu1_begin	/* DW_AT_type */
+	.4byte		.Lbegin_func_cu1	/* DW_AT_low_pc */
+	.4byte		.Lend_func_cu1		/* DW_AT_high_pc */
+	.byte		1			/* DW_AT_frame_base: length */
+	.byte		0x55			/* DW_AT_frame_base: DW_OP_reg5 */
+
+.Ltype_int:
+	.uleb128	3			/* Abbrev: DW_TAG_base_type */
+	.ascii		"int\0"			/* DW_AT_name */
+	.byte		4			/* DW_AT_byte_size */
+	.byte		5			/* DW_AT_encoding */
+
+	.byte		0			/* End of children of CU */
+
+.Lcu1_end:
+
+/* Line table */
+	.section .debug_line
+.Lline1_begin:
+	.4byte		.Lline1_end - .Lline1_start	/* Initial length */
+.Lline1_start:
+	.2byte		2			/* Version */
+	.4byte		.Lline1_lines - .Lline1_hdr	/* header_length */
+.Lline1_hdr:
+	.byte		1			/* Minimum insn length */
+	.byte		1			/* default_is_stmt */
+	.byte		1			/* line_base */
+ 	.byte		1			/* line_range */
+	.byte		0x10			/* opcode_base */
+
+	/* Standard lengths */
+	.byte		0
+	.byte		1
+	.byte		1
+	.byte		1
+	.byte		1
+	.byte		0
+	.byte		0
+	.byte		0
+	.byte		1
+	.byte		0
+	.byte		0
+	.byte		1
+	.byte		0
+	.byte		0
+	.byte		0
+
+	/* Include directories */
+	.byte		0
+
+	/* File names */
+	.ascii		"file1.txt\0"
+	.uleb128	0
+	.uleb128	0
+	.uleb128	0
+
+	.byte		0
+
+.Lline1_lines:
+	.byte		0	/* DW_LNE_set_address */
+	.uleb128	5
+	.byte		2
+	.4byte		.Lbegin_func_cu1
+
+	.byte		3	/* DW_LNS_advance_line */
+	.sleb128	3	/* ... to 4 */
+
+	.byte		1	/* DW_LNS_copy */
+
+	.byte		1	/* DW_LNS_copy (second time as an end-of-prologue marker) */
+
+	.byte		0	/* DW_LNE_set_address */
+	.uleb128	5
+	.byte		2
+	.4byte		.Lend_func_cu1
+
+	.byte		0	/* DW_LNE_end_of_sequence */
+	.uleb128	1
+	.byte		1
+
+.Lline1_end:
+
+/* Abbrev table -- compressed */
+	.section .zdebug_abbrev
+.Labbrev1_begin:
+	.ascii		"ZLIB"
+	.4byte		0
+	.2byte		0
+	.byte		0
+	.byte		51
+	.byte		0x78
+	.byte		0x5e
+	.byte		0x63
+	.byte		0x14
+	.byte		0x64
+	.byte		0x14
+	.byte		0x60
+	.byte		0x13
+	.byte		0x62
+	.byte		0x14
+	.byte		0x64
+	.byte		0x64
+	.byte		0xe6
+	.byte		0x50
+	.byte		0xe5
+	.byte		0x10
+	.byte		0xe6
+	.byte		0x66
+	.byte		0x60
+	.byte		0x60
+	.byte		0xd2
+	.byte		0x63
+	.byte		0xb0
+	.byte		0xe7
+	.byte		0xb1
+	.byte		0xe2
+	.byte		0xb6
+	.byte		0xe6
+	.byte		0x66
+	.byte		0xe6
+	.byte		0xf0
+	.byte		0x14
+	.byte		0x16
+	.byte		0x64
+	.byte		0x14
+	.byte		0x62
+	.byte		0x74
+	.byte		0xe0
+	.byte		0x02
+	.byte		0x00
+	.byte		0x25
+	.byte		0x78
+	.byte		0x02
+	.byte		0x81
+	.byte		0x78
+	.byte		0x9c
+	.byte		0x63
+	.byte		0x60
+	.byte		0x60
+	.byte		0x56
+	.byte		0x61
+	.byte		0x60
+	.byte		0xe6
+	.byte		0xe0
+	.byte		0xe6
+	.byte		0xb6
+	.byte		0xe3
+	.byte		0x66
+	.byte		0x00
+	.byte		0x02
+	.byte		0x00
+	.byte		0x04
+	.byte		0x9c
+	.byte		0x00
+	.byte		0x92
diff --git a/gas/testsuite/gas/elf/dwarf2-2.d b/gas/testsuite/gas/elf/dwarf2-2.d
new file mode 100644
index 0000000..de87004
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-2.d
@@ -0,0 +1,100 @@
+#readelf: -w
+#name: DWARF2 2
+#not-target: ia64-*-*
+
+Contents of the .debug_info section:
+
+  Compilation Unit @ offset 0x0:
+   Length:        0x4e \(32-bit\)
+   Version:       2
+   Abbrev Offset: 0
+   Pointer Size:  4
+ <0><b>: Abbrev Number: 1 \(DW_TAG_compile_unit\)
+    < c>   DW_AT_stmt_list   : 0x0	
+    <10>   DW_AT_high_pc     : 0x.	
+    <14>   DW_AT_low_pc      : 0x.	
+    <18>   DW_AT_name        : file1.txt	
+    <22>   DW_AT_producer    : GNU C 3.3.3	
+    <2e>   DW_AT_language    : 1	\(ANSI C\)
+ <1><2f>: Abbrev Number: 2 \(DW_TAG_subprogram\)
+    <30>   DW_AT_external    : 1	
+    <31>   DW_AT_decl_file   : 1	
+    <32>   DW_AT_decl_line   : 2	
+    <33>   DW_AT_name        : func_cu1	
+    <3c>   DW_AT_type        : <0x4a>	
+    <40>   DW_AT_low_pc      : 0x.	
+    <44>   DW_AT_high_pc     : 0x.	
+    <48>   DW_AT_frame_base  : 1 byte block: 55 	\(DW_OP_reg5\)
+ <1><4a>: Abbrev Number: 3 \(DW_TAG_base_type\)
+    <4b>   DW_AT_name        : int	
+    <4f>   DW_AT_byte_size   : 4	
+    <50>   DW_AT_encoding    : 5	\(signed\)
+
+Raw dump of debug contents of section .debug_line:
+
+  Offset:                      0x0
+  Length:                      62
+  DWARF Version:               2
+  Prologue Length:             35
+  Minimum Instruction Length:  1
+  Initial value of 'is_stmt':  1
+  Line Base:                   1
+  Line Range:                  1
+  Opcode Base:                 16
+
+ Opcodes:
+  Opcode 1 has 0 args
+  Opcode 2 has 1 args
+  Opcode 3 has 1 args
+  Opcode 4 has 1 args
+  Opcode 5 has 1 args
+  Opcode 6 has 0 args
+  Opcode 7 has 0 args
+  Opcode 8 has 0 args
+  Opcode 9 has 1 args
+  Opcode 10 has 0 args
+  Opcode 11 has 0 args
+  Opcode 12 has 1 args
+  Opcode 13 has 0 args
+  Opcode 14 has 0 args
+  Opcode 15 has 0 args
+
+ The Directory Table is empty.
+
+ The File Name Table:
+  Entry	Dir	Time	Size	Name
+  1	0	0	0	file1.txt
+
+ Line Number Statements:
+  Extended opcode 2: set Address to .*
+  Advance Line by 3 to 4
+  Copy
+  Copy
+  Extended opcode 2: set Address to .*
+  Extended opcode 1: End of Sequence
+
+
+Contents of the .zdebug_abbrev section:
+
+  Number TAG
+   1      DW_TAG_compile_unit    \[has children\]
+    DW_AT_stmt_list    DW_FORM_data4
+    DW_AT_high_pc      DW_FORM_addr
+    DW_AT_low_pc       DW_FORM_addr
+    DW_AT_name         DW_FORM_string
+    DW_AT_producer     DW_FORM_string
+    DW_AT_language     DW_FORM_data1
+   2      DW_TAG_subprogram    \[no children\]
+    DW_AT_external     DW_FORM_flag
+    DW_AT_decl_file    DW_FORM_data1
+    DW_AT_decl_line    DW_FORM_data1
+    DW_AT_name         DW_FORM_string
+    DW_AT_type         DW_FORM_ref4
+    DW_AT_low_pc       DW_FORM_addr
+    DW_AT_high_pc      DW_FORM_addr
+    DW_AT_frame_base   DW_FORM_block1
+   3      DW_TAG_base_type    \[no children\]
+    DW_AT_name         DW_FORM_string
+    DW_AT_byte_size    DW_FORM_data1
+    DW_AT_encoding     DW_FORM_data1
+
diff --git a/gas/testsuite/gas/elf/dwarf2-2.s b/gas/testsuite/gas/elf/dwarf2-2.s
new file mode 100644
index 0000000..389918c
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-2.s
@@ -0,0 +1,219 @@
+/* This testcase is derived from a similar test in GDB.
+
+   Copyright 2009 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* This tests that gdb can read compressed sections.  The contents
+   are a basic assembly file, but the .debug_abbrev section has been
+   comrpessed using zlib.  */
+
+/* Dummy function to provide debug information for.  */
+
+	.file "dwarf2-2.c"
+	.section .gnu.linkonce.t.foo,"axG",%progbits,foo,comdat
+	.globl _start
+_start:
+	.int 0
+.Lbegin_text1:
+	.globl func_cu1
+	.type func_cu1, %function
+func_cu1:
+.Lbegin_func_cu1:
+	.int 0
+.Lend_func_cu1:
+	.size func_cu1, .-func_cu1
+.Lend_text1:
+
+/* Debug information */
+
+	.section .debug_info,"G",%progbits,foo,comdat
+.Lcu1_begin:
+	/* CU header */
+	.4byte	.Lcu1_end - .Lcu1_start		/* Length of Compilation Unit */
+.Lcu1_start:
+	.2byte	2				/* DWARF Version */
+	.4byte	.Labbrev1_begin			/* Offset into abbrev section */
+	.byte	4				/* Pointer size */
+
+	/* CU die */
+	.uleb128 1				/* Abbrev: DW_TAG_compile_unit */
+	.4byte	.Lline1_begin			/* DW_AT_stmt_list */
+	.4byte	.Lend_text1			/* DW_AT_high_pc */
+	.4byte	.Lbegin_text1			/* DW_AT_low_pc */
+	.ascii	"file1.txt\0"			/* DW_AT_name */
+	.ascii	"GNU C 3.3.3\0"			/* DW_AT_producer */
+	.byte	1				/* DW_AT_language (C) */
+
+	/* func_cu1 */
+	.uleb128	2			/* Abbrev: DW_TAG_subprogram */
+	.byte		1			/* DW_AT_external */
+	.byte		1			/* DW_AT_decl_file */
+	.byte		2			/* DW_AT_decl_line */
+	.ascii		"func_cu1\0"		/* DW_AT_name */
+	.4byte		.Ltype_int-.Lcu1_begin	/* DW_AT_type */
+	.4byte		.Lbegin_func_cu1	/* DW_AT_low_pc */
+	.4byte		.Lend_func_cu1		/* DW_AT_high_pc */
+	.byte		1			/* DW_AT_frame_base: length */
+	.byte		0x55			/* DW_AT_frame_base: DW_OP_reg5 */
+
+.Ltype_int:
+	.uleb128	3			/* Abbrev: DW_TAG_base_type */
+	.ascii		"int\0"			/* DW_AT_name */
+	.byte		4			/* DW_AT_byte_size */
+	.byte		5			/* DW_AT_encoding */
+
+	.byte		0			/* End of children of CU */
+
+.Lcu1_end:
+
+/* Line table */
+	.section .debug_line,"G",%progbits,foo,comdat
+.Lline1_begin:
+	.4byte		.Lline1_end - .Lline1_start	/* Initial length */
+.Lline1_start:
+	.2byte		2			/* Version */
+	.4byte		.Lline1_lines - .Lline1_hdr	/* header_length */
+.Lline1_hdr:
+	.byte		1			/* Minimum insn length */
+	.byte		1			/* default_is_stmt */
+	.byte		1			/* line_base */
+ 	.byte		1			/* line_range */
+	.byte		0x10			/* opcode_base */
+
+	/* Standard lengths */
+	.byte		0
+	.byte		1
+	.byte		1
+	.byte		1
+	.byte		1
+	.byte		0
+	.byte		0
+	.byte		0
+	.byte		1
+	.byte		0
+	.byte		0
+	.byte		1
+	.byte		0
+	.byte		0
+	.byte		0
+
+	/* Include directories */
+	.byte		0
+
+	/* File names */
+	.ascii		"file1.txt\0"
+	.uleb128	0
+	.uleb128	0
+	.uleb128	0
+
+	.byte		0
+
+.Lline1_lines:
+	.byte		0	/* DW_LNE_set_address */
+	.uleb128	5
+	.byte		2
+	.4byte		.Lbegin_func_cu1
+
+	.byte		3	/* DW_LNS_advance_line */
+	.sleb128	3	/* ... to 4 */
+
+	.byte		1	/* DW_LNS_copy */
+
+	.byte		1	/* DW_LNS_copy (second time as an end-of-prologue marker) */
+
+	.byte		0	/* DW_LNE_set_address */
+	.uleb128	5
+	.byte		2
+	.4byte		.Lend_func_cu1
+
+	.byte		0	/* DW_LNE_end_of_sequence */
+	.uleb128	1
+	.byte		1
+
+.Lline1_end:
+
+/* Abbrev table -- compressed */
+	.section .zdebug_abbrev,"G",%progbits,foo,comdat
+.Labbrev1_begin:
+	.ascii		"ZLIB"
+	.4byte		0
+	.2byte		0
+	.byte		0
+	.byte		51
+	.byte		0x78
+	.byte		0x5e
+	.byte		0x63
+	.byte		0x14
+	.byte		0x64
+	.byte		0x14
+	.byte		0x60
+	.byte		0x13
+	.byte		0x62
+	.byte		0x14
+	.byte		0x64
+	.byte		0x64
+	.byte		0xe6
+	.byte		0x50
+	.byte		0xe5
+	.byte		0x10
+	.byte		0xe6
+	.byte		0x66
+	.byte		0x60
+	.byte		0x60
+	.byte		0xd2
+	.byte		0x63
+	.byte		0xb0
+	.byte		0xe7
+	.byte		0xb1
+	.byte		0xe2
+	.byte		0xb6
+	.byte		0xe6
+	.byte		0x66
+	.byte		0xe6
+	.byte		0xf0
+	.byte		0x14
+	.byte		0x16
+	.byte		0x64
+	.byte		0x14
+	.byte		0x62
+	.byte		0x74
+	.byte		0xe0
+	.byte		0x02
+	.byte		0x00
+	.byte		0x25
+	.byte		0x78
+	.byte		0x02
+	.byte		0x81
+	.byte		0x78
+	.byte		0x9c
+	.byte		0x63
+	.byte		0x60
+	.byte		0x60
+	.byte		0x56
+	.byte		0x61
+	.byte		0x60
+	.byte		0xe6
+	.byte		0xe0
+	.byte		0xe6
+	.byte		0xb6
+	.byte		0xe3
+	.byte		0x66
+	.byte		0x00
+	.byte		0x02
+	.byte		0x00
+	.byte		0x04
+	.byte		0x9c
+	.byte		0x00
+	.byte		0x92
diff --git a/gas/testsuite/gas/elf/dwarf2-3.d b/gas/testsuite/gas/elf/dwarf2-3.d
new file mode 100644
index 0000000..2d8c2ac
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-3.d
@@ -0,0 +1,38 @@
+#readelf: -wl
+#name: DWARF2 3
+#not-target: ia64-*-*
+
+Raw dump of debug contents of section .debug_line:
+
+  Offset:                      0x0
+  Length:                      41
+  DWARF Version:               2
+  Prologue Length:             35
+  Minimum Instruction Length:  [0-9]*
+  Initial value of 'is_stmt':  1
+  Line Base:                   -5
+  Line Range:                  14
+  Opcode Base:                 13
+
+ Opcodes:
+  Opcode 1 has 0 args
+  Opcode 2 has 1 args
+  Opcode 3 has 1 args
+  Opcode 4 has 1 args
+  Opcode 5 has 1 args
+  Opcode 6 has 0 args
+  Opcode 7 has 0 args
+  Opcode 8 has 0 args
+  Opcode 9 has 1 args
+  Opcode 10 has 0 args
+  Opcode 11 has 0 args
+  Opcode 12 has 1 args
+
+ The Directory Table is empty.
+
+ The File Name Table:
+  Entry	Dir	Time	Size	Name
+  1	0	0	0	/beginwarn.c
+
+ Line Number Statements:
+
diff --git a/gas/testsuite/gas/elf/dwarf2-3.s b/gas/testsuite/gas/elf/dwarf2-3.s
new file mode 100644
index 0000000..8c4b1e8
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf2-3.s
@@ -0,0 +1,186 @@
+	.file	"beginwarn.c"
+	.section	.debug_abbrev,"",%progbits
+.Ldebug_abbrev0:
+	.section	.debug_info,"",%progbits
+.Ldebug_info0:
+	.section	.debug_line,"",%progbits
+.Ldebug_line0:
+	.text
+.Ltext0:
+	.section	.init_array,"aw"
+	.align 4
+	.type	init_array, %object
+	.size	init_array, 4
+init_array:
+	.long	foo
+	.section	.gnu.warning.foo,"a",%progbits
+	.type	_evoke_link_warning_foo, %object
+	.size	_evoke_link_warning_foo, 27
+_evoke_link_warning_foo:
+	.string	"function foo is deprecated"
+	.file 1 "/beginwarn.c"
+	.text
+.Letext0:
+	.section	.debug_info
+	.long	0x8a
+	.short  0x2
+	.long	.Ldebug_abbrev0
+	.byte	0x4
+	.uleb128 0x1
+	.long	.Ldebug_line0
+	.long	.Letext0
+	.long	.Ltext0
+	.long	.LASF4
+	.byte	0x1
+	.long	.LASF5
+	.uleb128 0x2
+	.long	0x31
+	.long	0x38
+	.uleb128 0x3
+	.long	0x31
+	.byte	0x1a
+	.byte	0x0
+	.uleb128 0x4
+	.long	.LASF0
+	.byte	0x4
+	.byte	0x7
+	.uleb128 0x5
+	.long	0x3d
+	.uleb128 0x4
+	.long	.LASF1
+	.byte	0x1
+	.byte	0x6
+	.uleb128 0x6
+	.long	.LASF2
+	.byte	0x1
+	.byte	0x3
+	.long	0x55
+	.byte	0x5
+	.byte	0x3
+	.long	_evoke_link_warning_foo
+	.uleb128 0x5
+	.long	0x21
+	.uleb128 0x2
+	.long	0x6a
+	.long	0x6c
+	.uleb128 0x3
+	.long	0x31
+	.byte	0x0
+	.byte	0x0
+	.uleb128 0x7
+	.byte	0x1
+	.uleb128 0x5
+	.long	0x71
+	.uleb128 0x8
+	.byte	0x4
+	.long	0x6a
+	.uleb128 0x6
+	.long	.LASF3
+	.byte	0x1
+	.byte	0x9
+	.long	0x88
+	.byte	0x5
+	.byte	0x3
+	.long	init_array
+	.uleb128 0x5
+	.long	0x5a
+	.byte	0x0
+	.section	.debug_abbrev
+	.uleb128 0x1
+	.uleb128 0x11
+	.byte	0x1
+	.uleb128 0x10
+	.uleb128 0x6
+	.uleb128 0x12
+	.uleb128 0x1
+	.uleb128 0x11
+	.uleb128 0x1
+	.uleb128 0x25
+	.uleb128 0xe
+	.uleb128 0x13
+	.uleb128 0xb
+	.uleb128 0x3
+	.uleb128 0xe
+	.byte	0x0
+	.byte	0x0
+	.uleb128 0x2
+	.uleb128 0x1
+	.byte	0x1
+	.uleb128 0x1
+	.uleb128 0x13
+	.uleb128 0x49
+	.uleb128 0x13
+	.byte	0x0
+	.byte	0x0
+	.uleb128 0x3
+	.uleb128 0x21
+	.byte	0x0
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x2f
+	.uleb128 0xb
+	.byte	0x0
+	.byte	0x0
+	.uleb128 0x4
+	.uleb128 0x24
+	.byte	0x0
+	.uleb128 0x3
+	.uleb128 0xe
+	.uleb128 0xb
+	.uleb128 0xb
+	.uleb128 0x3e
+	.uleb128 0xb
+	.byte	0x0
+	.byte	0x0
+	.uleb128 0x5
+	.uleb128 0x26
+	.byte	0x0
+	.uleb128 0x49
+	.uleb128 0x13
+	.byte	0x0
+	.byte	0x0
+	.uleb128 0x6
+	.uleb128 0x34
+	.byte	0x0
+	.uleb128 0x3
+	.uleb128 0xe
+	.uleb128 0x3a
+	.uleb128 0xb
+	.uleb128 0x3b
+	.uleb128 0xb
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x2
+	.uleb128 0xa
+	.byte	0x0
+	.byte	0x0
+	.uleb128 0x7
+	.uleb128 0x15
+	.byte	0x0
+	.uleb128 0x27
+	.uleb128 0xc
+	.byte	0x0
+	.byte	0x0
+	.uleb128 0x8
+	.uleb128 0xf
+	.byte	0x0
+	.uleb128 0xb
+	.uleb128 0xb
+	.uleb128 0x49
+	.uleb128 0x13
+	.byte	0x0
+	.byte	0x0
+	.byte	0x0
+	.section	.debug_str,"MS",%progbits,1
+.LASF5:
+	.string	"/beginwarn.c"
+.LASF0:
+	.string	"unsigned int"
+.LASF3:
+	.string	"init_array"
+.LASF2:
+	.string	"_evoke_link_warning_foo"
+.LASF4:
+	.string	"GNU C 3.4.6"
+.LASF1:
+	.string	"char"
diff --git a/gas/testsuite/gas/elf/elf.exp b/gas/testsuite/gas/elf/elf.exp
index e65d2cf..91d03e6 100644
--- a/gas/testsuite/gas/elf/elf.exp
+++ b/gas/testsuite/gas/elf/elf.exp
@@ -149,4 +149,7 @@ if { ([istarget "*-*-*elf*"]
 
     run_dump_test "section6" 
     run_dump_test "section7" 
+    run_dump_test "dwarf2-1" 
+    run_dump_test "dwarf2-2" 
+    run_dump_test "dwarf2-3" 
 }
diff --git a/gas/testsuite/gas/i386/debug1.d b/gas/testsuite/gas/i386/debug1.d
new file mode 100644
index 0000000..437e38f
--- /dev/null
+++ b/gas/testsuite/gas/i386/debug1.d
@@ -0,0 +1,46 @@
+#as: --gdwarf-2
+#readelf: -wl
+#name: DWARF2 debugging information 1
+
+Raw dump of debug contents of section .debug_line:
+
+  Offset:                      0x0
+  Length:                      .*
+  DWARF Version:               2
+  Prologue Length:             .*
+  Minimum Instruction Length:  1
+  Initial value of 'is_stmt':  1
+  Line Base:                   -5
+  Line Range:                  14
+  Opcode Base:                 13
+
+ Opcodes:
+  Opcode 1 has 0 args
+  Opcode 2 has 1 args
+  Opcode 3 has 1 args
+  Opcode 4 has 1 args
+  Opcode 5 has 1 args
+  Opcode 6 has 0 args
+  Opcode 7 has 0 args
+  Opcode 8 has 0 args
+  Opcode 9 has 1 args
+  Opcode 10 has 0 args
+  Opcode 11 has 0 args
+  Opcode 12 has 1 args
+
+ The Directory Table:
+  .*
+
+ The File Name Table:
+  Entry	Dir	Time	Size	Name
+  1	1	0	0	debug1.s
+
+ Line Number Statements:
+  Extended opcode 2: set Address to 0x0
+  Special opcode 7: advance Address by 0 to 0x0 and Line by 2 to 3
+  Special opcode 20: advance Address by 1 to 0x1 and Line by 1 to 4
+  Special opcode 20: advance Address by 1 to 0x2 and Line by 1 to 5
+  Advance PC by 1 to 0x3
+  Extended opcode 1: End of Sequence
+
+
diff --git a/gas/testsuite/gas/i386/debug1.s b/gas/testsuite/gas/i386/debug1.s
new file mode 100644
index 0000000..da623af
--- /dev/null
+++ b/gas/testsuite/gas/i386/debug1.s
@@ -0,0 +1,5 @@
+	.file "debug1.s"
+	.text
+	nop
+	nop
+	nop
diff --git a/gas/testsuite/gas/i386/i386.exp b/gas/testsuite/gas/i386/i386.exp
index 9d5e957..7c5a69d 100644
--- a/gas/testsuite/gas/i386/i386.exp
+++ b/gas/testsuite/gas/i386/i386.exp
@@ -193,6 +193,7 @@ if [expr ([istarget "i*86-*-*"] ||  [istarget "x86_64-*-*"]) && [gas_32_check]]
 	run_dump_test "ifunc"
 	run_list_test "l1om-inval" "-march=l1om --32"
 	run_dump_test "localpic"
+	run_dump_test "debug1"
     }
 
     # This is a PE specific test.
@@ -349,6 +350,7 @@ if [expr ([istarget "i*86-*-*"] || [istarget "x86_64-*-*"]) && [gas_64_check]] t
 	run_dump_test "x86-64-ifunc"
 	run_dump_test "l1om"
 	run_dump_test "x86-64-localpic"
+	run_dump_test "debug1"
     }
 
     set ASFLAGS "$old_ASFLAGS"

	* gas/elf/elf.exp: Run dwarf2-1, dwarf2-2 and dwarf2-3.

	* gas/i386/i386.exp: Run debug1 for both 32bit and 64bit.


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2009-10-27 17:32 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-18  4:09 PATCH: PR gas/10531: Strange assembler warning message on section group H.J. Lu
2009-08-18  5:40 ` Alan Modra
2009-08-18 16:41   ` H.J. Lu
2009-08-18 17:44     ` Daniel Jacobowitz
2009-08-18 17:52       ` H.J. Lu
2009-08-18 18:20         ` Daniel Jacobowitz
2009-08-18 18:48           ` H.J. Lu
2009-08-19  3:08 ` Jim Wilson
2009-08-19  5:25   ` H.J. Lu
2009-08-19 19:50     ` Jim Wilson
2009-08-20  4:02       ` H.J. Lu
2009-08-20  5:09         ` H.J. Lu
2009-08-20 21:08         ` Jim Wilson
2009-08-21  3:49         ` Jim Wilson
2009-08-21  4:26           ` H.J. Lu
2009-08-21 13:36             ` H.J. Lu
2009-08-22 19:10               ` H.J. Lu
2009-08-23  7:28                 ` H.J. Lu
2009-10-26 22:11                   ` Jim Wilson
2009-10-27 17:32                     ` H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).