public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH] Fix ASAN failure in DWO code
Date: Tue,  9 Jan 2024 12:51:43 -0700	[thread overview]
Message-ID: <20240109195143.291756-1-tom@tromey.com> (raw)

Simon pointed out that my recent change to the DWO code caused a
failure in ASAN testing.

The bug here was I updated the code to use a different search type in
the hash table; but then did not change the search code to use
htab_find_slot_with_hash.

Note that this bug would not be possible with my type-safe hash table
series, hint, hint.
---
 gdb/dwarf2/read.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index e055371dc6a..ca4dda5aea1 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -7783,16 +7783,24 @@ read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
    and DWP files (a file with the DWOs packaged up into one file), we treat
    DWP files as having a collection of virtual DWO files.  */
 
+/* A helper function to hash two file names.  This is a separate
+   function because the hash table uses a search with a different
+   type.  The second file may be NULL.  */
+
+static hashval_t
+hash_two_files (const char *one, const char *two)
+{
+  hashval_t hash = htab_hash_string (one);
+  if (two != nullptr)
+    hash += htab_hash_string (two);
+  return hash;
+}
+
 static hashval_t
 hash_dwo_file (const void *item)
 {
   const struct dwo_file *dwo_file = (const struct dwo_file *) item;
-  hashval_t hash;
-
-  hash = htab_hash_string (dwo_file->dwo_name.c_str ());
-  if (dwo_file->comp_dir != NULL)
-    hash += htab_hash_string (dwo_file->comp_dir);
-  return hash;
+  return hash_two_files (dwo_file->dwo_name.c_str (), dwo_file->comp_dir);
 }
 
 /* This is used when looking up entries in the DWO hash table.  */
@@ -7803,6 +7811,12 @@ struct dwo_file_search
   const char *dwo_name;
   /* Compilation directory to look for.  */
   const char *comp_dir;
+
+  /* Return a hash value compatible with the table.  */
+  hashval_t hash () const
+  {
+    return hash_two_files (dwo_name, comp_dir);
+  }
 };
 
 static int
@@ -7846,8 +7860,9 @@ lookup_dwo_file_slot (dwarf2_per_objfile *per_objfile,
 
   find_entry.dwo_name = dwo_name;
   find_entry.comp_dir = comp_dir;
-  slot = htab_find_slot (per_objfile->per_bfd->dwo_files.get (), &find_entry,
-			 INSERT);
+  slot = htab_find_slot_with_hash (per_objfile->per_bfd->dwo_files.get (),
+				   &find_entry, find_entry.hash (),
+				   INSERT);
 
   return slot;
 }
-- 
2.43.0


             reply	other threads:[~2024-01-09 19:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-09 19:51 Tom Tromey [this message]
2024-01-09 20:29 ` Simon Marchi

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=20240109195143.291756-1-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@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).