Re: [PATCH] debug: Pass --gdwarf-N to assembler if fixed gas is detected during configure
Hi, On Tue, 2020-10-06 at 16:57 -0400, Jason Merrill wrote: > All three of these patches (Jakub's, and your two) look good to me, > except that your add_filepath_AT_string patch is missing comments on > some of the new functions. I added documentation for the two new functions missing comments before pushing. Thanks, Mark
Re: [PATCH] debug: Pass --gdwarf-N to assembler if fixed gas is detected during configure
On 10/6/20 11:54 AM, Mark Wielaard wrote: 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 * 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). All three of these patches (Jakub's, and your two) look good to me, except that your add_filepath_AT_string patch is missing comments on some of the new functions. Jason
Re: [PATCH] debug: Pass --gdwarf-N to assembler if fixed gas is detected during configure
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 > > > > * 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 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
Re: [PATCH] debug: Pass --gdwarf-N to assembler if fixed gas is detected during configure
Hi, 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 > > * 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? From c31667db57de62c3107a0b2a5e30fbd57a4708a3 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Fri, 18 Sep 2020 17:07:03 +0200 Subject: [PATCH] Output filepath strings in .debug_line_str for DWARF5 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. --- gcc/dwarf2out.c | 96 - 1 file changed, 64 insertions(+), 32 deletions(-) diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 4096c0c0d69f..a43082864a75 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -3347,6 +3347,8 @@ output_asm_line_debug_info (void) || !debug_variable_location_views)); } +static bool asm_outputs_debug_line_str (void); + /* Minimum line offset in a special line info. opcode. This value was chosen to give a reasonable range of values. */ #define DWARF_LINE_BASE -10 @@ -4731,6 +4733,33 @@ reset_indirect_string (indirect_string_node **h, void *) return 1; } +static inline void +add_filepath_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, + const char *str) +{ + if (! asm_outputs_debug_line_str ()) +add_AT_string (die, attr_kind, str); + else +{ + dw_attr_node attr; + struct indirect_string_node *node; + + if (!debug_line_str_hash) + debug_line_str_hash + = hash_table::create_ggc (10); + + node = find_AT_string_in_table (str, debug_line_str_hash); + set_indirect_string (node); + node->form = DW_FORM_line_strp; + + attr.dw_attr = attr_kind; + attr.dw_attr_val.val_class = dw_val_class_str; + attr.dw_attr_val.val_entry = NULL; + attr.dw_attr_val.v.val_str = node; + add_dwarf_attr (die, ); +} +} + /* Find out whether a string should be output inline in DIE or out-of-line in .debug_str section. */ @@ -11839,6 +11868,29 @@ output_ranges (void) for -gsplit-dwarf we should use DW_FORM_strx instead. */ \ && !dwarf_split_debug_info) + +/* Returns TRUE if we are outputting DWARF5 and the assembler supports + DWARF5 .debug_line tables using .debug_line_str or we generate + it ourselves, except for split-dwarf which doesn't have a + .debug_line_str. */ +static bool +asm_outputs_debug_line_str (void) +{ + if (dwarf_version >= 5 + && ! output_asm_line_debug_info () + && DWARF5_USE_DEBUG_LINE_STR) +return true; + else +{ +#if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_4_FLAG) + return !dwarf_split_debug_info && dwarf_version >= 5; +#else + return false; +#endif +} +} + + /* Assign .debug_rnglists indexes. */ static void @@ -20514,6 +20566,13 @@ add_name_attribute
Re: [PATCH] debug: Pass --gdwarf-N to assembler if fixed gas is detected during configure
On Wed, Sep 16, 2020 at 02:33:03PM +0200, Mark Wielaard wrote: > > 2020-09-15 Jakub Jelinek > > > > * 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. > > I tested against the binutils-2_35-branch which will become 2.35.1 next > week. The configure tests succeed there. So I think you can change the > [elf,2,36,0] to [elf,2,35,1]. No problem with such a change, although it isn't that important, because most of the people don't use in-tree builds and for out of tree builds the actual test rather than version comparison is used instead. Jakub
Re: [PATCH] debug: Pass --gdwarf-N to assembler if fixed gas is detected during configure
Hi, 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 > > * 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. I tested against the binutils-2_35-branch which will become 2.35.1 next week. The configure tests succeed there. So I think you can change the [elf,2,36,0] to [elf,2,35,1]. Also tested that they fail with an older binutils (2.32). Cheers, Mark
[PATCH] debug: Pass --gdwarf-N to assembler if fixed gas is detected during configure
On Thu, Sep 10, 2020 at 01:45:50PM +0200, Jakub Jelinek wrote: > On Thu, Sep 10, 2020 at 01:16:57PM +0200, Jakub Jelinek via Gcc-patches wrote: > > As for the test assembly, I'd say we should take > > #define F void foo (void) {} > > F > > compile it with > > gcc -S -O2 -g1 -dA -gno-as-loc-support -fno-merge-debug-strings > > remove .cfi_* directives, remove the ret instruction, change @function > > and @progbits to %function and %progbits, change .uleb128 to just .byte, > > I think all the values should be small enough, maybe change .value to > > .2byte and .long to .4byte (whatever is most portable across different > > arches and gas versions), simplify (shorten) strings and adjust > > sizes, and do something with the .quad directives, that is dependent on > > the address size, perhaps just take those attributes out and adjust > > .debug_abbrev? Finally, remove all comments (emit them in the first case > > just to better understand the debug info). > > I'm afraid it is hard to avoid the .quad or .8byte. > Here is a 64-bit address version that assembles fine by both x86_64 and > aarch64 as. > Unfortunately doesn't fail with broken gas versions with -gdwarf-2 without > the nop, so we'll need at least a nop in there. > Fortunately gcc/configure.ac already determines the right nop insn for the > target, in $insn. > So I guess what we want next is have the 32-bit version of this with .4byte > instead of .8byte and just let's try to assemble both versions, first > without -gdwarf-2 and the one that succeeds assemble again with -gdwarf-2 > and check for the duplicate .debug_line sections error. > What do you think? 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 * 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. --- gcc/configure.ac.jj 2020-09-08 16:48:32.377900856 +0200 +++ gcc/configure.ac2020-09-15 18:07:23.292249972 +0200 @@ -5192,6 +5192,194 @@ if test x"$insn" != x; then [AC_DEFINE(HAVE_AS_GDWARF2_DEBUG_FLAG, 1, [Define if your assembler supports the --gdwarf2 option.])]) + gcc_GAS_CHECK_FEATURE([--gdwarf-5 option], + gcc_cv_as_gdwarf_5_flag, + [elf,2,36,0], [--gdwarf-5], [$insn],, + [AC_DEFINE(HAVE_AS_GDWARF_5_DEBUG_FLAG, 1, +[Define if your assembler supports the --gdwarf-5 option.])]) + + dwarf4_debug_info_size=0x46 + dwarf4_high_pc_form=7 + dwarf4_debug_aranges_size=0x2c + dwarf4_line_sz=9 + for dwarf4_addr_size in 8 4; do + conftest_s="\ + .file \"a.c\" + .text +.Ltext0: + .p2align 4 + .globl foo + .type foo, %function +foo: +.LFB0: +.LM1: + $insn +.LM2: +.LFE0: + .size foo, .-foo +.Letext0: + .section.debug_info,\"\",%progbits +.Ldebug_info0: + .4byte $dwarf4_debug_info_size + .2byte 0x4 + .4byte .Ldebug_abbrev0 + .byte 0x$dwarf4_addr_size + .byte 0x1 + .ascii \"GNU C17\\0\" + .byte 0xc + .ascii \"a.c\\0\" + .ascii \"/\\0\" + .${dwarf4_addr_size}byte.Ltext0 + .${dwarf4_addr_size}byte.Letext0-.Ltext0 + .4byte .Ldebug_line0 + .byte 0x2 + .ascii \"foo\\0\" + .byte 0x1 + .byte 0x2 + .byte 0x1 + .${dwarf4_addr_size}byte.LFB0 + .${dwarf4_addr_size}byte.LFE0-.LFB0 + .byte 0x1 + .byte 0x9c + .byte 0 + .section.debug_abbrev,\"\",%progbits +.Ldebug_abbrev0: + .byte 0x1 + .byte 0x11 + .byte 0x1 + .byte 0x25 + .byte 0x8 + .byte 0x13 + .byte 0xb + .byte 0x3 + .byte 0x8 + .byte 0x1b + .byte 0x8 + .byte 0x11 + .byte 0x1 + .byte 0x12 + .byte 0x$dwarf4_high_pc_form + .byte 0x10 + .byte 0x17 + .byte 0 + .byte 0 + .byte