Hi! During work on dwz I've discovered wrong -g3 debug info emitted e.g. for Ada sources. While DW_AT_macro_info can point to just '\0' termination of .debug_macinfo section (but it is IMHO pointless, I don't see what distinction between -g2 and -g3 if no content of macinfo is provided would be good for), DW_AT_GNU_macros certainly shouldn't point to that, because there is no header emitted in that case.
Fixed by acting as if -g3 wasn't specified if macinfo/macro section would be empty. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.7? 2012-05-14 Jakub Jelinek <ja...@redhat.com> * dwarf2out.c (dwarf2out_finish): Don't emit DW_AT_GNU_macros or DW_AT_macro_info attribute, don't force empty compilation unit and don't emit any .debug_macinfo/.debug_macro section if macinfo_table is empty. --- gcc/dwarf2out.c.jj 2012-05-12 10:21:06.000000000 +0200 +++ gcc/dwarf2out.c 2012-05-14 10:34:18.301813673 +0200 @@ -22145,7 +22145,8 @@ dwarf2out_finish (const char *filename) add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list, debug_line_section_label); - if (debug_info_level >= DINFO_LEVEL_VERBOSE) + if (debug_info_level >= DINFO_LEVEL_VERBOSE + && !VEC_empty (macinfo_entry, macinfo_table)) add_AT_macptr (comp_unit_die (), dwarf_strict ? DW_AT_macro_info : DW_AT_GNU_macros, macinfo_section_label); @@ -22180,8 +22181,10 @@ dwarf2out_finish (const char *filename) htab_delete (comdat_type_table); /* Output the main compilation unit if non-empty or if .debug_macinfo - will be emitted. */ - output_comp_unit (comp_unit_die (), debug_info_level >= DINFO_LEVEL_VERBOSE); + or .debug_macro will be emitted. */ + output_comp_unit (comp_unit_die (), + debug_info_level >= DINFO_LEVEL_VERBOSE + && !VEC_empty (macinfo_entry, macinfo_table)); /* Output the abbreviation table. */ if (abbrev_die_table_in_use != 1) @@ -22261,12 +22264,12 @@ dwarf2out_finish (const char *filename) } /* Have to end the macro section. */ - if (debug_info_level >= DINFO_LEVEL_VERBOSE) + if (debug_info_level >= DINFO_LEVEL_VERBOSE + && !VEC_empty (macinfo_entry, macinfo_table)) { switch_to_section (debug_macinfo_section); ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label); - if (!VEC_empty (macinfo_entry, macinfo_table)) - output_macinfo (); + output_macinfo (); dw2_asm_output_data (1, 0, "End compilation unit"); } Jakub