diff options
author | Alan Modra <amodra@gmail.com> | 2022-07-06 09:54:21 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2022-07-09 21:36:10 +0930 |
commit | 7bfc4db2893c5de00197e40ab52394979f83a75d (patch) | |
tree | 2241be46f5e1a57a9f5a8b62f680a205aa67f7aa /gas | |
parent | a51628a9d49bf7abb89b71032aa38d7f596be674 (diff) | |
download | gdb-7bfc4db2893c5de00197e40ab52394979f83a75d.zip gdb-7bfc4db2893c5de00197e40ab52394979f83a75d.tar.gz gdb-7bfc4db2893c5de00197e40ab52394979f83a75d.tar.bz2 |
gas: target string hash tables
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.
* config/obj-coff-seh.c (get_pxdata_name, alloc_pxdata_item): Use
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): Likewise.
* config/tc-score7.c (s7_build_score_ops_hsh): Likewise.
(s7_build_dependency_insn_hsh): Likewise.
* config/tc-tic4x.c (tic4x_asg): Likewise.
Diffstat (limited to 'gas')
-rw-r--r-- | gas/config/obj-coff-seh.c | 7 | ||||
-rw-r--r-- | gas/config/tc-alpha.c | 11 | ||||
-rw-r--r-- | gas/config/tc-h8300.c | 5 | ||||
-rw-r--r-- | gas/config/tc-ia64.c | 24 | ||||
-rw-r--r-- | gas/config/tc-nds32.c | 9 | ||||
-rw-r--r-- | gas/config/tc-riscv.c | 2 | ||||
-rw-r--r-- | gas/config/tc-score.c | 38 | ||||
-rw-r--r-- | gas/config/tc-score7.c | 22 | ||||
-rw-r--r-- | 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 c30eda9..0b43c8b 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 = dollar; - sname = concat (base_name, name, NULL); + sname = notes_concat (base_name, name, NULL); return sname; } @@ -75,8 +75,7 @@ alloc_pxdata_item (segT seg, int subseg, char *name) { struct seh_seg_list *r; - r = (struct seh_seg_list *) - xmalloc (sizeof (struct seh_seg_list) + strlen (name)); + r = notes_alloc (sizeof (struct seh_seg_list) + strlen (name)); r->seg = seg; r->subseg = subseg; r->seg_name = 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); return item; } diff --git a/gas/config/tc-alpha.c b/gas/config/tc-alpha.c index ecc6a2f..c305acc 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 = strlen (buffer); - info = (struct alpha_reloc_tag *) - xcalloc (sizeof (struct alpha_reloc_tag) + len, 1); + info = notes_calloc (sizeof (struct alpha_reloc_tag) + len, 1); info->segment = now_seg; info->sequence = sequence; @@ -5434,10 +5433,12 @@ md_begin (void) if ((slash = strchr (name, '/')) != NULL) { - char *p = XNEWVEC (char, strlen (name)); + size_t len = strlen (name); + char *p = notes_alloc (len); + size_t len1 = slash - name; - memcpy (p, name, slash - name); - strcpy (p + (slash - name), slash + 1); + memcpy (p, name, len1); + memcpy (p + len1, slash + 1, len - len1); (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 690055e..ac1dc07 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 = 0; if (!bfd_set_arch_mach (stdoutput, bfd_arch_h8300, default_mach)) as_warn (_("could not set architecture and machine")); opcode_hash_control = str_htab_create (); - prev_buffer[0] = 0; nopcodes = sizeof (h8_opcodes) / sizeof (struct h8_opcode); @@ -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 = buffer = XNEWVEC (char, strlen (src) + 1); + dst = buffer = notes_alloc (strlen (src) + 1); while (*src) { if (*src == '.') @@ -283,7 +281,6 @@ md_begin (void) if (cmplen == 0) cmplen = len; str_hash_insert (opcode_hash_control, buffer, pi, 0); - strcpy (prev_buffer, buffer); idx++; for (p = p1; p->name; p++) diff --git a/gas/config/tc-ia64.c b/gas/config/tc-ia64.c index 771071b..7fa7e57 100644 --- a/gas/config/tc-ia64.c +++ b/gas/config/tc-ia64.c @@ -4663,14 +4663,9 @@ dot_rot (int type) } if (!*drpp) - { - *drpp = XOBNEW (¬es, struct dynreg); - memset (*drpp, 0, sizeof (*dr)); - } + *drpp = notes_calloc (1, sizeof (**drpp)); - name = XOBNEWVEC (¬es, char, len + 1); - memcpy (name, start, len); - name[len] = '\0'; + name = notes_memdup (start, len, len + 1); dr = *drpp; dr->name = name; @@ -4682,7 +4677,6 @@ dot_rot (int type) if (str_hash_insert (md.dynreg_hash, name, dr, 0) != NULL) { as_bad (_("Attempt to redefine register set `%s'"), name); - obstack_free (¬es, name); goto err; } @@ -5007,7 +5001,7 @@ dot_pred_rel (int type) type = 'c'; else if (strcmp (form, "imply") == 0) type = 'i'; - obstack_free (¬es, form); + notes_free (form); } else if (*input_line_pointer == '@') { @@ -11781,9 +11775,7 @@ dot_alias (int section) } /* Make a copy of name string. */ - len = strlen (name) + 1; - obstack_grow (¬es, name, len); - name = obstack_finish (¬es); + name = notes_strdup (name); 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; } @@ -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; } - h = XNEW (struct alias); + h = notes_alloc (sizeof (*h)); h->file = as_where (&h->line); h->name = name; diff --git a/gas/config/tc-nds32.c b/gas/config/tc-nds32.c index 3ad227b..48893a5 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 = str_hash_find (nds32_hint_hash, name); if (relocs == NULL) { - relocs = XNEW (struct nds32_relocs_pattern); - memset (relocs, 0, sizeof (struct nds32_relocs_pattern)); + relocs = notes_calloc (1, sizeof (*relocs)); str_hash_insert (nds32_hint_hash, name, relocs, 0); } else { while (relocs->next) - relocs=relocs->next; - relocs->next = XNEW (struct nds32_relocs_pattern); + relocs = relocs->next; + relocs->next = notes_calloc (1, sizeof (*relocs)); relocs = relocs->next; - memset (relocs, 0, sizeof (struct nds32_relocs_pattern)); } - relocs->next = NULL; *input_line_pointer = saved_char; ignore_rest_of_line (); diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c index 7807dd0..291d07f 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; - entry = XNEW (struct riscv_csr_extra); + entry = notes_alloc (sizeof (*entry)); entry->csr_class = class; entry->address = address; entry->define_version = define_version; diff --git a/gas/config/tc-score.c b/gas/config/tc-score.c index c2814a0..53712281 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 = 0; - int len = strlen (r->name) + 2; - char *buf = XNEWVEC (char, len); - char *buf2 = XNEWVEC (char, len); + char *buf = notes_strdup (r->name); + char *p; - strcpy (buf + i, r->name); - for (i = 0; buf[i]; i++) - { - buf2[i] = TOUPPER (buf[i]); - } - buf2[i] = '\0'; + for (p = buf; *p; p++) + *p = TOUPPER (*p); + str_hash_insert (htab, r->name, r, 0); str_hash_insert (htab, buf, r, 0); - str_hash_insert (htab, buf2, r, 0); } static void @@ -6286,20 +6280,17 @@ static void s3_build_score_ops_hsh (void) { unsigned int i; - static struct obstack insn_obstack; - obstack_begin (&insn_obstack, 4000); for (i = 0; i < sizeof (s3_score_insns) / sizeof (struct s3_asm_opcode); i++) { const struct s3_asm_opcode *insn = s3_score_insns + i; - size_t len = strlen (insn->template_name); + size_t len = strlen (insn->template_name) + 1; struct s3_asm_opcode *new_opcode; char *template_name; - new_opcode = (struct s3_asm_opcode *) - obstack_alloc (&insn_obstack, sizeof (struct s3_asm_opcode)); - template_name = (char *) obstack_alloc (& insn_obstack, len + 1); - strcpy (template_name, insn->template_name); + new_opcode = notes_alloc (sizeof (*new_opcode)); + template_name = notes_memdup (insn->template_name, len, len); + new_opcode->template_name = template_name; new_opcode->parms = insn->parms; new_opcode->value = insn->value; @@ -6315,22 +6306,17 @@ static void s3_build_dependency_insn_hsh (void) { unsigned int i; - static struct obstack dependency_obstack; - obstack_begin (&dependency_obstack, 4000); for (i = 0; i < sizeof (s3_insn_to_dependency_table) / sizeof (s3_insn_to_dependency_table[0]); i++) { const struct s3_insn_to_dependency *tmp = s3_insn_to_dependency_table + i; - size_t len = strlen (tmp->insn_name); + size_t len = strlen (tmp->insn_name) + 1; struct s3_insn_to_dependency *new_i2n; char *buf; - new_i2n = (struct s3_insn_to_dependency *) - obstack_alloc (&dependency_obstack, - sizeof (struct s3_insn_to_dependency)); - buf = (char *) obstack_alloc (&dependency_obstack, len + 1); + new_i2n = notes_alloc (sizeof (*new_i2n)); + buf = notes_memdup (tmp->insn_name, len, len); - strcpy (buf, tmp->insn_name); new_i2n->insn_name = buf; new_i2n->type = 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 c36945f..a2cde1fc 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; - obstack_begin (&insn_obstack, 4000); for (i = 0; i < sizeof (s7_score_insns) / sizeof (struct s7_asm_opcode); i++) { const struct s7_asm_opcode *insn = s7_score_insns + i; - size_t len = strlen (insn->template_name); + size_t len = strlen (insn->template_name) + 1; struct s7_asm_opcode *new_opcode; char *template_name; - new_opcode = (struct s7_asm_opcode *) - obstack_alloc (&insn_obstack, sizeof (struct s7_asm_opcode)); - template_name = (char *) obstack_alloc (&insn_obstack, len + 1); - strcpy (template_name, insn->template_name); + new_opcode = notes_alloc (sizeof (*new_opcode)); + template_name = notes_memdup (insn->template_name, len, len); + new_opcode->template_name = template_name; new_opcode->parms = insn->parms; new_opcode->value = insn->value; @@ -5114,22 +5111,17 @@ static void s7_build_dependency_insn_hsh (void) { unsigned int i; - static struct obstack dependency_obstack; - obstack_begin (&dependency_obstack, 4000); for (i = 0; i < ARRAY_SIZE (s7_insn_to_dependency_table); i++) { const struct s7_insn_to_dependency *tmp = s7_insn_to_dependency_table + i; - size_t len = strlen (tmp->insn_name); + size_t len = strlen (tmp->insn_name) + 1; struct s7_insn_to_dependency *new_i2d; char *insn_name; - new_i2d = (struct s7_insn_to_dependency *) - obstack_alloc (&dependency_obstack, - sizeof (struct s7_insn_to_dependency)); - insn_name = (char *) obstack_alloc (&dependency_obstack, len + 1); + new_i2d = notes_alloc (sizeof (*new_i2d)); + insn_name = notes_memdup (tmp->insn_name, len, len); - strcpy (insn_name, tmp->insn_name); new_i2d->insn_name = insn_name; new_i2d->type = 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 b1b7bcf..03da1d4 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; SKIP_WHITESPACE (); str = input_line_pointer; @@ -721,10 +722,11 @@ tic4x_asg (int x ATTRIBUTE_UNUSED) as_bad (_("Comma expected\n")); return; } - *input_line_pointer++ = '\0'; + len = input_line_pointer - str; + str = notes_memdup (str, len, len + 1); + input_line_pointer++; c = get_symbol_name (&name); /* Get terminator. */ - str = xstrdup (str); - name = xstrdup (name); + name = notes_strdup (name); str_hash_insert (tic4x_asg_hash, name, str, 1); (void) restore_line_pointer (c); demand_empty_rest_of_line (); |