public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] as: Add a .dwarf_level directive to set the DWARF level
@ 2021-01-17  4:48 H.J. Lu
  2021-01-17  6:11 ` Fangrui Song
  0 siblings, 1 reply; 10+ messages in thread
From: H.J. Lu @ 2021-01-17  4:48 UTC (permalink / raw)
  To: binutils

Currently

$ as -o x.o x.s

fails when x.s contains DWARF5 info.  Add a .dwarf_level directive to
set the DWARF level and GCC can emit ".dwarf_level 5" when generating
DWARF5 info so that

$ gcc -S -g -c x.c
$ gcc -c x.s

works.

	PR gas/27195
	* NEWS: Mention .dwarf_level.
	* read.c (s_dwarf_level): New.
	(potable): Add dwarf_level.
	* doc/as.texi: Document .dwarf_level.
	* testsuite/gas/elf/elf.exp: Run PR gas/27195 tests.
	* testsuite/gas/elf/dwarf-5-directive-1.d: New file.
	* testsuite/gas/elf/dwarf-5-directive-1.s: Likewise.
	* testsuite/gas/elf/dwarf-5-directive-2.d: Likewise.
	* testsuite/gas/elf/dwarf-5-directive-2.l: Likewise.
	* testsuite/gas/elf/dwarf-5-directive-2.s: Likewise.
	* testsuite/gas/elf/dwarf-5-directive-3.d: Likewise.
	* testsuite/gas/elf/dwarf-5-directive-3.l: Likewise.
	* testsuite/gas/elf/dwarf-5-directive-3.s: Likewise.
---
 gas/NEWS                                    |  2 ++
 gas/doc/as.texi                             |  7 +++++++
 gas/read.c                                  | 12 ++++++++++++
 gas/testsuite/gas/elf/dwarf-5-directive-1.d | 12 ++++++++++++
 gas/testsuite/gas/elf/dwarf-5-directive-1.s | 15 +++++++++++++++
 gas/testsuite/gas/elf/dwarf-5-directive-2.d |  3 +++
 gas/testsuite/gas/elf/dwarf-5-directive-2.l |  2 ++
 gas/testsuite/gas/elf/dwarf-5-directive-2.s | 15 +++++++++++++++
 gas/testsuite/gas/elf/dwarf-5-directive-3.d |  3 +++
 gas/testsuite/gas/elf/dwarf-5-directive-3.l |  2 ++
 gas/testsuite/gas/elf/dwarf-5-directive-3.s | 15 +++++++++++++++
 gas/testsuite/gas/elf/elf.exp               |  3 +++
 12 files changed, 91 insertions(+)
 create mode 100644 gas/testsuite/gas/elf/dwarf-5-directive-1.d
 create mode 100644 gas/testsuite/gas/elf/dwarf-5-directive-1.s
 create mode 100644 gas/testsuite/gas/elf/dwarf-5-directive-2.d
 create mode 100644 gas/testsuite/gas/elf/dwarf-5-directive-2.l
 create mode 100644 gas/testsuite/gas/elf/dwarf-5-directive-2.s
 create mode 100644 gas/testsuite/gas/elf/dwarf-5-directive-3.d
 create mode 100644 gas/testsuite/gas/elf/dwarf-5-directive-3.l
 create mode 100644 gas/testsuite/gas/elf/dwarf-5-directive-3.s

diff --git a/gas/NEWS b/gas/NEWS
index 33dc91b48b4..67d7bfaae40 100644
--- a/gas/NEWS
+++ b/gas/NEWS
@@ -2,6 +2,8 @@
 
 Changes in 2.36:
 
+* Added a .dwarf_level directive to set the DWARF level.
+
 * Add support for Intel AVX VNNI instructions.
 
 * Add support for Intel HRESET instruction.
diff --git a/gas/doc/as.texi b/gas/doc/as.texi
index e0559cf0f1d..2f751bc16a0 100644
--- a/gas/doc/as.texi
+++ b/gas/doc/as.texi
@@ -4384,6 +4384,7 @@ Some machine configurations provide additional directives.
 @end ifset
 
 * Double::                      @code{.double @var{flonums}}
+* Dwarf_level::                 @code{.dwarf_level @var{level}}
 * Eject::                       @code{.eject}
 * Else::                        @code{.else}
 * Elseif::                      @code{.elseif}
@@ -5188,6 +5189,12 @@ in @sc{ieee} format.
 @end ifset
 @end ifclear
 
+@node Dwarf_level
+@section @code{.dwarf_level @var{level}}
+
+@cindex @code{dwarf_level} directive
+Set the DWARF level to @var{level}.  Must be between 2 and 5.
+
 @node Eject
 @section @code{.eject}
 
diff --git a/gas/read.c b/gas/read.c
index 06ca7fbb95f..0f0fb0887c8 100644
--- a/gas/read.c
+++ b/gas/read.c
@@ -343,6 +343,17 @@ po_entry_find (htab_t table, const char *poc_name)
 
 static struct htab *po_hash;
 
+static void
+s_dwarf_level (int arg ATTRIBUTE_UNUSED)
+{
+  dwarf_level = get_absolute_expression ();
+  if (dwarf_level < 2 || dwarf_level > 5)
+    as_fatal (_("invalid DWARF level %d (must be between 2 and 5)"),
+	      dwarf_level);
+  SKIP_WHITESPACE ();
+  demand_empty_rest_of_line ();
+}
+
 static const pseudo_typeS potable[] = {
   {"abort", s_abort, 0},
   {"align", s_align_ptwo, 0},
@@ -394,6 +405,7 @@ static const pseudo_typeS potable[] = {
 #endif
 /* dim  */
   {"double", float_cons, 'd'},
+  {"dwarf_level", s_dwarf_level, 0},
 /* dsect  */
   {"eject", listing_eject, 0},	/* Formfeed listing.  */
   {"else", s_else, 0},
diff --git a/gas/testsuite/gas/elf/dwarf-5-directive-1.d b/gas/testsuite/gas/elf/dwarf-5-directive-1.d
new file mode 100644
index 00000000000..74247c492df
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf-5-directive-1.d
@@ -0,0 +1,12 @@
+#as:
+#name: DWARF5 directive 1
+#readelf: -wi
+
+#...
+  Compilation Unit @ offset 0x0:
+   Length:        0x.*
+   Version:       5
+   Unit Type:     DW_UT_compile \(1\)
+   Abbrev Offset: 0x0
+   Pointer Size:  .
+#pass
diff --git a/gas/testsuite/gas/elf/dwarf-5-directive-1.s b/gas/testsuite/gas/elf/dwarf-5-directive-1.s
new file mode 100644
index 00000000000..598ec9e65eb
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf-5-directive-1.s
@@ -0,0 +1,15 @@
+	.dwarf_level 5
+	.text
+	.file 1 "foo/bar.s"
+	.loc_mark_labels 1
+	.globl foobar
+	.type   foobar, %function
+foobar:
+	.quad   0x1
+	.size foobar, .-foobar
+
+	.globl baz
+	.type  baz, %function
+baz:
+	.quad 0x1
+	.size baz, .-baz
diff --git a/gas/testsuite/gas/elf/dwarf-5-directive-2.d b/gas/testsuite/gas/elf/dwarf-5-directive-2.d
new file mode 100644
index 00000000000..5fd8991338c
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf-5-directive-2.d
@@ -0,0 +1,3 @@
+#as:
+#name: DWARF5 directive 2
+#error_output: dwarf-5-directive-2.l
diff --git a/gas/testsuite/gas/elf/dwarf-5-directive-2.l b/gas/testsuite/gas/elf/dwarf-5-directive-2.l
new file mode 100644
index 00000000000..fab172218db
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf-5-directive-2.l
@@ -0,0 +1,2 @@
+[^:]*: Assembler messages:
+[^:]*.* Fatal error: invalid DWARF level 1 \(must be between 2 and 5\)
diff --git a/gas/testsuite/gas/elf/dwarf-5-directive-2.s b/gas/testsuite/gas/elf/dwarf-5-directive-2.s
new file mode 100644
index 00000000000..3d34e34b215
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf-5-directive-2.s
@@ -0,0 +1,15 @@
+	.dwarf_level 1
+	.text
+	.file 1 "foo/bar.s"
+	.loc_mark_labels 1
+	.globl foobar
+	.type   foobar, %function
+foobar:
+	.quad   0x1
+	.size foobar, .-foobar
+
+	.globl baz
+	.type  baz, %function
+baz:
+	.quad 0x1
+	.size baz, .-baz
diff --git a/gas/testsuite/gas/elf/dwarf-5-directive-3.d b/gas/testsuite/gas/elf/dwarf-5-directive-3.d
new file mode 100644
index 00000000000..f3a1625efaf
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf-5-directive-3.d
@@ -0,0 +1,3 @@
+#as:
+#name: DWARF5 directive 3
+#error_output: dwarf-5-directive-3.l
diff --git a/gas/testsuite/gas/elf/dwarf-5-directive-3.l b/gas/testsuite/gas/elf/dwarf-5-directive-3.l
new file mode 100644
index 00000000000..6d8b748a438
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf-5-directive-3.l
@@ -0,0 +1,2 @@
+[^:]*: Assembler messages:
+[^:]*.* Fatal error: invalid DWARF level 6 \(must be between 2 and 5\)
diff --git a/gas/testsuite/gas/elf/dwarf-5-directive-3.s b/gas/testsuite/gas/elf/dwarf-5-directive-3.s
new file mode 100644
index 00000000000..0cec4c9a94c
--- /dev/null
+++ b/gas/testsuite/gas/elf/dwarf-5-directive-3.s
@@ -0,0 +1,15 @@
+	.dwarf_level 6
+	.text
+	.file 1 "foo/bar.s"
+	.loc_mark_labels 1
+	.globl foobar
+	.type   foobar, %function
+foobar:
+	.quad   0x1
+	.size foobar, .-foobar
+
+	.globl baz
+	.type  baz, %function
+baz:
+	.quad 0x1
+	.size baz, .-baz
diff --git a/gas/testsuite/gas/elf/elf.exp b/gas/testsuite/gas/elf/elf.exp
index a0f98eddd67..881cca0b9e1 100644
--- a/gas/testsuite/gas/elf/elf.exp
+++ b/gas/testsuite/gas/elf/elf.exp
@@ -297,6 +297,9 @@ if { [is_elf_format] } then {
     run_dump_test "dwarf-5-file0" $dump_opts
     run_dump_test "dwarf-4-cu" $dump_opts
     run_dump_test "dwarf-5-cu" $dump_opts
+    run_dump_test "dwarf-5-directive-1" $dump_opts
+    run_dump_test "dwarf-5-directive-2" $dump_opts
+    run_dump_test "dwarf-5-directive-3" $dump_opts
     run_dump_test "dwarf-5-nop-for-line-table" $dump_opts
     run_dump_test "pr25917"
     run_dump_test "bss"
-- 
2.29.2


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

* Re: [PATCH] as: Add a .dwarf_level directive to set the DWARF level
  2021-01-17  4:48 [PATCH] as: Add a .dwarf_level directive to set the DWARF level H.J. Lu
@ 2021-01-17  6:11 ` Fangrui Song
  2021-01-17 16:00   ` [PATCH] as: Automatically enable DWARF5 support H.J. Lu
  0 siblings, 1 reply; 10+ messages in thread
From: Fangrui Song @ 2021-01-17  6:11 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

On 2021-01-16, H.J. Lu via Binutils wrote:
>Currently
>
>$ as -o x.o x.s
>
>fails when x.s contains DWARF5 info.  Add a .dwarf_level directive to
>set the DWARF level and GCC can emit ".dwarf_level 5" when generating
>DWARF5 info so that
>
>$ gcc -S -g -c x.c
>$ gcc -c x.s
>
>works.

The problem is file number 0 in .file and .loc directives.  An alternative
design is to detect number 0 and upgrade to DWARF v5 line tables automatically.

If we decide to add a new directive, .dwarf_version is better than .dwarf_level .
The DWARF specifications don't use the term "level".

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

* [PATCH] as: Automatically enable DWARF5 support
  2021-01-17  6:11 ` Fangrui Song
