]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PR 33029 segv in dwarf2_finish with --gdwarf-5
authorAlan Modra <amodra@gmail.com>
Wed, 28 May 2025 08:50:17 +0000 (18:20 +0930)
committerAlan Modra <amodra@gmail.com>
Wed, 28 May 2025 08:57:23 +0000 (18:27 +0930)
Specifying --gdwarf-5 with a source lacking a ".file 0" directive
results in this segfault.

* dwarf2dbg.c (out_debug_str): Use files[1] if files[0] is
empty regardless of dwarf level.

gas/dwarf2dbg.c

index fd1f96d80c50efd0bb0f29d8beeb7d373752ee36..a40fe6967d58b7d9ead68848f4a65bffad456c04 100644 (file)
@@ -3019,6 +3019,11 @@ out_debug_str (segT str_seg, symbolS **name_sym, symbolS **comp_dir_sym,
   int len;
   int first_file = DWARF2_LINE_VERSION > 4 ? 0 : 1;
 
+  if (files_in_use == 0)
+    abort ();
+  if (first_file == 0 && files[first_file].filename == NULL)
+    first_file = 1;
+
   subseg_set (str_seg, 0);
 
   /* DW_AT_name.  We don't have the actual file name that was present
@@ -3026,8 +3031,7 @@ out_debug_str (segT str_seg, symbolS **name_sym, symbolS **comp_dir_sym,
      We're not supposed to get called unless at least one line number
      entry was emitted, so this should always be defined.  */
   *name_sym = symbol_temp_new_now_octets ();
-  if (files_in_use == 0)
-    abort ();
+
   if (files[first_file].dir)
     {
       char *dirname = remap_debug_filename (dirs[files[first_file].dir]);