From 8728bc3d87b8e785689f234ac1f9b73fe6c1fdd1 Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Wed, 23 Mar 2022 08:48:02 +0100 Subject: [PATCH] gas/Dwarf5: adjust .debug_line file 0 checking First of all when a table entry has a NULL filename, the two inner if()s are better done the other way around: The 2nd doesn't depend on what the first does. This then renders redundant half of the conditions of the other if() and clarifies that subsequently only entry 0 is dealt with (indicating that part of the comment was wrong). Finally for there to be a usable name in slot 1, files_in_use needs to be larger than 1 and slot 1's (rather than slot 0's) name needs to be non-NULL. --- gas/dwarf2dbg.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c index c6778fe996a..c0a052df7d5 100644 --- a/gas/dwarf2dbg.c +++ b/gas/dwarf2dbg.c @@ -2271,11 +2271,15 @@ out_dir_and_file_list (segT line_seg, int sizeof_offset) if (files[i].filename == NULL) { - /* Prevent a crash later, particularly for file 1. DWARF5 - uses slot zero, but that is only set explicitly using a - .file 0 directive. If that isn't used, but file 1 is, - then use that as main file name. */ - if (DWARF2_LINE_VERSION >= 5 && i == 0 && files_in_use >= 1 && files[0].filename == NULL) + if (DWARF2_LINE_VERSION < 5 || i != 0) + { + as_bad (_("unassigned file number %ld"), (long) i); + continue; + } + /* DWARF5 uses slot zero, but that is only set explicitly using + a .file 0 directive. If that isn't used, but file 1 is, then + use that as main file name. */ + if (files_in_use > 1 && files[1].filename != NULL) { files[0].filename = files[1].filename; files[0].dir = files[1].dir; @@ -2284,12 +2288,7 @@ out_dir_and_file_list (segT line_seg, int sizeof_offset) files[0].md5[j] = files[1].md5[j]; } else - files[i].filename = ""; - if (DWARF2_LINE_VERSION < 5 || i != 0) - { - as_bad (_("unassigned file number %ld"), (long) i); - continue; - } + files[0].filename = ""; } fullfilename = DWARF2_FILE_NAME (files[i].filename, -- 2.30.2