@ 2021-01-17 16:00   ` H.J. Lu
  2021-01-17 18:56     ` Fangrui Song
  2021-01-18  5:57     ` Alan Modra
  0 siblings, 2 replies; 10+ messages in thread
From: H.J. Lu @ 2021-01-17 16:00 UTC (permalink / raw)
  To: Fangrui Song, Mark Wielaard; +Cc: Binutils

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

On Sat, Jan 16, 2021 at 10:11 PM Fangrui Song <i@maskray.me> wrote:
>
> On 2021-01-16, H.J. Lu via Binutils wrote:
> >Currently
> >
> >$ as -o x.o x.s
> >
> >fails when x.s contains DWARF5 info.  Add a .dwarf_level directive to
> >set the DWARF level and GCC can emit ".dwarf_level 5" when generating
> >DWARF5 info so that
> >
> >$ gcc -S -g -c x.c
> >$ gcc -c x.s
> >
> >works.
>
> The problem is file number 0 in .file and .loc directives.  An alternative
> design is to detect number 0 and upgrade to DWARF v5 line tables automatically.
>
> If we decide to add a new directive, .dwarf_version is better than .dwarf_level .
> The DWARF specifications don't use the term "level".

How about this patch to automatically enable DWARF5 support?

-- 
H.J.

[-- Attachment #2: 0001-as-Automatically-enable-DWARF5-support.patch --]
[-- Type: application/x-patch, Size: 3193 bytes --]

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

* Re: [PATCH] as: Automatically enable DWARF5 support
  2021-01-17 16:00   ` [PATCH] as: Automatically enable DWARF5 support H.J. Lu
