[binutils-gdb] PR 33029 segv in dwarf2_finish with --gdwarf-5

Alan Modra amodra@sourceware.org
Wed May 28 09:00:16 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f601ffb52199a883f16df385b73a14e756b3e19a

commit f601ffb52199a883f16df385b73a14e756b3e19a
Author: Alan Modra <amodra@gmail.com>
Date:   Wed May 28 18:20:17 2025 +0930

    PR 33029 segv in dwarf2_finish with --gdwarf-5
    
    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.

Diff:
---
 gas/dwarf2dbg.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index fd1f96d80c5..a40fe6967d5 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -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]);


More information about the Binutils-cvs mailing list