From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id 3EFAF385AE70; Sat, 9 Jul 2022 12:36:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3EFAF385AE70 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Alan Modra To: bfd-cvs@sourceware.org Subject: [binutils-gdb] gas: target string hash tables X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: a51628a9d49bf7abb89b71032aa38d7f596be674 X-Git-Newrev: 7bfc4db2893c5de00197e40ab52394979f83a75d Message-Id: <20220709123631.3EFAF385AE70@sourceware.org> Date: Sat, 9 Jul 2022 12:36:31 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Jul 2022 12:36:31 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D7bfc4db2893c= 5de00197e40ab52394979f83a75d commit 7bfc4db2893c5de00197e40ab52394979f83a75d Author: Alan Modra Date: Wed Jul 6 09:54:21 2022 +0930 gas: target string hash tables =20 This allocates entries added to the string hash tables on the notes obstack, so that at least those do not leak. A followup patch will switch over the str_hash allocation to notes_calloc, which is why I haven't implemented deleting all the target string hash tables. =20 * config/obj-coff-seh.c (get_pxdata_name, alloc_pxdata_item): U= se notes obstack for string hash table entries. * config/tc-alpha.c (get_alpha_reloc_tag, md_begin): Likewise. * config/tc-h8300.c (md_begin): Likewise. * config/tc-ia64.c (dot_rot, dot_pred_rel, dot_alias): Likewise. * config/tc-nds32.c (nds32_relax_hint): Likewise. * config/tc-riscv.c (riscv_init_csr_hash): Likewise. * config/tc-score.c (s3_insert_reg): Likewise. (s3_build_score_ops_hsh, s3_build_dependency_insn_hsh): Likewis= e. * config/tc-score7.c (s7_build_score_ops_hsh): Likewise. (s7_build_dependency_insn_hsh): Likewise. * config/tc-tic4x.c (tic4x_asg): Likewise. Diff: --- gas/config/obj-coff-seh.c | 7 +++---- gas/config/tc-alpha.c | 11 ++++++----- gas/config/tc-h8300.c | 5 +---- gas/config/tc-ia64.c | 24 +++++++----------------- gas/config/tc-nds32.c | 9 +++------ gas/config/tc-riscv.c | 2 +- gas/config/tc-score.c | 38 ++++++++++++-------------------------- gas/config/tc-score7.c | 22 +++++++--------------- gas/config/tc-tic4x.c | 8 +++++--- 9 files changed, 45 insertions(+), 81 deletions(-) diff --git a/gas/config/obj-coff-seh.c b/gas/config/obj-coff-seh.c index c30eda9cd7f..0b43c8b2d98 100644 --- a/gas/config/obj-coff-seh.c +++ b/gas/config/obj-coff-seh.c @@ -64,7 +64,7 @@ get_pxdata_name (segT seg, const char *base_name) else name =3D dollar; =20 - sname =3D concat (base_name, name, NULL); + sname =3D notes_concat (base_name, name, NULL); =20 return sname; } @@ -75,8 +75,7 @@ alloc_pxdata_item (segT seg, int subseg, char *name) { struct seh_seg_list *r; =20 - r =3D (struct seh_seg_list *) - xmalloc (sizeof (struct seh_seg_list) + strlen (name)); + r =3D notes_alloc (sizeof (struct seh_seg_list) + strlen (name)); r->seg =3D seg; r->subseg =3D subseg; r->seg_name =3D name; @@ -145,7 +144,7 @@ seh_hash_find_or_make (segT cseg, const char *base_name) seh_hash_insert (item->seg_name, item); } else - free (name); + notes_free (name); =20 return item; } diff --git a/gas/config/tc-alpha.c b/gas/config/tc-alpha.c index ecc6a2f4b18..c305acc2594 100644 --- a/gas/config/tc-alpha.c +++ b/gas/config/tc-alpha.c @@ -594,8 +594,7 @@ get_alpha_reloc_tag (long sequence) { size_t len =3D strlen (buffer); =20 - info =3D (struct alpha_reloc_tag *) - xcalloc (sizeof (struct alpha_reloc_tag) + len, 1); + info =3D notes_calloc (sizeof (struct alpha_reloc_tag) + len, 1); =20 info->segment =3D now_seg; info->sequence =3D sequence; @@ -5434,10 +5433,12 @@ md_begin (void) =20 if ((slash =3D strchr (name, '/')) !=3D NULL) { - char *p =3D XNEWVEC (char, strlen (name)); + size_t len =3D strlen (name); + char *p =3D notes_alloc (len); + size_t len1 =3D slash - name; =20 - memcpy (p, name, slash - name); - strcpy (p + (slash - name), slash + 1); + memcpy (p, name, len1); + memcpy (p + len1, slash + 1, len - len1); =20 (void) str_hash_insert (alpha_opcode_hash, p, &alpha_opcodes[i], 0); /* Ignore failures -- the opcode table does duplicate some diff --git a/gas/config/tc-h8300.c b/gas/config/tc-h8300.c index 690055e26bf..ac1dc0722bc 100644 --- a/gas/config/tc-h8300.c +++ b/gas/config/tc-h8300.c @@ -235,14 +235,12 @@ md_begin (void) unsigned int nopcodes; struct h8_opcode *p, *p1; struct h8_instruction *pi; - char prev_buffer[100]; int idx =3D 0; =20 if (!bfd_set_arch_mach (stdoutput, bfd_arch_h8300, default_mach)) as_warn (_("could not set architecture and machine")); =20 opcode_hash_control =3D str_htab_create (); - prev_buffer[0] =3D 0; =20 nopcodes =3D sizeof (h8_opcodes) / sizeof (struct h8_opcode); =20 @@ -266,7 +264,7 @@ md_begin (void) break; /* Strip off any . part when inserting the opcode and only enter unique codes into the hash table. */ - dst =3D buffer =3D XNEWVEC (char, strlen (src) + 1); + dst =3D buffer =3D notes_alloc (strlen (src) + 1); while (*src) { if (*src =3D=3D '.') @@ -283,7 +281,6 @@ md_begin (void) if (cmplen =3D=3D 0) cmplen =3D len; str_hash_insert (opcode_hash_control, buffer, pi, 0); - strcpy (prev_buffer, buffer); idx++; =20 for (p =3D p1; p->name; p++) diff --git a/gas/config/tc-ia64.c b/gas/config/tc-ia64.c index 771071b23cf..7fa7e572a22 100644 --- a/gas/config/tc-ia64.c +++ b/gas/config/tc-ia64.c @@ -4663,14 +4663,9 @@ dot_rot (int type) } =20 if (!*drpp) - { - *drpp =3D XOBNEW (¬es, struct dynreg); - memset (*drpp, 0, sizeof (*dr)); - } + *drpp =3D notes_calloc (1, sizeof (**drpp)); =20 - name =3D XOBNEWVEC (¬es, char, len + 1); - memcpy (name, start, len); - name[len] =3D '\0'; + name =3D notes_memdup (start, len, len + 1); =20 dr =3D *drpp; dr->name =3D name; @@ -4682,7 +4677,6 @@ dot_rot (int type) if (str_hash_insert (md.dynreg_hash, name, dr, 0) !=3D NULL) { as_bad (_("Attempt to redefine register set `%s'"), name); - obstack_free (¬es, name); goto err; } =20 @@ -5007,7 +5001,7 @@ dot_pred_rel (int type) type =3D 'c'; else if (strcmp (form, "imply") =3D=3D 0) type =3D 'i'; - obstack_free (¬es, form); + notes_free (form); } else if (*input_line_pointer =3D=3D '@') { @@ -11781,9 +11775,7 @@ dot_alias (int section) } =20 /* Make a copy of name string. */ - len =3D strlen (name) + 1; - obstack_grow (¬es, name, len); - name =3D obstack_finish (¬es); + name =3D notes_strdup (name); =20 if (section) { @@ -11806,8 +11798,7 @@ dot_alias (int section) if (strcmp (h->name, name)) as_bad (_("`%s' is already the alias of %s `%s'"), alias, kind, h->name); - obstack_free (¬es, name); - obstack_free (¬es, alias); + notes_free (alias); goto out; } =20 @@ -11817,12 +11808,11 @@ dot_alias (int section) { if (strcmp (a, alias)) as_bad (_("%s `%s' already has an alias `%s'"), kind, name, a); - obstack_free (¬es, name); - obstack_free (¬es, alias); + notes_free (alias); goto out; } =20 - h =3D XNEW (struct alias); + h =3D notes_alloc (sizeof (*h)); h->file =3D as_where (&h->line); h->name =3D name; =20 diff --git a/gas/config/tc-nds32.c b/gas/config/tc-nds32.c index 3ad227bf31c..48893a5762e 100644 --- a/gas/config/tc-nds32.c +++ b/gas/config/tc-nds32.c @@ -4284,20 +4284,17 @@ nds32_relax_hint (int mode ATTRIBUTE_UNUSED) relocs =3D str_hash_find (nds32_hint_hash, name); if (relocs =3D=3D NULL) { - relocs =3D XNEW (struct nds32_relocs_pattern); - memset (relocs, 0, sizeof (struct nds32_relocs_pattern)); + relocs =3D notes_calloc (1, sizeof (*relocs)); str_hash_insert (nds32_hint_hash, name, relocs, 0); } else { while (relocs->next) - relocs=3Drelocs->next; - relocs->next =3D XNEW (struct nds32_relocs_pattern); + relocs =3D relocs->next; + relocs->next =3D notes_calloc (1, sizeof (*relocs)); relocs =3D relocs->next; - memset (relocs, 0, sizeof (struct nds32_relocs_pattern)); } =20 - relocs->next =3D NULL; *input_line_pointer =3D saved_char; ignore_rest_of_line (); =20 diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c index 7807dd00cf2..291d07f6d8f 100644 --- a/gas/config/tc-riscv.c +++ b/gas/config/tc-riscv.c @@ -879,7 +879,7 @@ riscv_init_csr_hash (const char *name, if (!need_enrty) return; =20 - entry =3D XNEW (struct riscv_csr_extra); + entry =3D notes_alloc (sizeof (*entry)); entry->csr_class =3D class; entry->address =3D address; entry->define_version =3D define_version; diff --git a/gas/config/tc-score.c b/gas/config/tc-score.c index c2814a0bc6b..537122816d7 100644 --- a/gas/config/tc-score.c +++ b/gas/config/tc-score.c @@ -6255,20 +6255,14 @@ s3_s_score_lcomm (int bytes_p) static void s3_insert_reg (const struct s3_reg_entry *r, htab_t htab) { - int i =3D 0; - int len =3D strlen (r->name) + 2; - char *buf =3D XNEWVEC (char, len); - char *buf2 =3D XNEWVEC (char, len); + char *buf =3D notes_strdup (r->name); + char *p; =20 - strcpy (buf + i, r->name); - for (i =3D 0; buf[i]; i++) - { - buf2[i] =3D TOUPPER (buf[i]); - } - buf2[i] =3D '\0'; + for (p =3D buf; *p; p++) + *p =3D TOUPPER (*p); =20 + str_hash_insert (htab, r->name, r, 0); str_hash_insert (htab, buf, r, 0); - str_hash_insert (htab, buf2, r, 0); } =20 static void @@ -6286,20 +6280,17 @@ static void s3_build_score_ops_hsh (void) { unsigned int i; - static struct obstack insn_obstack; =20 - obstack_begin (&insn_obstack, 4000); for (i =3D 0; i < sizeof (s3_score_insns) / sizeof (struct s3_asm_opcode= ); i++) { const struct s3_asm_opcode *insn =3D s3_score_insns + i; - size_t len =3D strlen (insn->template_name); + size_t len =3D strlen (insn->template_name) + 1; struct s3_asm_opcode *new_opcode; char *template_name; - new_opcode =3D (struct s3_asm_opcode *) - obstack_alloc (&insn_obstack, sizeof (struct s3_asm_opcode)); - template_name =3D (char *) obstack_alloc (& insn_obstack, len + 1); =20 - strcpy (template_name, insn->template_name); + new_opcode =3D notes_alloc (sizeof (*new_opcode)); + template_name =3D notes_memdup (insn->template_name, len, len); + new_opcode->template_name =3D template_name; new_opcode->parms =3D insn->parms; new_opcode->value =3D insn->value; @@ -6315,22 +6306,17 @@ static void s3_build_dependency_insn_hsh (void) { unsigned int i; - static struct obstack dependency_obstack; =20 - obstack_begin (&dependency_obstack, 4000); for (i =3D 0; i < sizeof (s3_insn_to_dependency_table) / sizeof (s3_insn= _to_dependency_table[0]); i++) { const struct s3_insn_to_dependency *tmp =3D s3_insn_to_dependency_ta= ble + i; - size_t len =3D strlen (tmp->insn_name); + size_t len =3D strlen (tmp->insn_name) + 1; struct s3_insn_to_dependency *new_i2n; char *buf; =20 - new_i2n =3D (struct s3_insn_to_dependency *) - obstack_alloc (&dependency_obstack, - sizeof (struct s3_insn_to_dependency)); - buf =3D (char *) obstack_alloc (&dependency_obstack, len + 1); + new_i2n =3D notes_alloc (sizeof (*new_i2n)); + buf =3D notes_memdup (tmp->insn_name, len, len); =20 - strcpy (buf, tmp->insn_name); new_i2n->insn_name =3D buf; new_i2n->type =3D tmp->type; str_hash_insert (s3_dependency_insn_hsh, new_i2n->insn_name, new_i2n= , 0); diff --git a/gas/config/tc-score7.c b/gas/config/tc-score7.c index c36945f8eb3..a2cde1fc69f 100644 --- a/gas/config/tc-score7.c +++ b/gas/config/tc-score7.c @@ -5085,20 +5085,17 @@ static void s7_build_score_ops_hsh (void) { unsigned int i; - static struct obstack insn_obstack; =20 - obstack_begin (&insn_obstack, 4000); for (i =3D 0; i < sizeof (s7_score_insns) / sizeof (struct s7_asm_opcode= ); i++) { const struct s7_asm_opcode *insn =3D s7_score_insns + i; - size_t len =3D strlen (insn->template_name); + size_t len =3D strlen (insn->template_name) + 1; struct s7_asm_opcode *new_opcode; char *template_name; - new_opcode =3D (struct s7_asm_opcode *) - obstack_alloc (&insn_obstack, sizeof (struct s7_asm_opcode)); - template_name =3D (char *) obstack_alloc (&insn_obstack, len + 1); =20 - strcpy (template_name, insn->template_name); + new_opcode =3D notes_alloc (sizeof (*new_opcode)); + template_name =3D notes_memdup (insn->template_name, len, len); + new_opcode->template_name =3D template_name; new_opcode->parms =3D insn->parms; new_opcode->value =3D insn->value; @@ -5114,22 +5111,17 @@ static void s7_build_dependency_insn_hsh (void) { unsigned int i; - static struct obstack dependency_obstack; =20 - obstack_begin (&dependency_obstack, 4000); for (i =3D 0; i < ARRAY_SIZE (s7_insn_to_dependency_table); i++) { const struct s7_insn_to_dependency *tmp =3D s7_insn_to_dependency_ta= ble + i; - size_t len =3D strlen (tmp->insn_name); + size_t len =3D strlen (tmp->insn_name) + 1; struct s7_insn_to_dependency *new_i2d; char *insn_name; =20 - new_i2d =3D (struct s7_insn_to_dependency *) - obstack_alloc (&dependency_obstack, - sizeof (struct s7_insn_to_dependency)); - insn_name =3D (char *) obstack_alloc (&dependency_obstack, len + 1); + new_i2d =3D notes_alloc (sizeof (*new_i2d)); + insn_name =3D notes_memdup (tmp->insn_name, len, len); =20 - strcpy (insn_name, tmp->insn_name); new_i2d->insn_name =3D insn_name; new_i2d->type =3D tmp->type; str_hash_insert (s7_dependency_insn_hsh, new_i2d->insn_name, new_i2d= , 0); diff --git a/gas/config/tc-tic4x.c b/gas/config/tc-tic4x.c index b1b7bcf6268..03da1d432b2 100644 --- a/gas/config/tc-tic4x.c +++ b/gas/config/tc-tic4x.c @@ -709,6 +709,7 @@ tic4x_asg (int x ATTRIBUTE_UNUSED) char c; char *name; char *str; + size_t len; =20 SKIP_WHITESPACE (); str =3D input_line_pointer; @@ -721,10 +722,11 @@ tic4x_asg (int x ATTRIBUTE_UNUSED) as_bad (_("Comma expected\n")); return; } - *input_line_pointer++ =3D '\0'; + len =3D input_line_pointer - str; + str =3D notes_memdup (str, len, len + 1); + input_line_pointer++; c =3D get_symbol_name (&name); /* Get terminator. */ - str =3D xstrdup (str); - name =3D xstrdup (name); + name =3D notes_strdup (name); str_hash_insert (tic4x_asg_hash, name, str, 1); (void) restore_line_pointer (c); demand_empty_rest_of_line ();