@ 2021-01-17 18:56     ` Fangrui Song
  2021-01-17 19:26       ` H.J. Lu
  2021-01-18  5:57     ` Alan Modra
  1 sibling, 1 reply; 10+ messages in thread
From: Fangrui Song @ 2021-01-17 18:56 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Mark Wielaard, Binutils

On 2021-01-17, H.J. Lu wrote:
>On Sat, Jan 16, 2021 at 10:11 PM Fangrui Song <i@maskray.me> wrote:
>>
>> On 2021-01-16, H.J. Lu via Binutils wrote:
>> >Currently
>> >
>> >$ as -o x.o x.s
>> >
>> >fails when x.s contains DWARF5 info.  Add a .dwarf_level directive to
>> >set the DWARF level and GCC can emit ".dwarf_level 5" when generating
>> >DWARF5 info so that
>> >
>> >$ gcc -S -g -c x.c
>> >$ gcc -c x.s
>> >
>> >works.
>>
>> The problem is file number 0 in .file and .loc directives.  An alternative
>> design is to detect number 0 and upgrade to DWARF v5 line tables automatically.
>>
>> If we decide to add a new directive, .dwarf_version is better than .dwarf_level .
>> The DWARF specifications don't use the term "level".
>
>How about this patch to automatically enable DWARF5 support?
>
>-- 
>H.J.

Thanks! I created a patch for LLVM integrated assembler:
https://reviews.llvm.org/D94882 to bring attention to debug info folks.


Some nitpicks:

> "fails when x.s contains DWARF5 info."

This can be elaborated: it is .file 0 or .loc 0.

as -gdwarf-4 x.s upon .file 0 probably deserves a test.  On LLVM side, making
it error requires additional complexity so I am going to ignore the diagnostic.
It is perfectly fine for as to error if it does not add much complexity.

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

* Re: [PATCH] as: Automatically enable DWARF5 support
  2021-01-17 18:56     ` Fangrui Song
