public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Re: [PATCH] gas: Don't error when .debug_line already exists, unless .loc was used
@ 2020-09-11 12:47 Nick Clifton
  2020-09-11 13:51 ` H.J. Lu
  0 siblings, 1 reply; 11+ messages in thread
From: Nick Clifton @ 2020-09-11 12:47 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: binutils

Hi Mark,

> The tests are unfortunately arch specific because the line table is only
> generated when actual instructions have been emitted.

Are you sure about that ?  How about using the NOP instruction ?

I admit that some architectures do need special syntax for their
nop instructions, but there is already a test in gas testsuite
that handles this (see gas/testsuite/gas/all/gas.exp:org-1).  The
nop-selecting code there could probably be extracted into a library
function then used in lots of places...

Cheers
  Nick


^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: [PATCH] gas: Don't error when .debug_line already exists, unless .loc was used
@ 2020-09-11 15:45 Nick Clifton
  2020-09-11 18:34 ` Mark Wielaard
  0 siblings, 1 reply; 11+ messages in thread
From: Nick Clifton @ 2020-09-11 15:45 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: binutils

Hi Mark,

> gas/ChangeLog:
> 
>     * as.texi (-g): Explicitly mention when .debug_info and .debug_line
>     are generated for the DWARF format.
>     (Loc): Add that it is an error to both use a .loc directive and
>     generate a .debug_line yourself.
>     * dwarf2dbg.c (dwarf2_any_loc_directive_seen): New static variable.
>     (dwarf2_directive_loc): Set dwarf2_any_loc_directive_seen to TRUE.
>     (dwarf2_finish): Check dwarf2_any_loc_directive_seen before emitting
>     an error. Only create .debug_line if it is empty (or doesn't exist).
>     * testsuite/gas/i386/i386.exp: Add dwarf2-line-{1,2,3,4} when testing
>     an elf target.
>     * testsuite/gas/i386/dwarf2-line-{1,2,3,4}.{s,d,l}: New test files.

Approved - please apply.

If you are feeling keen, then do please have a go at creating a generic
testcase.  If not, then I will make one myself soon.

Cheers
  Nick


^ permalink raw reply	[flat|nested] 11+ messages in thread
* Duplicate .debug_lines (Was: [PATCH 5/5] Add --gdwarf-5 to ASM_SPEC)
@ 2020-08-26 21:37 Mark Wielaard
  2020-09-07 12:37 ` [PATCH] gas: Don't error when .debug_line already exists, unless .loc was used Mark Wielaard
  0 siblings, 1 reply; 11+ messages in thread
From: Mark Wielaard @ 2020-08-26 21:37 UTC (permalink / raw)
  To: gcc-patches; +Cc: binutils, nickc, jakub

Hi gcc hackers, binutils hackers,

Nick, Jakub and I were discussing the gcc patch below and all the ways
it is wrong. Most things can be fixed in the spec. Like only passing
-gdwarf if we are generating DWARF and passing the right DWARF version
as -gdwarf-N for the version that gcc itself creates. But whether or
not we want gas to generate .debug_line info is a bit tricky. But when
giving -gdwarf-N gas will always try to generate a .debug_line section
and error out when there is already one.

Would it be possible to have something like the following in gas, so
that it doesn't try generating a .debug_line section if there already
is one, even when -gdwarf-N is given (unless the assembly also
contains .loc directives because that shows the user is really
confused)?

diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index e4ba56d82ba..c0c09f4e9d0 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -2626,7 +2626,7 @@ 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
+   were any .file/.loc directives, or --gdwarf2 was given, and 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.
@@ -2650,9 +2650,16 @@ dwarf2_finish (void)
   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.  */
+     Give an error if we have seen any .loc, otherwise trust the user
+     knows what they are doing and want to generate the .debug_line
+     (and all other debug sections) themselves.  */
   if (all_segs && !empty_debug_line)
-    as_fatal ("duplicate .debug_line sections");
+    {
+      if (dwarf2_loc_directive_seen)
+	as_fatal ("duplicate .debug_line sections");
+      else
+	return;
+    }
 
   if ((!all_segs && emit_other_sections)
       || (!emit_other_sections && !empty_debug_line))

On Mon, Aug 24, 2020 at 02:56:58PM +0200, Mark Wielaard wrote:
> This is needed to get DWARF version 5 .debug_line tables.
> It is also obviously wrong. It needs a check for whether as supports
> --gdwarf-<version> for all versions we support and it should only
> be added when generating DWARF debug information for the specific
> DWARF version we are generating.
> 
> It also needs some fixes to binutils, to make sure the line table is
> generated correctly:
> https://sourceware.org/pipermail/binutils/2020-August/112685.html
> And to make sure it can read the generated line table itself:
> https://sourceware.org/pipermail/binutils/2020-August/112966.html
> ---
>  gcc/gcc.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/gcc/gcc.c b/gcc/gcc.c
> index 10bc9881aed3..98b10e7cd154 100644
> --- a/gcc/gcc.c
> +++ b/gcc/gcc.c
> @@ -1882,6 +1882,11 @@ init_spec (void)
>    }
>  #endif
>  
> +  static const char dv[] = "--gdwarf-5 ";
> +  obstack_grow (&obstack, dv, sizeof (dv) - 1);
> +  obstack_grow0 (&obstack, asm_spec, strlen (asm_spec));
> +  asm_spec = XOBFINISH (&obstack, const char *);
> +
>  #if defined LINK_EH_SPEC || defined LINK_BUILDID_SPEC || \
>      defined LINKER_HASH_STYLE
>  # ifdef LINK_BUILDID_SPEC
> -- 
> 2.18.4
> 

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

end of thread, other threads:[~2020-09-14 22:44 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-11 12:47 [PATCH] gas: Don't error when .debug_line already exists, unless .loc was used Nick Clifton
2020-09-11 13:51 ` H.J. Lu
2020-09-11 15:40   ` Nick Clifton
2020-09-11 15:46   ` Mark Wielaard
2020-09-11 15:56     ` Nick Clifton
2020-09-14 15:17     ` Nick Clifton
  -- strict thread matches above, loose matches on Subject: below --
2020-09-11 15:45 Nick Clifton
2020-09-11 18:34 ` Mark Wielaard
2020-09-14  9:45   ` Nick Clifton
2020-09-14 22:43     ` Mark Wielaard
2020-08-26 21:37 Duplicate .debug_lines (Was: [PATCH 5/5] Add --gdwarf-5 to ASM_SPEC) Mark Wielaard
2020-09-07 12:37 ` [PATCH] gas: Don't error when .debug_line already exists, unless .loc was used Mark Wielaard

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