public inbox for binutils-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb/binutils-2_39-branch] ppc gas: don't leak ppc_hash memory
@ 2022-07-12  2:37 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2022-07-12  2:37 UTC (permalink / raw)
  To: bfd-cvs

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

commit c596fcd2a030414064d76818c6ca5b3839305012
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Jul 7 22:03:15 2022 +0930

    ppc gas: don't leak ppc_hash memory
    
            * config/tc-ppc.c (insn_obstack): New.
            (insn_calloc): New function.
            (ppc_setup_opcodes): Use insn_obstack for ppc_hash.
    
    (cherry picked from commit a887be69963c40ced36e319e5fb14b3de4b6658b)
    Without ppc_md_end since the infrastructure to call that late isn't
    available on the branch, and without the multiply overflow check.

Diff:
---
 gas/config/tc-ppc.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c
index 4d789fd16a9..25550528c05 100644
--- a/gas/config/tc-ppc.c
+++ b/gas/config/tc-ppc.c
@@ -976,6 +976,10 @@ ppc_optimize_expr (expressionS *left, operatorT op, expressionS *right)
 /* Whether to target xcoff64/elf64.  */
 static unsigned int ppc_obj64 = BFD_DEFAULT_TARGET_SIZE == 64;
 
+/* A separate obstack for use by ppc_hash, so that we can quickly
+   throw away hash table memory .  */
+struct obstack insn_obstack;
+
 /* Opcode hash table.  */
 static htab_t ppc_hash;
 
@@ -1613,6 +1617,15 @@ insn_validate (const struct powerpc_opcode *op)
   return false;
 }
 
+static void *
+insn_calloc (size_t n, size_t size)
+{
+  size_t amt = n * size;
+  void *ret = obstack_alloc (&insn_obstack, amt);
+  memset (ret, 0, amt);
+  return ret;
+}
+
 /* Insert opcodes into hash tables.  Called at startup and for
    .machine pseudo.  */
 
@@ -1624,10 +1637,16 @@ ppc_setup_opcodes (void)
   bool bad_insn = false;
 
   if (ppc_hash != NULL)
-    htab_delete (ppc_hash);
+    {
+      htab_delete (ppc_hash);
+      _obstack_free (&insn_obstack, NULL);
+    }
+
+  obstack_begin (&insn_obstack, chunksize);
 
   /* Insert the opcodes into a hash table.  */
-  ppc_hash = str_htab_create ();
+  ppc_hash = htab_create_alloc (5000, hash_string_tuple, eq_string_tuple,
+				NULL, insn_calloc, NULL);
 
   if (ENABLE_CHECKING)
     {


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

only message in thread, other threads:[~2022-07-12  2:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-12  2:37 [binutils-gdb/binutils-2_39-branch] ppc gas: don't leak ppc_hash memory Alan Modra

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