]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Don't obstack-allocate the call site hash table
authorTom Tromey <tromey@adacore.com>
Wed, 5 Jun 2024 15:38:53 +0000 (09:38 -0600)
committerTom Tromey <tromey@adacore.com>
Mon, 24 Jun 2024 15:11:30 +0000 (09:11 -0600)
The call site hash table is the last hash table using obstack
allocation.  In one large (non-public) test case, these hash tables
take a substiantial amount of memory.  Some of this memory is wasted
-- whenever the hash table is resized, the old table is not freed.

This patch fixes the problem by changing this hash table to be
heap-allocated.  This means that resizing will no longer "leak"
memory.

gdb/dwarf2/cu.h
gdb/dwarf2/read.c
gdb/objfiles.c
gdb/symtab.c
gdb/symtab.h

index d23cc9b70e5e773d2ea80a87e919f4c4cdf3471d..b0ec2d6fabce78eed63eb17a47097a211e9b76f2 100644 (file)
@@ -170,7 +170,7 @@ public:
   std::vector<delayed_method_info> method_list;
 
   /* To be copied to symtab->call_site_htab.  */
-  htab_t call_site_htab = nullptr;
+  htab_up call_site_htab;
 
   /* Non-NULL if this CU came from a DWO file.
      There is an invariant here that is important to remember:
index eee8b454e5f5f6bb4c4773741b2376484e244688..01d1a6bcb3aea1907b2b0e71dfe965ba1cc3d1c9 100644 (file)
@@ -6233,7 +6233,7 @@ process_full_comp_unit (dwarf2_cu *cu, enum language pretend_language)
       else
        cust->set_epilogue_unwind_valid (true);
 
-      cust->set_call_site_htab (cu->call_site_htab);
+      cust->set_call_site_htab (std::move (cu->call_site_htab));
     }
 
   per_objfile->set_symtab (cu->per_cu, cust);
@@ -10208,13 +10208,12 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
     }
   unrelocated_addr pc = attr->as_address ();
 
-  if (cu->call_site_htab == NULL)
-    cu->call_site_htab = htab_create_alloc_ex (16, call_site::hash,
-                                              call_site::eq, NULL,
-                                              &objfile->objfile_obstack,
-                                              hashtab_obstack_allocate, NULL);
+  if (cu->call_site_htab == nullptr)
+    cu->call_site_htab.reset (htab_create_alloc (16, call_site::hash,
+                                                call_site::eq, nullptr,
+                                                xcalloc, xfree));
   struct call_site call_site_local (pc, nullptr, nullptr);
-  slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT);
+  slot = htab_find_slot (cu->call_site_htab.get (), &call_site_local, INSERT);
   if (*slot != NULL)
     {
       complaint (_("Duplicate PC %s for DW_TAG_call_site "
index e6b0ca7f29b93b84f0f8b471e696d07161c8e24e..368e129b49d3c4fd9700b145e5fba8714438515d 100644 (file)
@@ -530,6 +530,8 @@ objfile::~objfile ()
   /* It still may reference data modules have associated with the objfile and
      the symbol file data.  */
   forget_cached_source_info ();
+  for (compunit_symtab *cu : compunits ())
+    cu->finalize ();
 
   breakpoint_free_objfile (this);
   btrace_free_objfile (this);
index 39a6915ee76ecfcf4fa4b66c0e92af1a8f394d30..41d71beec2ac165e424aa6d89eec0d4b6c591fc6 100644 (file)
@@ -428,10 +428,10 @@ compunit_symtab::find_call_site (CORE_ADDR pc) const
 /* See symtab.h.  */
 
 void
-compunit_symtab::set_call_site_htab (htab_t call_site_htab)
+compunit_symtab::set_call_site_htab (htab_up call_site_htab)
 {
   gdb_assert (m_call_site_htab == nullptr);
-  m_call_site_htab = call_site_htab;
+  m_call_site_htab = call_site_htab.release ();
 }
 
 /* See symtab.h.  */
@@ -494,6 +494,16 @@ compunit_symtab::forget_cached_source_info ()
     s->release_fullname ();
 }
 
+/* See symtab.h.  */
+
+void
+compunit_symtab::finalize ()
+{
+  this->forget_cached_source_info ();
+  if (m_call_site_htab != nullptr)
+    htab_delete (m_call_site_htab);
+}
+
 /* The relocated address of the minimal symbol, using the section
    offsets from OBJFILE.  */
 
index d0b599fc58e189acdbeb1e6a09e8228e960146ff..a5631a27b5e26103c183618c4a7a4bf38237b3ec 100644 (file)
@@ -1957,7 +1957,7 @@ struct compunit_symtab
   symtab *primary_filetab () const;
 
   /* Set m_call_site_htab.  */
-  void set_call_site_htab (htab_t call_site_htab);
+  void set_call_site_htab (htab_up call_site_htab);
 
   /* Find call_site info for PC.  */
   call_site *find_call_site (CORE_ADDR pc) const;
@@ -1968,6 +1968,12 @@ struct compunit_symtab
   /* Clear any cached source file names.  */
   void forget_cached_source_info ();
 
+  /* This is called when an objfile is being destroyed and will free
+     any resources used by this compunit_symtab.  Normally a
+     destructor would be used instead, but at the moment
+     compunit_symtab objects are allocated on an obstack.  */
+  void finalize ();
+
   /* Unordered chain of all compunit symtabs of this objfile.  */
   struct compunit_symtab *next;