https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98708
--- Comment #8 from Mark Wielaard <mark at gcc dot gnu.org> --- I am not sure where the -g -O2 -g0 comes from. I must have missed this in my testing. The issue is the .file 0 directive, which is special to gas (only valid with -gdwarf-5). It is generated by dwarf2out_finish (): /* Output the source line correspondence table. We must do this even if there is no line information. Otherwise, on an empty translation unit, we will generate a present, but empty, .debug_info section. IRIX 6.5 `nm' will then complain when examining the file. This is done late so that any filenames used by the debug_info section are marked as 'used'. */ switch_to_section (debug_line_section); 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); } So it looks like the asm_outputs_debug_line_str () is wrong: /* 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_N_FLAG) return !dwarf_split_debug_info && dwarf_version >= 5; #else return false; #endif } } It probably should check debug_info_level > DINFO_LEVEL_NONE.