public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Bernd Edlinger <bernd.edlinger@hotmail.de>
To: Richard Biener <rguenther@suse.de>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
	Eric Botcazou <ebotcazou@libertysurf.fr>,
	Arnaud Charlet <charlet@adacore.com>
Subject: Re: [PATCH 1/2] Fix debug info for ignored decls at start of assembly
Date: Fri, 30 Jul 2021 13:09:05 +0200	[thread overview]
Message-ID: <AM8PR10MB4708B38ECDACBEB57AF9002AE4EC9@AM8PR10MB4708.EURPRD10.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <nycvar.YFH.7.76.2107290922390.31669@zhemvz.fhfr.qr>

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



On 7/29/21 9:23 AM, Richard Biener wrote:
> On Wed, 28 Jul 2021, Bernd Edlinger wrote:
> 
>> On 7/28/21 2:51 PM, Richard Biener wrote:
>>> On Mon, 26 Jul 2021, Bernd Edlinger wrote:
>>>
>>>> Ignored functions decls that are compiled at the start of
>>>> the assembly have bogus line numbers until the first .file
>>>> directive, as reported in PR101575.
>>>>
>>>> The work around for this issue is to emit a dummy .file
>>>> directive when the first function is DECL_IGNORED_P, when
>>>> that is not already done, mostly for -fdwarf-4.
>>>
>>> I wonder if it makes sense to unconditionally announce the
>>> TU with a .file directive at the beginning.  ISTR this is
>>> what we now do with -gdwarf-5.
>>>
>>
>> Yes, that would work, even when the file name is not guessed
>> correctly.
>>
>> Initially I had "<dummy>" unconditionally here, and it did
>> not really hurt, except that it is visible with readelf.
> 
> I think I'd prefer that, since if we don't announce a .file
> before the first assembler statement but ask gas to produce
> line info it might be tempted to create line info referencing
> the possibly temporary filename of the assembler file which
> is undesirable from a build reproducability point.
> 

Yeah, I understand.

Meanwhile I found a simple C test case without ignored functions

$ cat test1.c
asm("nop");
int main () 
{
  return 0;
}

$ gcc -g test1.c
$ readelf --debug-dump=decodedline a.out 
Contents of the .debug_line section:

CU: ./test1.c:
File name                            Line number    Starting address    View    Stmt
test1.c                                        5            0x401106               x
test1.c                                        3            0x401107               x
test1.c                                        4            0x40110b               x
test1.c                                        5            0x401110               x
test1.c                                        -            0x401112

even with the proposed patch, so I agree it is incomplete.

I tried the gdb test case and compile it with different LTO
options, but the gen_AT_string was always valid, in some
cases a lto debug section together with a couple .file <n>
directives was output before the .file 0.
So I'd like to use the file name from gen_AT_string, since
it's most of the time accurate, and avoids unnecessary confusion
on the readers of the produced debug info.

So I'd propose the attached patch instead.
Is it OK for trunk?


