public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Convert elfread.c to type-safe registry API
@ 2019-05-08 22:09 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2019-05-08 22:09 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8127a2fab5780f27a1c9998b0be4d8b5c28c1603

commit 8127a2fab5780f27a1c9998b0be4d8b5c28c1603
Author: Tom Tromey <tom@tromey.com>
Date:   Wed May 1 15:41:13 2019 -0600

    Convert elfread.c to type-safe registry API
    
    This changes elfread.c to use the type-safe registry API.  This also
    fixes a potential memory leak, by changing the hash table so that it
    is no longer allocated on an obstack.
    
    gdb/ChangeLog
    2019-05-08  Tom Tromey  <tom@tromey.com>
    
    	* elfread.c (elf_objfile_gnu_ifunc_cache_data): Change type.
    	(elf_gnu_ifunc_record_cache): Update.  Don't allocate hash table
    	on obstack.
    	(elf_gnu_ifunc_resolve_by_cache, _initialize_elfread): Update.

Diff:
---
 gdb/ChangeLog |  7 +++++++
 gdb/elfread.c | 18 ++++++++----------
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 4f1859c..be3e5db 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,12 @@
 2019-05-08  Tom Tromey  <tom@tromey.com>
 
+	* elfread.c (elf_objfile_gnu_ifunc_cache_data): Change type.
+	(elf_gnu_ifunc_record_cache): Update.  Don't allocate hash table
+	on obstack.
+	(elf_gnu_ifunc_resolve_by_cache, _initialize_elfread): Update.
+
+2019-05-08  Tom Tromey  <tom@tromey.com>
+
 	* mdebugread.c (basic_type_data): Change type.
 	(basic_type, _initialize_mdebugread): Update.
 
diff --git a/gdb/elfread.c b/gdb/elfread.c
index deee6f0..cb98b83 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -639,7 +639,8 @@ elf_rel_plt_read (minimal_symbol_reader &reader,
 
 /* The data pointer is htab_t for gnu_ifunc_record_cache_unchecked.  */
 
-static const struct objfile_data *elf_objfile_gnu_ifunc_cache_data;
+static const struct objfile_key<htab, htab_deleter>
+  elf_objfile_gnu_ifunc_cache_data;
 
 /* Map function names to CORE_ADDR in elf_objfile_gnu_ifunc_cache_data.  */
 
@@ -710,15 +711,13 @@ elf_gnu_ifunc_record_cache (const char *name, CORE_ADDR addr)
   if (len > 4 && strcmp (target_name + len - 4, "@plt") == 0)
     return 0;
 
-  htab = (htab_t) objfile_data (objfile, elf_objfile_gnu_ifunc_cache_data);
+  htab = elf_objfile_gnu_ifunc_cache_data.get (objfile);
   if (htab == NULL)
     {
-      htab = htab_create_alloc_ex (1, elf_gnu_ifunc_cache_hash,
-				   elf_gnu_ifunc_cache_eq,
-				   NULL, &objfile->objfile_obstack,
-				   hashtab_obstack_allocate,
-				   dummy_obstack_deallocate);
-      set_objfile_data (objfile, elf_objfile_gnu_ifunc_cache_data, htab);
+      htab = htab_create_alloc (1, elf_gnu_ifunc_cache_hash,
+				elf_gnu_ifunc_cache_eq,
+				NULL, xcalloc, xfree);
+      elf_objfile_gnu_ifunc_cache_data.set (objfile, htab);
     }
 
   entry_local.addr = addr;
@@ -769,7 +768,7 @@ elf_gnu_ifunc_resolve_by_cache (const char *name, CORE_ADDR *addr_p)
       struct elf_gnu_ifunc_cache *entry_p;
       void **slot;
 
-      htab = (htab_t) objfile_data (objfile, elf_objfile_gnu_ifunc_cache_data);
+      htab = elf_objfile_gnu_ifunc_cache_data.get (objfile);
       if (htab == NULL)
 	continue;
 
@@ -1462,6 +1461,5 @@ _initialize_elfread (void)
 {
   add_symtab_fns (bfd_target_elf_flavour, &elf_sym_fns);
 
-  elf_objfile_gnu_ifunc_cache_data = register_objfile_data ();
   gnu_ifunc_fns_p = &elf_gnu_ifunc_fns;
 }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-05-08 22:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-08 22:09 [binutils-gdb] Convert elfread.c to type-safe registry API Tom Tromey

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).