[gcc r11-3733] debug: Make sure to output .file 0 when generating DWARF5.

Mark Wielaard mark@gcc.gnu.org
Thu Oct 8 15:19:58 GMT 2020


https://gcc.gnu.org/g:3a9e6ee42acf1e3d00e4391ab1b1a56bb0b32ad2

commit r11-3733-g3a9e6ee42acf1e3d00e4391ab1b1a56bb0b32ad2
Author: Mark Wielaard <mark@klomp.org>
Date:   Tue Oct 6 17:41:19 2020 +0200

    debug: Make sure to output .file 0 when generating DWARF5.
    
    When gas outputs DWARF5 .debug_line[_str] then we have to tell it the
    comp_dir and main file name for the zero entry line table. Otherwise
    gas has to guess at the CU compilation directory and file.
    
    Before a gcc -gdwarf-5 ../src/hello.c line table looked like:
    
    Directory table:
     0     ../src (24)
     1     ../src (24)
     2     /usr/include (31)
    
    File name table:
     0     hello.c (16),  0
     1     hello.c (16),  1
     2     stdio.h (44),  2
    
    With this patch it looks like:
    
    Directory table:
     0     /tmp/obj (0)
     1     ../src (24)
     2     /usr/include (31)
    
    File name table:
     0     ../src/hello.c (9),  0
     1     hello.c (16),  1
     2     stdio.h (44),  2
    
    gcc/ChangeLog:
    
            * dwarf2out.c (dwarf2out_finish): Emit .file 0 entry when
            generating DWARF5 .debug_line table through gas.

Diff:
---
 gcc/dwarf2out.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 30367443ad6..ba93a6c3d81 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -31768,6 +31768,27 @@ dwarf2out_finish (const char *filename)
   ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
   if (! output_asm_line_debug_info ())
     output_line_info (false);
+  else if (asm_outputs_debug_line_str ())
+    {
+      /* When gas outputs DWARF5 .debug_line[_str] then we have to
+	 tell it the comp_dir and main file name for the zero entry
+	 line table.  */
+      const char *comp_dir, *filename0;
+
+      comp_dir = comp_dir_string ();
+      if (comp_dir == NULL)
+	comp_dir = "";
+
+      filename0 = get_AT_string (comp_unit_die (), DW_AT_name);
+      if (filename0 == NULL)
+	filename0 = "";
+
+      fprintf (asm_out_file, "\t.file 0 ");
+      output_quoted_string (asm_out_file, remap_debug_filename (comp_dir));
+      fputc (' ', asm_out_file);
+      output_quoted_string (asm_out_file, remap_debug_filename (filename0));
+      fputc ('\n', asm_out_file);
+    }
 
   if (dwarf_split_debug_info && info_section_emitted)
     {


More information about the Gcc-cvs mailing list