From: Mark Wielaard Date: Wed, 3 Jul 2019 13:08:01 +0000 (+0000) Subject: PR debug/90981 Empty .debug_addr crashes -gdwarf-5 -gsplit-dwarf X-Git-Tag: upstream/12.2.0~23474 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6c47a87b661598cfba79925a6fdd1ebf7737bbdc;p=platform%2Fupstream%2Fgcc.git PR debug/90981 Empty .debug_addr crashes -gdwarf-5 -gsplit-dwarf Even if there was no, or an empty address list we would try to generate a header for the .debug_addr section with -gdwarf-5 and -gsplit-dwarf. The skeleton DIE would also get a (dangling) DW_AT_addr_base in that case. PR debug/90981 * dwarf2out.c (add_top_level_skeleton_die_attrs): Only add DW_AT_addr_base if there is actually a .debug_addr section with addresses. (output_addr_table): Add DWARF5 table header generation here after checking there are actually any addresses from... (dwarf2out_finish): ...here. * testsuite/g++.dg/pr90981.C: New test. From-SVN: r273008 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b3695cf..2152c2f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2019-07-03 Mark Wielaard + + PR debug/90981 + * dwarf2out.c (add_top_level_skeleton_die_attrs): Only add + DW_AT_addr_base if there is actually a .debug_addr section with + addresses. + (output_addr_table): Add DWARF5 table header generation here after + checking there are actually any addresses from... + (dwarf2out_finish): ...here. + * testsuite/g++.dg/pr90981.C: New test. + 2019-07-03 Richard Biener PR middle-end/91069 diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 6e82802..2c4cc6c 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -11196,7 +11196,8 @@ add_top_level_skeleton_die_attrs (dw_die_ref die) if (comp_dir != NULL) add_skeleton_AT_string (die, DW_AT_comp_dir, comp_dir); add_AT_pubnames (die); - add_AT_lineptr (die, dwarf_AT (DW_AT_addr_base), debug_addr_section_label); + if (addr_index_table != NULL && addr_index_table->size () > 0) + add_AT_lineptr (die, dwarf_AT (DW_AT_addr_base), debug_addr_section_label); } /* Output skeleton debug sections that point to the dwo file. */ @@ -29109,6 +29110,30 @@ output_addr_table (void) return; switch_to_section (debug_addr_section); + /* GNU DebugFission https://gcc.gnu.org/wiki/DebugFission + which GCC uses to implement -gsplit-dwarf as DWARF GNU extension + before DWARF5, didn't have a header for .debug_addr units. + DWARF5 specifies a small header when address tables are used. */ + if (dwarf_version >= 5) + { + unsigned int last_idx = 0; + unsigned long addrs_length; + + addr_index_table->traverse_noresize + (&last_idx); + addrs_length = last_idx * DWARF2_ADDR_SIZE + 4; + + if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4) + dw2_asm_output_data (4, 0xffffffff, + "Escape value for 64-bit DWARF extension"); + dw2_asm_output_data (DWARF_OFFSET_SIZE, addrs_length, + "Length of Address Unit"); + dw2_asm_output_data (2, 5, "DWARF addr version"); + dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address"); + dw2_asm_output_data (1, 0, "Size of Segment Descriptor"); + } + ASM_OUTPUT_LABEL (asm_out_file, debug_addr_section_label); + addr_index_table ->traverse_noresize (&index); } @@ -31631,30 +31656,6 @@ dwarf2out_finish (const char *filename) ranges_section_label); } - switch_to_section (debug_addr_section); - /* GNU DebugFission https://gcc.gnu.org/wiki/DebugFission - which GCC uses to implement -gsplit-dwarf as DWARF GNU extension - before DWARF5, didn't have a header for .debug_addr units. - DWARF5 specifies a small header when address tables are used. */ - if (dwarf_version >= 5) - { - unsigned int last_idx = 0; - unsigned long addrs_length; - - addr_index_table->traverse_noresize - (&last_idx); - addrs_length = last_idx * DWARF2_ADDR_SIZE + 4; - - if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4) - dw2_asm_output_data (4, 0xffffffff, - "Escape value for 64-bit DWARF extension"); - dw2_asm_output_data (DWARF_OFFSET_SIZE, addrs_length, - "Length of Address Unit"); - dw2_asm_output_data (2, 5, "DWARF addr version"); - dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address"); - dw2_asm_output_data (1, 0, "Size of Segment Descriptor"); - } - ASM_OUTPUT_LABEL (asm_out_file, debug_addr_section_label); output_addr_table (); } diff --git a/gcc/testsuite/g++.dg/pr90981.C b/gcc/testsuite/g++.dg/pr90981.C new file mode 100644 index 0000000..5a27302 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr90981.C @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -g -gdwarf-5 -gsplit-dwarf" } */ + +/* No addresses in the DWARF, so no .debug_addr section, + don't crash trying to generate an addr index header anyway. */ + +namespace { struct t {}; } +t f () { return t (); }