@ 2021-01-17 19:26       ` H.J. Lu
  0 siblings, 0 replies; 10+ messages in thread
From: H.J. Lu @ 2021-01-17 19:26 UTC (permalink / raw)
  To: Fangrui Song; +Cc: Mark Wielaard, Binutils

On Sun, Jan 17, 2021 at 10:56 AM Fangrui Song <i@maskray.me> wrote:
>
> On 2021-01-17, H.J. Lu wrote:
> >On Sat, Jan 16, 2021 at 10:11 PM Fangrui Song <i@maskray.me> wrote:
> >>
> >> On 2021-01-16, H.J. Lu via Binutils wrote:
> >> >Currently
> >> >
> >> >$ as -o x.o x.s
> >> >
> >> >fails when x.s contains DWARF5 info.  Add a .dwarf_level directive to
> >> >set the DWARF level and GCC can emit ".dwarf_level 5" when generating
> >> >DWARF5 info so that
> >> >
> >> >$ gcc -S -g -c x.c
> >> >$ gcc -c x.s
> >> >
> >> >works.
> >>
> >> The problem is file number 0 in .file and .loc directives.  An alternative
> >> design is to detect number 0 and upgrade to DWARF v5 line tables automatically.
> >>
> >> If we decide to add a new directive, .dwarf_version is better than .dwarf_level .
> >> The DWARF specifications don't use the term "level".
> >
> >How about this patch to automatically enable DWARF5 support?
> >
> >--
> >H.J.
>
> Thanks! I created a patch for LLVM integrated assembler:
> https://reviews.llvm.org/D94882 to bring attention to debug info folks.
>
>
> Some nitpicks:
>
> > "fails when x.s contains DWARF5 info."
>
> This can be elaborated: it is .file 0 or .loc 0.

Like

---
Currently

$ as -o x.o x.s

fails when x.s contains DWARF5 ".file 0" or ".loc 0" directives.  Update
assembler to automatically enable DWARF5 support so that

$ gcc -S -g -c x.c
$ gcc -c x.s

works.
---

> as -gdwarf-4 x.s upon .file 0 probably deserves a test.  On LLVM side, making

I updated the patch to test -gdwarf-3 with ".file 0" in

https://gitlab.com/x86-binutils/binutils-gdb/-/commit/a1da4f25964b54317071fd27fd9121c187f2a79a

Since readelf doesn't support ".loc 0", I have a followup patch:

https://gitlab.com/x86-binutils/binutils-gdb/-/commit/edde4bf8d2c35d94a0567e8bd3c5d3d4b1233010

> it error requires additional complexity so I am going to ignore the diagnostic.
> It is perfectly fine for as to error if it does not add much complexity.


-- 
H.J.

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

* Re: [PATCH] as: Automatically enable DWARF5 support
  2021-01-17 16:00   ` [PATCH] as: Automatically enable DWARF5 support H.J. Lu
  2021-01-17 18:56     ` Fangrui Song
@ 2021-01-18  5:57     ` Alan Modra
  2021-01-18 13:36       ` V2 " H.J. Lu
  1 sibling, 1 reply; 10+ messages in thread
From: Alan Modra @ 2021-01-18  5:57 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Fangrui Song, Mark Wielaard, Binutils

On Sun, Jan 17, 2021 at 08:00:25AM -0800, H.J. Lu via Binutils wrote:
> How about this patch to automatically enable DWARF5 support?

> diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
> index a428370ecca..6c9871cb300 100644
> --- a/gas/dwarf2dbg.c
> +++ b/gas/dwarf2dbg.c
> @@ -551,7 +551,7 @@ dwarf2_gen_line_info (addressT ofs, struct dwarf2_line_info *loc)
>    if (loc->line == 0)
>      return;
>    if (loc->filenum == 0 && DWARF2_LINE_VERSION < 5)
> -    return;
> +    dwarf_level = 5;
>  
>    /* Don't emit sequences of line symbols for the same line when the
>       symbols apply to assembler code.  It is necessary to emit

A target may override the default DWARF2_LINE_VERSION, so I think you
should write something like

  if (loc->filenum == 0 && dwarf_level < 5)
    dwarf_level = 5;
  if (loc->filenum == 0 && DWARF2_LINE_VERSION < 5)
    return;


> @@ -1043,11 +1043,7 @@ dwarf2_directive_filename (void)
>    num = get_absolute_expression ();
>  
>    if ((offsetT) num < 1 && DWARF2_LINE_VERSION < 5)
> -    {
> -      as_bad (_("file number less than one"));
> -      ignore_rest_of_line ();
> -      return NULL;
> -    }
> +    dwarf_level = 5;
>  
>    /* FIXME: Should we allow ".file <N>\n" as an expression meaning
>       "switch back to the already allocated file <N> as the current

Similarly here, and in any case we shouldn't ignore a negative file
number.  This should be

  if (num == 0 && dwarf_level < 5)
    dwarf_level = 5;
  if ((offsetT) num < 0 || (num != 0 && DWARF2_LINE_VERSION < 5))
    {
      as_bad (_("file number less than one"));
      ignore_rest_of_line ();
      return NULL;
    }

> @@ -1142,10 +1138,7 @@ dwarf2_directive_loc (int dummy ATTRIBUTE_UNUSED)
>    if (filenum < 1)
>      {
>        if (filenum != 0 || DWARF2_LINE_VERSION < 5)
> -	{
> -	  as_bad (_("file number less than one"));
> -	  return;
> -	}
> +	dwarf_level = 5;
>      }
>  
>    if (filenum >= (int) files_in_use || files[filenum].filename == NULL)

Similarly.

-- 
Alan Modra
Australia Development Lab, IBM

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

* V2 [PATCH] as: Automatically enable DWARF5 support
  2021-01-18  5:57     ` Alan Modra
