]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Empty hash table fix in .debug_names reader
authorTom Tromey <tom@tromey.com>
Mon, 4 Dec 2023 14:58:48 +0000 (07:58 -0700)
committerTom Tromey <tom@tromey.com>
Thu, 18 Jan 2024 15:20:17 +0000 (08:20 -0700)
The handling of an empty hash table in the .debug_names reader is
slightly wrong.

Currently the code assumes there is always an array of hashes.
However, section 6.1.1.4.5 Hash Lookup Table says:

    The optional hash lookup table immediately follows the list of
    type signatures.

and then:

    The hash lookup table is actually two separate arrays: an array of
    buckets, followed immediately by an array of hashes.

My reading of this is that the hash table as a whole is optional, and
so the hashes will not exist in this case.  (This also makes sense
because the hashes are not useful without the buckets anyway.)

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=25950

gdb/dwarf2/read-debug-names.c

index a2a9fd425ae82f7178f238cab04c913ca51c6610..b4ff36f0ed60ea1bf5f7db84fa6b70ae01413fdb 100644 (file)
@@ -294,7 +294,8 @@ read_debug_names_from_section (struct objfile *objfile,
   map.bucket_table_reordered = reinterpret_cast<const uint32_t *> (addr);
   addr += map.bucket_count * 4;
   map.hash_table_reordered = reinterpret_cast<const uint32_t *> (addr);
-  addr += map.name_count * 4;
+  if (map.bucket_count != 0)
+    addr += map.name_count * 4;
 
   /* Name Table */
   map.name_table_string_offs_reordered = addr;