Hi, On Fri, 2020-09-18 at 17:21 +0200, Mark Wielaard wrote: > On Tue, 2020-09-15 at 20:40 +0200, Jakub Jelinek wrote: > > Ok, here it is in patch form. > > I've briefly tested it, with the older binutils I have around (no --gdwarf-N > > support), with latest gas (--gdwarf-N that can be passed to as even when > > compiling C/C++ etc. code and emitting .debug_line) and latest gas with > > Mark's fix > > reverted (--gdwarf-N support, but can only pass it to as when assembling > > user .s/.S files, not when compiling C/C++ etc.). > > Will bootstrap/regtest (with the older binutils) later tonight. > > > > 2020-09-15 Jakub Jelinek <ja...@redhat.com> > > > > * configure.ac (HAVE_AS_GDWARF_5_DEBUG_FLAG, > > HAVE_AS_WORKING_DWARF_4_FLAG): New tests. > > * gcc.c (ASM_DEBUG_DWARF_OPTION): Define. > > (ASM_DEBUG_SPEC): Use ASM_DEBUG_DWARF_OPTION instead of > > "--gdwarf2". Use %{cond:opt1;:opt2} style. > > (ASM_DEBUG_OPTION_DWARF_OPT): Define. > > (ASM_DEBUG_OPTION_SPEC): Define. > > (asm_debug_option): New variable. > > (asm_options): Add "%(asm_debug_option)". > > (static_specs): Add asm_debug_option entry. > > (static_spec_functions): Add dwarf-version-gt. > > (debug_level_greater_than_spec_func): New function. > > * config/darwin.h (ASM_DEBUG_OPTION_SPEC): Define. > > * config/darwin9.h (ASM_DEBUG_OPTION_SPEC): Redefine. > > * config.in: Regenerated. > > * configure: Regenerated. > > Once this is in we can more generally emit DW_FORM_line_str for > filepaths in CU DIEs for the name and comp_dir attribute. There > currently is a bit of a hack to do this in dwarf2out_early_finish, but > that only works when the assembler doesn't emit a DWARF5 .debug_line, > but gcc does it itself. > > What do you think of the attached patch? > > DWARF5 has a new string table specially for file paths. .debug_line > file and dir tables reference strings in .debug_line_str. If a > .debug_line_str section is emitted then also place CU DIE file > names and comp dirs there. > > gcc/ChangeLog: > > * dwarf2out.c (add_filepath_AT_string): New function. > (asm_outputs_debug_line_str): Likewise. > (add_filename_attribute): Likewise. > (add_comp_dir_attribute): Call add_filepath_AT_string. > (gen_compile_unit_die): Call add_filename_attribute for name. > (init_sections_and_labels): Init debug_line_str_section when > asm_outputs_debug_line_str return true. > (dwarf2out_early_finish): Remove DW_AT_name and DW_AT_comp_dir > hack and call add_filename_attribute for the remap_debug_filename.
On top of that, we also need the following, which makes sure the actual compilation directory is used in a DWARF5 .debug_line directory table (and not just a relative path).
From 66b25bc0a5df06e211b48a54e3b5d33999c24fb6 Mon Sep 17 00:00:00 2001 From: Mark Wielaard <m...@klomp.org> Date: Tue, 6 Oct 2020 17:41:19 +0200 Subject: [PATCH] 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. --- gcc/dwarf2out.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index a43082864a75..399937a9f310 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -31764,6 +31764,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) { -- 2.18.4