diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2024-11-04 13:27:46 -0500 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2024-11-25 22:07:04 -0500 |
commit | 9f3341981413cf8b03f3a6b564e260a49d7c18ef (patch) | |
tree | 4bd4ef58c2544e2cf5c88628a0a94e43dc7b86b1 /gdb | |
parent | Convert type copying to new hash table (diff) | |
download | binutils-gdb-9f3341981413cf8b03f3a6b564e260a49d7c18ef.tar.gz binutils-gdb-9f3341981413cf8b03f3a6b564e260a49d7c18ef.tar.bz2 binutils-gdb-9f3341981413cf8b03f3a6b564e260a49d7c18ef.zip |
Convert static links to new hash table
This converts the objfile static link table to the new hash map.
Change-Id: If978e895679899ca2af4ef01c12842b4184d88e6
Co-Authored-By: Tom Tromey <tom@tromey.com>
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/objfiles.c | 74 | ||||
-rw-r--r-- | gdb/objfiles.h | 4 | ||||
-rw-r--r-- | gdb/symfile.c | 2 |
3 files changed, 13 insertions, 67 deletions
diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 555195dc61f..207a0cb22eb 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -153,39 +153,6 @@ set_objfile_main_name (struct objfile *objfile, objfile->per_bfd->language_of_main = lang; } -/* Helper structure to map blocks to static link properties in hash tables. */ - -struct static_link_htab_entry -{ - const struct block *block; - const struct dynamic_prop *static_link; -}; - -/* Return a hash code for struct static_link_htab_entry *P. */ - -static hashval_t -static_link_htab_entry_hash (const void *p) -{ - const struct static_link_htab_entry *e - = (const struct static_link_htab_entry *) p; - - return htab_hash_pointer (e->block); -} - -/* Return whether P1 an P2 (pointers to struct static_link_htab_entry) are - mappings for the same block. */ - -static int -static_link_htab_entry_eq (const void *p1, const void *p2) -{ - const struct static_link_htab_entry *e1 - = (const struct static_link_htab_entry *) p1; - const struct static_link_htab_entry *e2 - = (const struct static_link_htab_entry *) p2; - - return e1->block == e2->block; -} - /* Register STATIC_LINK as the static link for BLOCK, which is part of OBJFILE. Must not be called more than once for each BLOCK. */ @@ -194,25 +161,10 @@ objfile_register_static_link (struct objfile *objfile, const struct block *block, const struct dynamic_prop *static_link) { - void **slot; - struct static_link_htab_entry lookup_entry; - struct static_link_htab_entry *entry; - - if (objfile->static_links == NULL) - objfile->static_links.reset (htab_create_alloc - (1, &static_link_htab_entry_hash, static_link_htab_entry_eq, NULL, - xcalloc, xfree)); - - /* Create a slot for the mapping, make sure it's the first mapping for this - block and then create the mapping itself. */ - lookup_entry.block = block; - slot = htab_find_slot (objfile->static_links.get (), &lookup_entry, INSERT); - gdb_assert (*slot == NULL); - - entry = XOBNEW (&objfile->objfile_obstack, static_link_htab_entry); - entry->block = block; - entry->static_link = static_link; - *slot = (void *) entry; + /* Enter the mapping and make sure it's the first mapping for this + block. */ + bool inserted = objfile->static_links.emplace (block, static_link).second; + gdb_assert (inserted); } /* Look for a static link for BLOCK, which is part of OBJFILE. Return NULL if @@ -222,19 +174,11 @@ const struct dynamic_prop * objfile_lookup_static_link (struct objfile *objfile, const struct block *block) { - struct static_link_htab_entry *entry; - struct static_link_htab_entry lookup_entry; - - if (objfile->static_links == NULL) - return NULL; - lookup_entry.block = block; - entry = ((struct static_link_htab_entry *) - htab_find (objfile->static_links.get (), &lookup_entry)); - if (entry == NULL) - return NULL; - - gdb_assert (entry->block == block); - return entry->static_link; + if (auto iter = objfile->static_links.find (block); + iter != objfile->static_links.end ()) + return iter->second; + + return nullptr; } diff --git a/gdb/objfiles.h b/gdb/objfiles.h index bd65e2bd030..2121fd31792 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -32,6 +32,7 @@ #include "jit.h" #include "quick-symbol.h" #include <forward_list> +#include "gdbsupport/unordered_map.h" struct htab; struct objfile_data; @@ -857,7 +858,8 @@ public: Very few blocks have a static link, so it's more memory efficient to store these here rather than in struct block. Static links must be allocated on the objfile's obstack. */ - htab_up static_links; + gdb::unordered_map<const block *, const dynamic_prop *> + static_links; /* JIT-related data for this objfile, if the objfile is a JITer; that is, it produces JITed objfiles. */ diff --git a/gdb/symfile.c b/gdb/symfile.c index 4386cdce5e7..4bc0c4916bd 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -2585,7 +2585,7 @@ reread_symbols (int from_tty) objfile->sect_index_text = -1; objfile->compunit_symtabs = NULL; objfile->template_symbols = NULL; - objfile->static_links.reset (nullptr); + objfile->static_links.clear (); /* obstack_init also initializes the obstack so it is empty. We could use obstack_specify_allocation but |