public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: bfd/dwarf2.c: allow use of DWARF5 directory entry 0
Date: Mon, 26 Dec 2022 22:56:36 +1030	[thread overview]
Message-ID: <Y6mS/HVlwxWvjyo9@squeak.grove.modra.org> (raw)

I think the test for table->files[file].dir being non-zero is wrong
for DWARF5 where index zero is allowed and is the current directory of
the compilation.  Most times this will be covered by the use of
table->comp_dir (from DW_AT_comp_dir) in concat_filename but the point
of putting the current dir in .debug_line was so the section could
stand alone without .debug_info.

Also, there is no need to check for table->dirs non-NULL, the
table->num_dirs test is sufficient.

	* dwarf2.c (concat_filename): Correct and simplify tests of
	directory index.

diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c
index 88335cb4fb0..a207665bbfa 100644
--- a/bfd/dwarf2.c
+++ b/bfd/dwarf2.c
@@ -2044,19 +2044,16 @@ concat_filename (struct line_info_table *table, unsigned int file)
       char *subdir_name = NULL;
       char *name;
       size_t len;
-
-      if (table->files[file].dir
-	  /* PR 17512: file: 0317e960.  */
-	  && table->files[file].dir
-	  <= (table->use_dir_and_file_0 ? table->num_dirs - 1 : table->num_dirs)
-	  /* PR 17512: file: 7f3d2e4b.  */
-	  && table->dirs != NULL)
-	{
-	  if (table->use_dir_and_file_0)
-	    subdir_name = table->dirs[table->files[file].dir];
-	  else
-	    subdir_name = table->dirs[table->files[file].dir - 1];
-	}
+      unsigned int dir = table->files[file].dir;
+
+      if (!table->use_dir_and_file_0)
+	--dir;
+      /* Wrapping from 0 to -1u above gives the intended result with
+	 the test below of leaving subdir_name NULL for pre-DWARF5 dir
+	 of 0.  */
+      /* PR 17512: file: 0317e960, file: 7f3d2e4b.  */
+      if (dir < table->num_dirs)
+	subdir_name = table->dirs[dir];
 
       if (!subdir_name || !IS_ABSOLUTE_PATH (subdir_name))
 	dir_name = table->comp_dir;

-- 
Alan Modra
Australia Development Lab, IBM

                 reply	other threads:[~2022-12-26 12:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y6mS/HVlwxWvjyo9@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).