> Richard.
> 
>>> Note get_AT_string (comp_unit_die (), DW_AT_name) doesn't
>>> work with LTO, you'll get <dummy> then.
>>>
>>
>> Yeah, that's why I wanted to restrict that to the case where
>> it's absolutely necessary.
>>
>>> Is the dwarf assembler bug reported/fixed?  Can you include
>>> a reference please?
>>>
>>
>> I've just added a bug report, it's unlikely to be fixed IMHO:
>> https://sourceware.org/bugzilla/show_bug.cgi?id=28149
>>
>> I will add that to the patch description:
>>
>> Ignored functions decls that are compiled at the start of
>> the assembly have bogus line numbers until the first .file
>> directive, as reported in PR101575.
>>
>> The corresponding binutils bug report is
>> https://sourceware.org/bugzilla/show_bug.cgi?id=28149
>>
>> The work around for this issue is to emit a dummy .file
>> directive when the first function is DECL_IGNORED_P, when
>> that is not already done, mostly for -fdwarf-4.
>>
>>
>> Thanks
>> Bernd.
>>
>>> Thanks,
>>> Richard.
>>>
>>>> 2021-07-24  Bernd Edlinger  <bernd.edlinger@hotmail.de>
>>>>
>>>> 	PR ada/101575
>>>> 	* dwarf2out.c (dwarf2out_begin_prologue): Move init
>>>> 	of fde->ignored_debug to dwarf2out_set_ignored_loc.
>>>> 	(dwarf2out_set_ignored_loc): This is now also called
>>>> 	when no .loc statement is to be generated, in that case
>>>> 	we emit a dummy .file statement when needed.
>>>> 	* final.c (final_start_function_1,
>>>> 	final_scan_insn_1): Call debug_hooks->set_ignored_loc
>>>> 	for all DECL_IGNORED_P functions.
>>>> ---
>>>>  gcc/dwarf2out.c | 29 +++++++++++++++++++++++++----
>>>>  gcc/final.c     |  5 ++---
>>>>  2 files changed, 27 insertions(+), 7 deletions(-)
>>>>
>>>> diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
>>>> index 884f1e1..8de0d6f 100644
>>>> --- a/gcc/dwarf2out.c
>>>> +++ b/gcc/dwarf2out.c
>>>> @@ -1115,7 +1115,6 @@ dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
>>>>    fde->dw_fde_current_label = dup_label;
>>>>    fde->in_std_section = (fnsec == text_section
>>>>  			 || (cold_text_section && fnsec == cold_text_section));
>>>> -  fde->ignored_debug = DECL_IGNORED_P (current_function_decl);
>>>>    in_text_section_p = fnsec == text_section;
>>>>  
>>>>    /* We only want to output line number information for the genuine dwarf2
>>>> @@ -28546,10 +28545,32 @@ dwarf2out_set_ignored_loc (unsigned int line, unsigned int column,
>>>>  {
>>>>    dw_fde_ref fde = cfun->fde;
>>>>  
>>>> -  fde->ignored_debug = false;
>>>> -  set_cur_line_info_table (function_section (fde->decl));
>>>> +  if (filename)
>>>> +    {
>>>> +      set_cur_line_info_table (function_section (fde->decl));
>>>> +
>>>> +      dwarf2out_source_line (line, column, filename, 0, true);
>>>> +    }
>>>> +  else
>>>> +    {
>>>> +      fde->ignored_debug = true;
>>>> +
>>>> +      /* Work around for PR101575: output a dummy .file directive.  */
>>>> +      if (in_first_function_p
>>>> +	  && debug_info_level >= DINFO_LEVEL_TERSE
>>>> +	  && dwarf_debuginfo_p ()
>>>> +#if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG)
>>>> +	  && dwarf_version <= 4
>>>> +#endif
>>>> +	  && output_asm_line_debug_info ())
>>>> +	{
>>>> +	  const char *filename0 = get_AT_string (comp_unit_die (), DW_AT_name);
>>>>  
>>>> -  dwarf2out_source_line (line, column, filename, 0, true);
>>>> +	  if (filename0 == NULL)
>>>> +	    filename0 = "<dummy>";
>>>> +	  maybe_emit_file (lookup_filename (filename0));
>>>> +	}
>>>> +    }
>>>>  }
>>>>  
>>>>  /* Record the beginning of a new source file.  */
>>>> diff --git a/gcc/final.c b/gcc/final.c
>>>> index ac6892d..82a5767 100644
>>>> --- a/gcc/final.c
>>>> +++ b/gcc/final.c
>>>> @@ -1725,7 +1725,7 @@ final_start_function_1 (rtx_insn **firstp, FILE *file, int *seen,
>>>>    if (!dwarf2_debug_info_emitted_p (current_function_decl))
>>>>      dwarf2out_begin_prologue (0, 0, NULL);
>>>>  
>>>> -  if (DECL_IGNORED_P (current_function_decl) && last_linenum && last_filename)
>>>> +  if (DECL_IGNORED_P (current_function_decl))
>>>>      debug_hooks->set_ignored_loc (last_linenum, last_columnnum, last_filename);
>>>>  
>>>>  #ifdef LEAF_REG_REMAP
>>>> @@ -2205,8 +2205,7 @@ final_scan_insn_1 (rtx_insn *insn, FILE *file, int optimize_p ATTRIBUTE_UNUSED,
>>>>  	    }
>>>>  	  else if (!DECL_IGNORED_P (current_function_decl))
>>>>  	    debug_hooks->switch_text_section ();
>>>> -	  if (DECL_IGNORED_P (current_function_decl) && last_linenum
>>>> -	      && last_filename)
>>>> +	  if (DECL_IGNORED_P (current_function_decl))
>>>>  	    debug_hooks->set_ignored_loc (last_linenum, last_columnnum,
>>>>  					  last_filename);
>>>>  
>>>>
>>>
>>
> 

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-debug-info-for-ignored-decls-at-start-of-assembl.patch --]
[-- Type: text/x-patch; name="0001-Fix-debug-info-for-ignored-decls-at-start-of-assembl.patch", Size: 1641 bytes --]

From dec4be8f3e9e1e7430e5c65d6aaa13526ebc77e2 Mon Sep 17 00:00:00 2001
From: Bernd Edlinger <bernd.edlinger@hotmail.de>
Date: Sat, 24 Jul 2021 12:53:39 +0200
Subject: [PATCH 1/2] Fix debug info for ignored decls at start of assembly

Ignored functions decls that are compiled at the start of
the assembly have bogus line numbers until the first .file
directive, as reported in PR101575.

The corresponding binutils bug report is
https://sourceware.org/bugzilla/show_bug.cgi?id=28149

The work around for this issue is to emit a dummy .file
directive before the first function is compiled, unless
another .file directive was already emitted previously.

2021-07-24  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	PR ada/101575
	* dwarf2out.c (dwarf2out_assembly_start): Emit a dummy
	.file statement when needed.
---
 gcc/dwarf2out.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 884f1e1..b91a9b5 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -29389,7 +29389,18 @@ dwarf2out_assembly_start (void)
       output_quoted_string (asm_out_file, remap_debug_filename (filename0));
       fputc ('\n', asm_out_file);
     }
+  else
 #endif
+  /* Work around for PR101575: output a dummy .file directive.  */
+  if (!last_emitted_file && dwarf_debuginfo_p ()
+      && debug_info_level >= DINFO_LEVEL_TERSE)
+    {
+      const char *filename0 = get_AT_string (comp_unit_die (), DW_AT_name);
+
+      if (filename0 == NULL)
+	filename0 = "<dummy>";
+      maybe_emit_file (lookup_filename (filename0));
+    }
 }
 
 /* A helper function for dwarf2out_finish called through
-- 
1.9.1


  reply	other threads:[~2021-07-30 11:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-26 16:45 Bernd Edlinger
2021-07-28 12:51 ` Richard Biener
2021-07-28 15:26   ` Bernd Edlinger
2021-07-29  7:23     ` Richard Biener
2021-07-30 11:09       ` Bernd Edlinger [this message]
2021-08-02 13:31         ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AM8PR10MB4708B38ECDACBEB57AF9002AE4EC9@AM8PR10MB4708.EURPRD10.PROD.OUTLOOK.COM \
    --to=bernd.edlinger@hotmail.de \
    --cc=charlet@adacore.com \
    --cc=ebotcazou@libertysurf.fr \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=rguenther@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).