@ 2021-01-18 13:36       ` H.J. Lu
  2021-01-18 14:23         ` H.J. Lu
  0 siblings, 1 reply; 10+ messages in thread
From: H.J. Lu @ 2021-01-18 13:36 UTC (permalink / raw)
  To: Alan Modra, Jakub Jelinek; +Cc: Fangrui Song, Mark Wielaard, Binutils

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

On Sun, Jan 17, 2021 at 9:57 PM Alan Modra <amodra@gmail.com> wrote:
>
> On Sun, Jan 17, 2021 at 08:00:25AM -0800, H.J. Lu via Binutils wrote:
> > How about this patch to automatically enable DWARF5 support?
>
> > diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
> > index a428370ecca..6c9871cb300 100644
> > --- a/gas/dwarf2dbg.c
> > +++ b/gas/dwarf2dbg.c
> > @@ -551,7 +551,7 @@ dwarf2_gen_line_info (addressT ofs, struct dwarf2_line_info *loc)
> >    if (loc->line == 0)
> >      return;
> >    if (loc->filenum == 0 && DWARF2_LINE_VERSION < 5)
> > -    return;
> > +    dwarf_level = 5;
> >
> >    /* Don't emit sequences of line symbols for the same line when the
> >       symbols apply to assembler code.  It is necessary to emit
>
> A target may override the default DWARF2_LINE_VERSION, so I think you
> should write something like
>
>   if (loc->filenum == 0 && dwarf_level < 5)
>     dwarf_level = 5;
>   if (loc->filenum == 0 && DWARF2_LINE_VERSION < 5)
>     return;

Fixed.

>
> > @@ -1043,11 +1043,7 @@ dwarf2_directive_filename (void)
> >    num = get_absolute_expression ();
> >
> >    if ((offsetT) num < 1 && DWARF2_LINE_VERSION < 5)
> > -    {
> > -      as_bad (_("file number less than one"));
> > -      ignore_rest_of_line ();
> > -      return NULL;
> > -    }
> > +    dwarf_level = 5;
> >
> >    /* FIXME: Should we allow ".file <N>\n" as an expression meaning
> >       "switch back to the already allocated file <N> as the current
>
> Similarly here, and in any case we shouldn't ignore a negative file
> number.  This should be

Fixed.

>   if (num == 0 && dwarf_level < 5)
>     dwarf_level = 5;
>   if ((offsetT) num < 0 || (num != 0 && DWARF2_LINE_VERSION < 5))
>     {
>       as_bad (_("file number less than one"));
>       ignore_rest_of_line ();
>       return NULL;
>     }
>
> > @@ -1142,10 +1138,7 @@ dwarf2_directive_loc (int dummy ATTRIBUTE_UNUSED)
> >    if (filenum < 1)
> >      {
> >        if (filenum != 0 || DWARF2_LINE_VERSION < 5)
> > -     {
> > -       as_bad (_("file number less than one"));
> > -       return;
> > -     }
> > +     dwarf_level = 5;
> >      }
> >
> >    if (filenum >= (int) files_in_use || files[filenum].filename == NULL)
>
> Similarly.
>

Fixed.

Here is the updated patch.   OK for master?

Thanks.

-- 
H.J.

[-- Attachment #2: 0001-as-Automatically-enable-DWARF5-support.patch --]
[-- Type: text/x-patch, Size: 3354 bytes --]

From 22361793ce115b899ca738dc8b9d9786e8005e8e Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Sat, 16 Jan 2021 20:42:27 -0800
Subject: [PATCH] as: Automatically enable DWARF5 support

Currently

$ as -o x.o x.s

fails when x.s contains DWARF5 ".file 0" or ".loc 0" directives.  Update
assembler to automatically enable DWARF5 support so that

$ gcc -S -g -c x.c
$ gcc -c x.s

works.

	PR gas/27195
	* dwarf2dbg.c (dwarf2_gen_line_info): Set dwarf_level to 5 if
	needed.
	(dwarf2_directive_filename): Likewise.
	(dwarf2_directive_loc): Likewise.
	* testsuite/gas/elf/dwarf-5-file0.d: Pass --gdwarf-3.
	* testsuite/gas/lns/lns-diag-1.l: Remove the
	"Error: file number less than one" errors.
---
 gas/dwarf2dbg.c                       | 24 ++++++++++++++++++------
 gas/testsuite/gas/elf/dwarf-5-file0.d |  2 +-
 gas/testsuite/gas/lns/lns-diag-1.l    |  2 --
 3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index a428370ecca..069f6316643 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -551,7 +551,11 @@ dwarf2_gen_line_info (addressT ofs, struct dwarf2_line_info *loc)
   if (loc->line == 0)
     return;
   if (loc->filenum == 0 && DWARF2_LINE_VERSION < 5)
-    return;
+    {
+      dwarf_level = 5;
+      if (DWARF2_LINE_VERSION < 5)
+	return;
+    }
 
   /* Don't emit sequences of line symbols for the same line when the
      symbols apply to assembler code.  It is necessary to emit
@@ -1044,9 +1048,13 @@ dwarf2_directive_filename (void)
 
   if ((offsetT) num < 1 && DWARF2_LINE_VERSION < 5)
     {
-      as_bad (_("file number less than one"));
-      ignore_rest_of_line ();
-      return NULL;
+      dwarf_level = 5;
+      if (DWARF2_LINE_VERSION < 5)
+	{
+	  as_bad (_("file number less than one"));
+	  ignore_rest_of_line ();
+	  return NULL;
+	}
     }
 
   /* FIXME: Should we allow ".file <N>\n" as an expression meaning
@@ -1143,8 +1151,12 @@ dwarf2_directive_loc (int dummy ATTRIBUTE_UNUSED)
     {
       if (filenum != 0 || DWARF2_LINE_VERSION < 5)
 	{
-	  as_bad (_("file number less than one"));
-	  return;
+	  dwarf_level = 5;
+	  if (DWARF2_LINE_VERSION < 5)
+	    {
+	      as_bad (_("file number less than one"));
+	      return;
+	    }
 	}
     }
 
diff --git a/gas/testsuite/gas/elf/dwarf-5-file0.d b/gas/testsuite/gas/elf/dwarf-5-file0.d
index 5d76b7bcd14..6cc96e3284f 100644
--- a/gas/testsuite/gas/elf/dwarf-5-file0.d
+++ b/gas/testsuite/gas/elf/dwarf-5-file0.d
@@ -1,4 +1,4 @@
-#as: --gdwarf-5
+#as: --gdwarf-3
 #name: DWARF5 .line 0
 #readelf: -wl
 
diff --git a/gas/testsuite/gas/lns/lns-diag-1.l b/gas/testsuite/gas/lns/lns-diag-1.l
index 1256e85cfcb..3d8a52f4d5b 100644
--- a/gas/testsuite/gas/lns/lns-diag-1.l
+++ b/gas/testsuite/gas/lns/lns-diag-1.l
@@ -1,5 +1,4 @@
 .*: Assembler messages:
-.*:2: Error: file number less than one
 .*:3: Error: missing string
 .*:4: Error: file table slot 1 is already occupied.*
 .*:8: Error: unassigned file number 3
@@ -9,7 +8,6 @@
 .*:19: Error: bad or irreducible absolute expression
 .*:23: Error: isa number less than zero
 .*:26: Error: bad or irreducible absolute expression
-.*:26: Error: file number less than one
 .*:27: Error: bad or irreducible absolute expression
 .*:28: Error: unknown .loc sub-directive `frobnitz'
 .*:29: Error: unknown .loc sub-directive `frobnitz'
-- 
2.29.2


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

* Re: V2 [PATCH] as: Automatically enable DWARF5 support
  2021-01-18 13:36       ` V2 " H.J. Lu
@ 2021-01-18 14:23         ` H.J. Lu
  2021-01-18 14:34           ` Nick Clifton
  2021-01-25 14:04           ` Florian Weimer
  0 siblings, 2 replies; 10+ messages in thread
From: H.J. Lu @ 2021-01-18 14:23 UTC (permalink / raw)
  To: Alan Modra, Jakub Jelinek; +Cc: Fangrui Song, Mark Wielaard, Binutils

On Mon, Jan 18, 2021 at 5:36 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Sun, Jan 17, 2021 at 9:57 PM Alan Modra <amodra@gmail.com> wrote:
> >
> > On Sun, Jan 17, 2021 at 08:00:25AM -0800, H.J. Lu via Binutils wrote:
> > > How about this patch to automatically enable DWARF5 support?
> >
> > > diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
> > > index a428370ecca..6c9871cb300 100644
> > > --- a/gas/dwarf2dbg.c
> > > +++ b/gas/dwarf2dbg.c
> > > @@ -551,7 +551,7 @@ dwarf2_gen_line_info (addressT ofs, struct dwarf2_line_info *loc)
> > >    if (loc->line == 0)
> > >      return;
> > >    if (loc->filenum == 0 && DWARF2_LINE_VERSION < 5)
> > > -    return;
> > > +    dwarf_level = 5;
> > >
> > >    /* Don't emit sequences of line symbols for the same line when the
> > >       symbols apply to assembler code.  It is necessary to emit
> >
> > A target may override the default DWARF2_LINE_VERSION, so I think you
> > should write something like
> >
> >   if (loc->filenum == 0 && dwarf_level < 5)
> >     dwarf_level = 5;
> >   if (loc->filenum == 0 && DWARF2_LINE_VERSION < 5)
> >     return;
>
> Fixed.
>
> >
> > > @@ -1043,11 +1043,7 @@ dwarf2_directive_filename (void)
> > >    num = get_absolute_expression ();
> > >
> > >    if ((offsetT) num < 1 && DWARF2_LINE_VERSION < 5)
> > > -    {
> > > -      as_bad (_("file number less than one"));
> > > -      ignore_rest_of_line ();
> > > -      return NULL;
> > > -    }
> > > +    dwarf_level = 5;
> > >
> > >    /* FIXME: Should we allow ".file <N>\n" as an expression meaning
> > >       "switch back to the already allocated file <N> as the current
> >
> > Similarly here, and in any case we shouldn't ignore a negative file
> > number.  This should be
>
> Fixed.
>
> >   if (num == 0 && dwarf_level < 5)
> >     dwarf_level = 5;
> >   if ((offsetT) num < 0 || (num != 0 && DWARF2_LINE_VERSION < 5))
> >     {
> >       as_bad (_("file number less than one"));
> >       ignore_rest_of_line ();
> >       return NULL;
> >     }
> >
> > > @@ -1142,10 +1138,7 @@ dwarf2_directive_loc (int dummy ATTRIBUTE_UNUSED)
> > >    if (filenum < 1)
> > >      {
> > >        if (filenum != 0 || DWARF2_LINE_VERSION < 5)
> > > -     {
> > > -       as_bad (_("file number less than one"));
> > > -       return;
> > > -     }
> > > +     dwarf_level = 5;
> > >      }
> > >
> > >    if (filenum >= (int) files_in_use || files[filenum].filename == NULL)
> >
> > Similarly.
> >
>
> Fixed.
>
> Here is the updated patch.   OK for master?
>

Nick approved my patch at

https://sourceware.org/bugzilla/show_bug.cgi?id=27195#c7

I am checking it in.  Is it OK to backport to 2.36 branch?

Thanks.

-- 
H.J.

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

* Re: V2 [PATCH] as: Automatically enable DWARF5 support
  2021-01-18 14:23         ` H.J. Lu
@ 2021-01-18 14:34           ` Nick Clifton
  2021-01-25 14:04           ` Florian Weimer
  1 sibling, 0 replies; 10+ messages in thread
From: Nick Clifton @ 2021-01-18 14:34 UTC (permalink / raw)
  To: H.J. Lu, Alan Modra, Jakub Jelinek; +Cc: Mark Wielaard, Binutils

Hi H.J.

> I am checking it in.  Is it OK to backport to 2.36 branch?

Yes, please do.

Cheers
   Nick



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

* Re: V2 [PATCH] as: Automatically enable DWARF5 support
  2021-01-18 14:23         ` H.J. Lu
  2021-01-18 14:34           ` Nick Clifton
@ 2021-01-25 14:04           ` Florian Weimer
  1 sibling, 0 replies; 10+ messages in thread
From: Florian Weimer @ 2021-01-25 14:04 UTC (permalink / raw)
  To: H.J. Lu via Binutils; +Cc: Alan Modra, Jakub Jelinek, H.J. Lu, Mark Wielaard

* H. J. Lu via Binutils:

> Nick approved my patch at
>
> https://sourceware.org/bugzilla/show_bug.cgi?id=27195#c7
>
> I am checking it in.  Is it OK to backport to 2.36 branch?

I think we need this on the 2.35 branch as well, otherwise glibc will
not enable --noexecstack on the architectures that need it, effectively
turning on an executable stack.  Maybe we also need to change the
configure check in glibc due to this bug.

Thanks,
Florian
-- 
Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill


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

end of thread, other threads:[~2021-01-25 14:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-17  4:48 [PATCH] as: Add a .dwarf_level directive to set the DWARF level H.J. Lu
2021-01-17  6:11 ` Fangrui Song
2021-01-17 16:00   ` [PATCH] as: Automatically enable DWARF5 support H.J. Lu
2021-01-17 18:56     ` Fangrui Song
2021-01-17 19:26       ` H.J. Lu
2021-01-18  5:57     ` Alan Modra
2021-01-18 13:36       ` V2 " H.J. Lu
2021-01-18 14:23         ` H.J. Lu
2021-01-18 14:34           ` Nick Clifton
2021-01-25 14:04           ` Florian Weimer

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).