+2021-01-18  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR gas/27195
+       * dwarf2dbg.c (dwarf2_gen_line_info): Set dwarf_level to 5 if
+       needed.
+       (dwarf2_directive_filename): Likewise.
+       (dwarf2_directive_loc): Likewise.
+       * testsuite/gas/elf/dwarf-5-file0.d: Pass --gdwarf-3.
+       * testsuite/gas/lns/lns-diag-1.l: Remove the
+       "Error: file number less than one" errors.
+
 2021-01-18  Alan Modra  <amodra@gmail.com>
 
        PR 27198
 
   if (loc->line == 0)
     return;
   if (loc->filenum == 0 && DWARF2_LINE_VERSION < 5)
-    return;
+    {
+      dwarf_level = 5;
+      if (DWARF2_LINE_VERSION < 5)
+       return;
+    }
 
   /* Don't emit sequences of line symbols for the same line when the
      symbols apply to assembler code.  It is necessary to emit
 
   if ((offsetT) num < 1 && DWARF2_LINE_VERSION < 5)
     {
-      as_bad (_("file number less than one"));
-      ignore_rest_of_line ();
-      return NULL;
+      dwarf_level = 5;
+      if (DWARF2_LINE_VERSION < 5)
+       {
+         as_bad (_("file number less than one"));
+         ignore_rest_of_line ();
+         return NULL;
+       }
     }
 
   /* FIXME: Should we allow ".file <N>\n" as an expression meaning
     {
       if (filenum != 0 || DWARF2_LINE_VERSION < 5)
        {
-         as_bad (_("file number less than one"));
-         return;
+         dwarf_level = 5;
+         if (DWARF2_LINE_VERSION < 5)
+           {
+             as_bad (_("file number less than one"));
+             return;
+           }
        }
     }
 
 
-#as: --gdwarf-5
+#as: --gdwarf-3
 #name: DWARF5 .line 0
 #readelf: -wl
 
 
 .*: Assembler messages:
-.*:2: Error: file number less than one
 .*:3: Error: missing string
 .*:4: Error: file table slot 1 is already occupied.*
 .*:8: Error: unassigned file number 3
 .*:19: Error: bad or irreducible absolute expression
 .*:23: Error: isa number less than zero
 .*:26: Error: bad or irreducible absolute expression
-.*:26: Error: file number less than one
 .*:27: Error: bad or irreducible absolute expression
 .*:28: Error: unknown .loc sub-directive `frobnitz'
 .*:29: Error: unknown .loc sub-directive `frobnitz'