diff options
Diffstat (limited to 'gas')
67 files changed, 633 insertions, 364 deletions
diff --git a/gas/ChangeLog b/gas/ChangeLog index 1155727..2dde2df 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,146 @@ +2020-08-23 Alan Modra <amodra@gmail.com> + + PR 26513 + * hash.h (htab_insert): Update prototype and comment. + (struct string_tuple): Make "value" a const void*. + (string_tuple_alloc): Likewise. + (str_hash_find, str_hash_find_n): Cast returned value. + (str_hash_insert): Add "replace" parameter, and return slot pointer. + Free alloc'd element when not inserted. + * hash.c (htab_insert): Likewise. Return slot when element exists, + otherwise return NULL. + * read.c (pop_insert): Insert into hash table without first searching. + * config/tc-avr.c (md_begin): Likewise. + * config/tc-msp430.c (md_begin): Likewise. + * config/tc-nds32.c (nds32_init_nds32_pseudo_opcodes): Likewise. + * config/tc-v850.c (md_begin): Likewise. + * macro.c (do_formals, define_macro, macro_expand_body): Likewise. + (delete_macro): Delete from hash table. + * config/tc-tic54x.c (subsym_create_or_replace): Correct logic. + + * symbols.c (local_symbol_make, symbol_table_insert): Allow + replacement of hash table entries. + * config/obj-coff-seh.c (seh_hash_insert): Likewise. + * config/obj-coff.c (tag_insert): Likewise. + * config/tc-iq2000.c (iq2000_add_macro): Likewise. + * config/tc-m68k.c (md_begin): Likewise for aliases. + * config/tc-tic4x.c (tic4x_asg): Likewise. + * config/tc-tic6x.c (md_begin): Likewise. + + * dw2gencfi.c (dwcfi_hash_find_or_make): Disallow replacement of + hash table entries. + * ecoff.c (add_string, get_tag): Likewise. + * macro.c (expand_irp): Likewise. + * config/obj-elf.c (build_additional_section_info): Likewise. + * config/tc-aarch64.c (insert_reg_alias): Likewise. + (checked_hash_insert): Likewise. + * config/tc-alpha.c (get_alpha_reloc_tag, md_begin): Likewise. + * config/tc-arc.c (arc_insert_opcode, declare_register): Likewise. + (declare_addrtype, md_begin, arc_extcorereg): Likewise. + * config/tc-arm.c (insert_reg_alias): Likewise. + (arm_tc_equal_in_insn, md_begin): Likewise. + * config/tc-cr16.c (initialise_reg_hash_table, md_begin): Likewise. + * config/tc-cris.c (md_begin): Likewise. + * config/tc-crx.c (md_begin): Likewise. + * config/tc-csky.c (md_begin): Likewise. + * config/tc-d10v.c (md_begin): Likewise. + * config/tc-dlx.c (md_begin): Likewise. + * config/tc-ft32.c (md_begin): Likewise. + * config/tc-h8300.c (md_begin): Likewise. + * config/tc-hppa.c (md_begin): Likewise. + * config/tc-i386.c (md_begin): Likewise. + * config/tc-ia64.c (dot_rot, dot_entry, declare_register): Likewise. + (md_begin, dot_alias): Likewise. + * config/tc-m68hc11.c (md_begin): Likewise. + * config/tc-m68k.c (md_begin): Likewise. + * config/tc-mcore.c (md_begin): Likewise. + * config/tc-microblaze.c (md_begin): Likewise. + * config/tc-mips.c (md_begin): Likewise. + * config/tc-mmix.c (md_begin): Likewise. + * config/tc-mn10200.c (md_begin): Likewise. + * config/tc-mn10300.c (md_begin): Likewise. + * config/tc-moxie.c (md_begin): Likewise. + * config/tc-nds32.c (nds32_relax_hint, md_begin): Likewise. + * config/tc-nios2.c (md_begin): Likewise. + * config/tc-ns32k.c (md_begin): Likewise. + * config/tc-pdp11.c (md_begin): Likewise. + * config/tc-pj.c (fake_opcode, md_begin): Likewise. + * config/tc-ppc.c (ppc_setup_opcodes): Likewise. + * config/tc-pru.c (md_begin): Likewise. + * config/tc-riscv.c (init_ext_version_hash): Likewise. + (init_opcode_names_hash, hash_reg_name, init_opcode_hash): Likewise. + (riscv_init_csr_hash): Likewise. + * config/tc-s390.c (s390_setup_opcodes, md_begin): 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, s7_insert_reg): Likewise. + * config/tc-sh.c (md_begin): Likewise. + * config/tc-sparc.c (md_begin): Likewise. + * config/tc-spu.c (md_begin): Likewise. + * config/tc-tic30.c (md_begin): Likewise. + * config/tc-tic4x.c (tic4x_inst_insert): Likewise. + * config/tc-tic54x.c (stag_add_field_symbols, md_begin): Likewise. + (tic54x_endstruct, tic54x_var, tic54x_macro_info): Likewise. + (subsym_substitute): Likewise. + * config/tc-tilegx.c (md_begin): Likewise. + * config/tc-tilepro.c (md_begin): Likewise. + * config/tc-vax.c (vip_begin): Likewise. + * config/tc-wasm32.c (md_begin): Likewise. + * config/tc-xgate.c (md_begin): Likewise. + * config/tc-z8k.c (md_begin): Likewise. + * testsuite/gas/ppc/dcbt.d, + * testsuite/gas/ppc/dcbt.s: New test. + * testsuite/gas/ppc/ppc.exp: Run it. + + * ecoff.c (add_string): Report fatal error on duplicates. + * config/tc-alpha.c (md_begin): Likewise. + * config/tc-arc.c (arc_insert_opcode, declare_register): Likewise. + (declare_addrtype, md_begin, arc_extcorereg): Likewise. + * config/tc-cr16.c (initialise_reg_hash_table, md_begin): Likewise. + * config/tc-cris.c (md_begin): Likewise. + * config/tc-crx.c (md_begin): Likewise. + * config/tc-dlx.c (md_begin): Likewise. + * config/tc-hppa.c (md_begin): Likewise. + * config/tc-i386.c (md_begin): Likewise. + * config/tc-ia64.c (dot_rot, dot_entry, declare_register): Likewise. + (md_begin): Likewise. + * config/tc-m68k.c (md_begin): Likewise. + * config/tc-mips.c (md_begin): Likewise. + * config/tc-nios2.c (md_begin): Likewise. + * config/tc-ns32k.c (md_begin): Likewise. + * config/tc-ppc.c (ppc_setup_opcodes): Likewise. + * config/tc-pru.c (md_begin): Likewise. + * config/tc-riscv.c (init_ext_version_hash): Likewise. + (init_opcode_names_hash, hash_reg_name, init_opcode_hash): Likewise. + * config/tc-s390.c (s390_setup_opcodes, md_begin): Likewise. + * config/tc-sparc.c (md_begin): Likewise. + * config/tc-tic30.c (md_begin): Likewise. + * config/tc-tic4x.c (tic4x_inst_insert): Likewise. + * config/tc-tilegx.c (md_begin): Likewise. + * config/tc-tilepro.c (md_begin): Likewise. + * config/tc-vax.c (vip_begin): Likewise. + + * config/tc-alpha.c, + * config/tc-arm.c, + * config/tc-avr.c, + * config/tc-cr16.c, + * config/tc-csky.c, + * config/tc-i386.c, + * config/tc-m68hc11.c, + * config/tc-m68k.c, + * config/tc-microblaze.c, + * config/tc-ns32k.c, + * config/tc-pj.c, + * config/tc-ppc.c, + * config/tc-score.c, + * config/tc-score7.c, + * config/tc-tic4x.c, + * config/tc-tic54x.c, + * config/tc-tilegx.c, + * config/tc-tilepro.c, + * config/tc-xgate.c: Formatting. + 2020-08-21 Alan Modra <amodra@gmail.com> * symbols.c (struct local_symbol): Add "hash" entry. Reorder fields. diff --git a/gas/config/obj-coff-seh.c b/gas/config/obj-coff-seh.c index 6a7ea9c..d4421d4 100644 --- a/gas/config/obj-coff-seh.c +++ b/gas/config/obj-coff-seh.c @@ -116,7 +116,7 @@ make_pxdata_seg (segT cseg, char *name) static void seh_hash_insert (const char *name, struct seh_seg_list *item) { - str_hash_insert (seh_hash, name, (char *) item); + str_hash_insert (seh_hash, name, item, 1); } static struct seh_seg_list * diff --git a/gas/config/obj-coff.c b/gas/config/obj-coff.c index 7e26e58..a0a30f4 100644 --- a/gas/config/obj-coff.c +++ b/gas/config/obj-coff.c @@ -128,7 +128,7 @@ tag_init (void) static void tag_insert (const char *name, symbolS *symbolP) { - str_hash_insert (tag_hash, name, (char *) symbolP); + str_hash_insert (tag_hash, name, symbolP, 1); } static symbolS * diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c index f169187..9e39707 100644 --- a/gas/config/obj-elf.c +++ b/gas/config/obj-elf.c @@ -2653,7 +2653,7 @@ build_additional_section_info (bfd *abfd ATTRIBUTE_UNUSED, /* Add index to hash. */ idx_ptr = XNEW (unsigned int); *idx_ptr = i; - str_hash_insert (list->indexes, group_name, (char *)idx_ptr); + str_hash_insert (list->indexes, group_name, idx_ptr, 0); } static int diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c index c7cae1a..2387927 100644 --- a/gas/config/tc-aarch64.c +++ b/gas/config/tc-aarch64.c @@ -1337,7 +1337,7 @@ insert_reg_alias (char *str, int number, aarch64_reg_type type) new->type = type; new->builtin = FALSE; - str_hash_insert (aarch64_reg_hsh, name, (void *) new); + str_hash_insert (aarch64_reg_hsh, name, new, 0); return new; } @@ -8622,7 +8622,7 @@ aarch64_adjust_symtab (void) static void checked_hash_insert (htab_t table, const char *key, void *value) { - str_hash_insert (table, key, value); + str_hash_insert (table, key, value, 0); } static void diff --git a/gas/config/tc-alpha.c b/gas/config/tc-alpha.c index 4810734..06432bf 100644 --- a/gas/config/tc-alpha.c +++ b/gas/config/tc-alpha.c @@ -600,7 +600,7 @@ get_alpha_reloc_tag (long sequence) info->segment = now_seg; info->sequence = sequence; strcpy (info->string, buffer); - str_hash_insert (alpha_literal_hash, info->string, (void *) info); + str_hash_insert (alpha_literal_hash, info->string, info, 0); #ifdef OBJ_EVAX info->sym = 0; info->psym = 0; @@ -1168,7 +1168,8 @@ assemble_tokens_to_insn (const char *opname, const struct alpha_opcode *opcode; /* Search opcodes. */ - opcode = (const struct alpha_opcode *) str_hash_find (alpha_opcode_hash, opname); + opcode = (const struct alpha_opcode *) str_hash_find (alpha_opcode_hash, + opname); if (opcode) { int cpumatch; @@ -3315,8 +3316,8 @@ assemble_tokens (const char *opname, #endif if (local_macros_on) { - macro = ((const struct alpha_macro *) - str_hash_find (alpha_macro_hash, opname)); + macro = (const struct alpha_macro *) str_hash_find (alpha_macro_hash, + opname); if (macro) { found_something = 1; @@ -3330,7 +3331,8 @@ assemble_tokens (const char *opname, } /* Search opcodes. */ - opcode = (const struct alpha_opcode *) str_hash_find (alpha_opcode_hash, opname); + opcode = (const struct alpha_opcode *) str_hash_find (alpha_opcode_hash, + opname); if (opcode) { found_something = 1; @@ -5422,7 +5424,8 @@ md_begin (void) const char *name, *slash; name = alpha_opcodes[i].name; - str_hash_insert (alpha_opcode_hash, name, (void *) &alpha_opcodes[i]); + if (str_hash_insert (alpha_opcode_hash, name, &alpha_opcodes[i], 0)) + as_fatal (_("duplicate %s"), name); /* Some opcodes include modifiers of various sorts with a "/mod" syntax, like the architecture manual suggests. However, for @@ -5436,7 +5439,7 @@ md_begin (void) memcpy (p, name, slash - name); strcpy (p + (slash - name), slash + 1); - (void) str_hash_insert (alpha_opcode_hash, p, (void *) &alpha_opcodes[i]); + (void) str_hash_insert (alpha_opcode_hash, p, &alpha_opcodes[i], 0); /* Ignore failures -- the opcode table does duplicate some variants in different forms, like "hw_stq" and "hw_st/q". */ } @@ -5455,7 +5458,8 @@ md_begin (void) const char *name; name = alpha_macros[i].name; - str_hash_insert (alpha_macro_hash, name, (void *) &alpha_macros[i]); + if (str_hash_insert (alpha_macro_hash, name, &alpha_macros[i], 0)) + as_fatal (_("duplicate %s"), name); while (++i < alpha_num_macros && (alpha_macros[i].name == name diff --git a/gas/config/tc-arc.c b/gas/config/tc-arc.c index 0232b3d..36a0898 100644 --- a/gas/config/tc-arc.c +++ b/gas/config/tc-arc.c @@ -765,7 +765,8 @@ arc_insert_opcode (const struct arc_opcode *opcode) entry->count = 0; entry->opcode = NULL; - str_hash_insert (arc_opcode_hash, name, (void *) entry); + if (str_hash_insert (arc_opcode_hash, name, entry, 0) != NULL) + as_fatal (_("duplicate %s"), name); } entry->opcode = XRESIZEVEC (const struct arc_opcode *, entry->opcode, @@ -2552,7 +2553,8 @@ declare_register (const char *name, int number) symbolS *regS = symbol_create (name, reg_section, &zero_address_frag, number); - str_hash_insert (arc_reg_hash, S_GET_NAME (regS), (void *) regS); + if (str_hash_insert (arc_reg_hash, S_GET_NAME (regS), regS, 0) != NULL) + as_fatal (_("duplicate %s"), name); } /* Construct symbols for each of the general registers. */ @@ -2583,8 +2585,8 @@ declare_addrtype (const char *name, int number) symbolS *addrtypeS = symbol_create (name, undefined_section, &zero_address_frag, number); - str_hash_insert (arc_addrtype_hash, S_GET_NAME (addrtypeS), - (void *) addrtypeS); + if (str_hash_insert (arc_addrtype_hash, S_GET_NAME (addrtypeS), addrtypeS, 0)) + as_fatal (_("duplicate %s"), name); } /* Port-specific assembler initialization. This function is called @@ -2694,7 +2696,8 @@ md_begin (void) && !check_cpu_feature (auxr->subclass)) continue; - str_hash_insert (arc_aux_hash, auxr->name, (void *) auxr); + if (str_hash_insert (arc_aux_hash, auxr->name, auxr, 0) != 0) + as_fatal (_("duplicate %s"), auxr->name); } /* Address type declaration. */ @@ -4889,7 +4892,8 @@ arc_extcorereg (int opertype) auxr->cpu = selected_cpu.flags; auxr->subclass = NONE; auxr->address = ereg.number; - str_hash_insert (arc_aux_hash, auxr->name, (void *) auxr); + if (str_hash_insert (arc_aux_hash, auxr->name, auxr, 0) != NULL) + as_bad (_("duplicate aux register %s"), auxr->name); break; case EXT_COND_CODE: /* Condition code. */ diff --git a/gas/config/tc-arm.c b/gas/config/tc-arm.c index ce2dd0e..c5ad260 100644 --- a/gas/config/tc-arm.c +++ b/gas/config/tc-arm.c @@ -2583,7 +2583,7 @@ insert_reg_alias (char *str, unsigned number, int type) new_reg->builtin = FALSE; new_reg->neon = NULL; - str_hash_insert (arm_reg_hsh, name, new_reg); + str_hash_insert (arm_reg_hsh, name, new_reg, 0); return new_reg; } @@ -2883,8 +2883,8 @@ s_unreq (int a ATTRIBUTE_UNUSED) as_bad (_("invalid syntax for .unreq directive")); else { - struct reg_entry *reg = (struct reg_entry *) str_hash_find (arm_reg_hsh, - name); + struct reg_entry *reg + = (struct reg_entry *) str_hash_find (arm_reg_hsh, name); if (!reg) as_bad (_("unknown register alias '%s'"), name); @@ -5536,8 +5536,9 @@ parse_shift (char **str, int i, enum parse_shift_mode mode) return FAIL; } - shift_name = (const struct asm_shift_name *) str_hash_find_n (arm_shift_hsh, *str, - p - *str); + shift_name + = (const struct asm_shift_name *) str_hash_find_n (arm_shift_hsh, *str, + p - *str); if (shift_name == NULL) { @@ -6338,7 +6339,7 @@ parse_psr (char **str, bfd_boolean lhs) p = start + strcspn (start, "rR") + 1; psr = (const struct asm_psr *) str_hash_find_n (arm_v7m_psr_hsh, start, - p - start); + p - start); if (!psr) return FAIL; @@ -6441,7 +6442,7 @@ parse_psr (char **str, bfd_boolean lhs) else { psr = (const struct asm_psr *) str_hash_find_n (arm_psr_hsh, start, - p - start); + p - start); if (!psr) goto error; @@ -6656,7 +6657,7 @@ parse_barrier (char **str) q++; o = (const struct asm_barrier_opt *) str_hash_find_n (arm_barrier_opt_hsh, p, - q - p); + q - p); if (!o) return FAIL; @@ -22620,7 +22621,7 @@ opcode_lookup (char **str) /* Look for unaffixed or special-case affixed mnemonic. */ opcode = (const struct asm_opcode *) str_hash_find_n (arm_ops_hsh, base, - end - base); + end - base); if (opcode) { /* step U */ @@ -22648,7 +22649,7 @@ opcode_lookup (char **str) affix = end - 1; cond = (const struct asm_cond *) str_hash_find_n (arm_vcond_hsh, affix, 1); opcode = (const struct asm_opcode *) str_hash_find_n (arm_ops_hsh, base, - affix - base); + affix - base); /* If this opcode can not be vector predicated then don't accept it with a vector predication code. */ if (opcode && !opcode->mayBeVecPred) @@ -22665,7 +22666,7 @@ opcode_lookup (char **str) affix = end - 2; cond = (const struct asm_cond *) str_hash_find_n (arm_cond_hsh, affix, 2); opcode = (const struct asm_opcode *) str_hash_find_n (arm_ops_hsh, base, - affix - base); + affix - base); } if (opcode && cond) @@ -22721,7 +22722,7 @@ opcode_lookup (char **str) memcpy (save, affix, 2); memmove (affix, affix + 2, (end - affix) - 2); opcode = (const struct asm_opcode *) str_hash_find_n (arm_ops_hsh, base, - (end - base) - 2); + (end - base) - 2); memmove (affix + 2, affix, (end - affix) - 2); memcpy (affix, save, 2); @@ -27999,7 +28000,7 @@ arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name) if (str_hash_find (already_warned, nbuf) == NULL) { as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name); - str_hash_insert (already_warned, nbuf, NULL); + str_hash_insert (already_warned, nbuf, NULL, 0); } } else @@ -30731,25 +30732,25 @@ md_begin (void) for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++) if (str_hash_find (arm_ops_hsh, insns[i].template_name) == NULL) - str_hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i)); + str_hash_insert (arm_ops_hsh, insns[i].template_name, insns + i, 0); for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++) - str_hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i)); + str_hash_insert (arm_cond_hsh, conds[i].template_name, conds + i, 0); for (i = 0; i < sizeof (vconds) / sizeof (struct asm_cond); i++) - str_hash_insert (arm_vcond_hsh, vconds[i].template_name, (void *) (vconds + i)); + str_hash_insert (arm_vcond_hsh, vconds[i].template_name, vconds + i, 0); for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++) - str_hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i)); + str_hash_insert (arm_shift_hsh, shift_names[i].name, shift_names + i, 0); for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++) - str_hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i)); + str_hash_insert (arm_psr_hsh, psrs[i].template_name, psrs + i, 0); for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++) str_hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name, - (void *) (v7m_psrs + i)); + v7m_psrs + i, 0); for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++) - str_hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i)); + str_hash_insert (arm_reg_hsh, reg_names[i].name, reg_names + i, 0); for (i = 0; i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt); i++) str_hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name, - (void *) (barrier_opt_names + i)); + barrier_opt_names + i, 0); #ifdef OBJ_ELF for (i = 0; i < ARRAY_SIZE (reloc_names); i++) { @@ -30759,7 +30760,7 @@ md_begin (void) /* This makes encode_branch() use the EABI versions of this relocation. */ entry->reloc = BFD_RELOC_UNUSED; - str_hash_insert (arm_reloc_hsh, entry->name, (void *) entry); + str_hash_insert (arm_reloc_hsh, entry->name, entry, 0); } #endif diff --git a/gas/config/tc-avr.c b/gas/config/tc-avr.c index 157eb9b..0dcc9f8 100644 --- a/gas/config/tc-avr.c +++ b/gas/config/tc-avr.c @@ -814,8 +814,7 @@ md_begin (void) quick index to the first opcode with a particular name in the opcode table. */ for (opcode = avr_opcodes; opcode->name; opcode++) - if (str_hash_find (avr_hash, opcode->name) == NULL) - str_hash_insert (avr_hash, opcode->name, (char *) opcode); + str_hash_insert (avr_hash, opcode->name, opcode, 0); avr_mod_hash = str_htab_create (); @@ -824,8 +823,7 @@ md_begin (void) mod_index m; m.index = i + 10; - str_hash_find (avr_mod_hash, EXP_MOD_NAME (i)); - str_hash_insert (avr_mod_hash, EXP_MOD_NAME (i), m.ptr); + str_hash_insert (avr_mod_hash, EXP_MOD_NAME (i), m.ptr, 0); } avr_no_sreg_hash = str_htab_create (); @@ -833,10 +831,12 @@ md_begin (void) for (i = 0; i < ARRAY_SIZE (avr_no_sreg); ++i) { gas_assert (str_hash_find (avr_hash, avr_no_sreg[i])); - str_hash_insert (avr_no_sreg_hash, avr_no_sreg[i], (char*) 4 /* dummy */); + str_hash_insert (avr_no_sreg_hash, avr_no_sreg[i], + (void *) 4 /* dummy */, 0); } - avr_gccisr_opcode = (struct avr_opcodes_s*) str_hash_find (avr_hash, "__gcc_isr"); + avr_gccisr_opcode = (struct avr_opcodes_s*) str_hash_find (avr_hash, + "__gcc_isr"); gas_assert (avr_gccisr_opcode); bfd_set_arch_mach (stdoutput, TARGET_ARCH, avr_mcu->mach); diff --git a/gas/config/tc-cr16.c b/gas/config/tc-cr16.c index e5db874..c0627ff 100644 --- a/gas/config/tc-cr16.c +++ b/gas/config/tc-cr16.c @@ -794,18 +794,21 @@ md_pcrel_from (fixS *fixp) } static void -initialise_reg_hash_table (htab_t * hash_table, - const reg_entry * register_table, - const unsigned int num_entries) +initialise_reg_hash_table (htab_t *hash_table, + const reg_entry *register_table, + const unsigned int num_entries) { - const reg_entry * rreg; - if ((* hash_table = str_htab_create ()) == NULL) + const reg_entry *rreg; + + *hash_table = str_htab_create (); + if (*hash_table == NULL) as_fatal (_("Virtual memory exhausted")); for (rreg = register_table; rreg < (register_table + num_entries); rreg++) - str_hash_insert (* hash_table, rreg->name, (char *) rreg); + if (str_hash_insert (*hash_table, rreg->name, rreg, 0) != NULL) + as_fatal (_("duplicate %s"), rreg->name); } /* This function is called once, at assembler startup time. This should @@ -824,8 +827,9 @@ md_begin (void) { const char *mnemonic = cr16_instruction[i].mnemonic; - str_hash_insert (cr16_inst_hash, mnemonic, - (char *)(cr16_instruction + i)); + if (str_hash_insert (cr16_inst_hash, mnemonic, cr16_instruction + i, 0)) + as_fatal (_("duplicate %s"), mnemonic); + /* Insert unique names into hash table. The CR16 instruction set has many identical opcode names that have different opcodes based on the operands. This hash table then provides a quick index to diff --git a/gas/config/tc-cris.c b/gas/config/tc-cris.c index 1231084..873f28b 100644 --- a/gas/config/tc-cris.c +++ b/gas/config/tc-cris.c @@ -1221,8 +1221,9 @@ md_begin (void) continue; } - /* Need to cast to get rid of "const". FIXME: Fix str_hash_insert instead. */ - str_hash_insert (op_hash, name, (void *) &cris_opcodes[i]); + if (str_hash_insert (op_hash, name, &cris_opcodes[i], 0) != NULL) + as_fatal (_("duplicate %s"), name); + do { if (cris_opcodes[i].match & cris_opcodes[i].lose) diff --git a/gas/config/tc-crx.c b/gas/config/tc-crx.c index 2757db8..10f3880 100644 --- a/gas/config/tc-crx.c +++ b/gas/config/tc-crx.c @@ -537,8 +537,8 @@ md_begin (void) { const char *mnemonic = crx_instruction[i].mnemonic; - str_hash_insert (crx_inst_hash, mnemonic, - (void *) &crx_instruction[i]); + if (str_hash_insert (crx_inst_hash, mnemonic, &crx_instruction[i], 0)) + as_fatal (_("duplicate %s"), mnemonic); /* Insert unique names into hash table. The CRX instruction set has many identical opcode names that have different opcodes based @@ -561,7 +561,8 @@ md_begin (void) for (regtab = crx_regtab; regtab < (crx_regtab + NUMREGS); regtab++) - str_hash_insert (reg_hash, regtab->name, (void *) regtab); + if (str_hash_insert (reg_hash, regtab->name, regtab, 0) != NULL) + as_fatal (_("duplicate %s"), regtab->name); } /* Initialize copreg_hash hash table. */ @@ -573,8 +574,8 @@ md_begin (void) for (copregtab = crx_copregtab; copregtab < (crx_copregtab + NUMCOPREGS); copregtab++) - str_hash_insert (copreg_hash, copregtab->name, - (void *) copregtab); + if (str_hash_insert (copreg_hash, copregtab->name, copregtab, 0) != NULL) + as_fatal (_("duplicate %s"), copregtab->name); } /* Set linkrelax here to avoid fixups in most sections. */ linkrelax = 1; diff --git a/gas/config/tc-csky.c b/gas/config/tc-csky.c index ec1ea94..5f536f4 100644 --- a/gas/config/tc-csky.c +++ b/gas/config/tc-csky.c @@ -1361,14 +1361,13 @@ md_begin (void) csky_opcodes_hash = str_htab_create (); for ( ; opcode->mnemonic != NULL; opcode++) if ((isa_flag & (opcode->isa_flag16 | opcode->isa_flag32)) != 0) - str_hash_insert (csky_opcodes_hash, opcode->mnemonic, (char *)opcode); + str_hash_insert (csky_opcodes_hash, opcode->mnemonic, opcode, 0); for ( ; macro->name != NULL; macro++) if ((isa_flag & macro->isa_flag) != 0) - str_hash_insert (csky_macros_hash, macro->name, (char *)macro); + str_hash_insert (csky_macros_hash, macro->name, macro, 0); if (do_nolrw && (isa_flag & CSKYV2_ISA_1E2) != 0) str_hash_insert (csky_macros_hash, - v2_lrw_macro_opcode.name, - (char *)&v2_lrw_macro_opcode); + v2_lrw_macro_opcode.name, &v2_lrw_macro_opcode, 0); /* Set e_flag to ELF Head. */ bfd_set_private_flags (stdoutput, mach_flag); /* Set bfd_mach to bfd backend data. */ @@ -2935,9 +2934,9 @@ parse_opcode (char *str) /* Find hash by name in csky_macros_hash and csky_opcodes_hash. */ csky_insn.macro = (struct csky_macro_info *) str_hash_find (csky_macros_hash, - macro_name); + macro_name); csky_insn.opcode = (struct csky_opcode *) str_hash_find (csky_opcodes_hash, - name); + name); if (csky_insn.macro == NULL && csky_insn.opcode == NULL) return FALSE; diff --git a/gas/config/tc-d10v.c b/gas/config/tc-d10v.c index bc87dc6..dd30b7f 100644 --- a/gas/config/tc-d10v.c +++ b/gas/config/tc-d10v.c @@ -289,7 +289,7 @@ md_begin (void) if (strcmp (prev_name, opcode->name)) { prev_name = (char *) opcode->name; - str_hash_insert (d10v_hash, opcode->name, (char *) opcode); + str_hash_insert (d10v_hash, opcode->name, opcode, 0); } } diff --git a/gas/config/tc-d30v.c b/gas/config/tc-d30v.c index 1e06bea..9f0b0eb 100644 --- a/gas/config/tc-d30v.c +++ b/gas/config/tc-d30v.c @@ -314,7 +314,7 @@ md_begin (void) /* Insert opcode names into a hash table. */ for (opcode = (struct d30v_opcode *) d30v_opcode_table; opcode->name; opcode++) - str_hash_insert (d30v_hash, opcode->name, (char *) opcode); + str_hash_insert (d30v_hash, opcode->name, opcode, 0); fixups = &FixUps[0]; FixUps[0].next = &FixUps[1]; diff --git a/gas/config/tc-dlx.c b/gas/config/tc-dlx.c index 51e7065..aacf044 100644 --- a/gas/config/tc-dlx.c +++ b/gas/config/tc-dlx.c @@ -285,7 +285,8 @@ md_begin (void) for (i = 0; i < num_dlx_opcodes; i++) { const char *name = machine_opcodes[i].name; - str_hash_insert (op_hash, name, (void *) &machine_opcodes[i]); + if (str_hash_insert (op_hash, name, &machine_opcodes[i], 0) != NULL) + as_fatal (_("duplicate %s"), name); } define_some_regs (); diff --git a/gas/config/tc-ft32.c b/gas/config/tc-ft32.c index fc3b181..7db5683 100644 --- a/gas/config/tc-ft32.c +++ b/gas/config/tc-ft32.c @@ -58,7 +58,7 @@ md_begin (void) /* Insert names into hash table. */ for (opcode = ft32_opc_info; opcode->name; opcode++) - str_hash_insert (opcode_hash_control, opcode->name, (char *) opcode); + str_hash_insert (opcode_hash_control, opcode->name, opcode, 0); bfd_set_arch_mach (stdoutput, TARGET_ARCH, 0); if (!norelax) diff --git a/gas/config/tc-h8300.c b/gas/config/tc-h8300.c index cbde92e..d675af5 100644 --- a/gas/config/tc-h8300.c +++ b/gas/config/tc-h8300.c @@ -283,7 +283,7 @@ md_begin (void) len = dst - buffer; if (cmplen == 0) cmplen = len; - str_hash_insert (opcode_hash_control, buffer, (char *) pi); + str_hash_insert (opcode_hash_control, buffer, pi, 0); strcpy (prev_buffer, buffer); idx++; diff --git a/gas/config/tc-hppa.c b/gas/config/tc-hppa.c index 1feebc8..4056178 100644 --- a/gas/config/tc-hppa.c +++ b/gas/config/tc-hppa.c @@ -8242,7 +8242,8 @@ md_begin (void) { const char *name = pa_opcodes[i].name; - str_hash_insert (op_hash, name, (void *)&pa_opcodes[i]); + if (str_hash_insert (op_hash, name, &pa_opcodes[i], 0) != NULL) + as_fatal (_("duplicate %s"), name); do { diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c index 43eb365..d237352 100644 --- a/gas/config/tc-i386.c +++ b/gas/config/tc-i386.c @@ -3050,7 +3050,9 @@ md_begin (void) /* different name --> ship out current template list; add to hash table; & begin anew. */ core_optab->end = optab; - str_hash_insert (op_hash, (optab - 1)->name, (void *) core_optab); + if (str_hash_insert (op_hash, (optab - 1)->name, core_optab, 0)) + as_fatal (_("duplicate %s"), (optab - 1)->name); + if (optab->name == NULL) break; core_optab = XNEW (templates); @@ -3066,7 +3068,8 @@ md_begin (void) unsigned int regtab_size = i386_regtab_size; for (regtab = i386_regtab; regtab_size--; regtab++) - str_hash_insert (reg_hash, regtab->reg_name, (void *) regtab); + if (str_hash_insert (reg_hash, regtab->reg_name, regtab, 0) != NULL) + as_fatal (_("duplicate %s"), regtab->reg_name); } /* Fill in lexical tables: mnemonic_chars, operand_chars. */ @@ -5218,8 +5221,8 @@ parse_insn (char *line, char *mnemonic) case QWORD_MNEM_SUFFIX: i.suffix = mnem_p[-1]; mnem_p[-1] = '\0'; - current_templates = (const templates *) str_hash_find (op_hash, - mnemonic); + current_templates + = (const templates *) str_hash_find (op_hash, mnemonic); break; case SHORT_MNEM_SUFFIX: case LONG_MNEM_SUFFIX: @@ -5227,8 +5230,8 @@ parse_insn (char *line, char *mnemonic) { i.suffix = mnem_p[-1]; mnem_p[-1] = '\0'; - current_templates = (const templates *) str_hash_find (op_hash, - mnemonic); + current_templates + = (const templates *) str_hash_find (op_hash, mnemonic); } break; @@ -5241,8 +5244,8 @@ parse_insn (char *line, char *mnemonic) else i.suffix = LONG_MNEM_SUFFIX; mnem_p[-1] = '\0'; - current_templates = (const templates *) str_hash_find (op_hash, - mnemonic); + current_templates + = (const templates *) str_hash_find (op_hash, mnemonic); } break; } @@ -10968,10 +10971,13 @@ i386_index_check (const char *operand_string) && current_templates->end[-1].operand_types[1] .bitfield.baseindex)) op = 1; - expected_reg = (const reg_entry *)str_hash_find (reg_hash, di_si[addr_mode][op == es_op]); + expected_reg + = (const reg_entry *) str_hash_find (reg_hash, + di_si[addr_mode][op == es_op]); } else - expected_reg = (const reg_entry *)str_hash_find (reg_hash, bx[addr_mode]); + expected_reg + = (const reg_entry *)str_hash_find (reg_hash, bx[addr_mode]); if (i.base_reg != expected_reg || i.index_reg diff --git a/gas/config/tc-ia64.c b/gas/config/tc-ia64.c index ed4636b..f827e45 100644 --- a/gas/config/tc-ia64.c +++ b/gas/config/tc-ia64.c @@ -4684,7 +4684,12 @@ dot_rot (int type) drpp = &dr->next; base_reg += num_regs; - str_hash_insert (md.dynreg_hash, name, dr); + 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; + } if (*input_line_pointer != ',') break; @@ -5171,7 +5176,8 @@ dot_entry (int dummy ATTRIBUTE_UNUSED) c = get_symbol_name (&name); symbolP = symbol_find_or_make (name); - str_hash_insert (md.entry_hash, S_GET_NAME (symbolP), (void *) symbolP); + if (str_hash_insert (md.entry_hash, S_GET_NAME (symbolP), symbolP, 0)) + as_bad (_("duplicate entry hint %s"), name); *input_line_pointer = c; SKIP_WHITESPACE_AFTER_NAME (); @@ -5374,7 +5380,8 @@ declare_register (const char *name, unsigned int regnum) sym = symbol_create (name, reg_section, &zero_address_frag, regnum); - str_hash_insert (md.reg_hash, S_GET_NAME (sym), (void *) sym); + if (str_hash_insert (md.reg_hash, S_GET_NAME (sym), sym, 0) != NULL) + as_fatal (_("duplicate %s"), name); return sym; } @@ -7393,8 +7400,9 @@ md_begin (void) md.pseudo_hash = str_htab_create (); for (i = 0; i < NELEMS (pseudo_opcode); ++i) - str_hash_insert (md.pseudo_hash, pseudo_opcode[i].name, - (void *) (pseudo_opcode + i)); + if (str_hash_insert (md.pseudo_hash, pseudo_opcode[i].name, + pseudo_opcode + i, 0) != NULL) + as_fatal (_("duplicate %s"), pseudo_opcode[i].name); md.reg_hash = str_htab_create (); md.dynreg_hash = str_htab_create (); @@ -7452,8 +7460,8 @@ md_begin (void) declare_register ("psp", REG_PSP); for (i = 0; i < NELEMS (const_bits); ++i) - str_hash_insert (md.const_hash, const_bits[i].name, - (void *) (const_bits + i)); + if (str_hash_insert (md.const_hash, const_bits[i].name, const_bits + i, 0)) + as_fatal (_("duplicate %s"), const_bits[i].name); /* Set the architecture and machine depending on defaults and command line options. */ @@ -11812,8 +11820,8 @@ dot_alias (int section) h->file = as_where (&h->line); h->name = name; - str_hash_insert (ahash, alias, (void *) h); - str_hash_insert (nhash, name, (void *) alias); + str_hash_insert (ahash, alias, h, 0); + str_hash_insert (nhash, name, alias, 0); out: demand_empty_rest_of_line (); diff --git a/gas/config/tc-iq2000.c b/gas/config/tc-iq2000.c index 3df8994..82ae9c2 100644 --- a/gas/config/tc-iq2000.c +++ b/gas/config/tc-iq2000.c @@ -277,7 +277,8 @@ iq2000_add_macro (const char * name, /* Add to macro's hash table. */ htab_insert (macro->formal_hash, formal_entry_alloc (sb_terminate (& formal->name), - formal)); + formal), + 1); formal->index = macro->formal_count; macro->formal_count++; *p = formal; @@ -289,7 +290,7 @@ iq2000_add_macro (const char * name, sb_add_string (¯o_name, name); namestr = sb_terminate (¯o_name); - htab_insert (macro_hash, macro_entry_alloc (namestr, macro)); + htab_insert (macro_hash, macro_entry_alloc (namestr, macro), 1); macro_defined = 1; } diff --git a/gas/config/tc-m68hc11.c b/gas/config/tc-m68hc11.c index 0956e7a..5735ff8 100644 --- a/gas/config/tc-m68hc11.c +++ b/gas/config/tc-m68hc11.c @@ -664,7 +664,7 @@ md_begin (void) opc->nb_modes = 0; opc->opcode = opcodes; opc->used = 0; - str_hash_insert (m68hc11_hash, opcodes->name, opc); + str_hash_insert (m68hc11_hash, opcodes->name, opc, 0); } opc->nb_modes++; opc->format |= opcodes->format; @@ -3477,7 +3477,8 @@ md_assemble (char *str) is given. */ if (opc == NULL && name[0] == 'j' && name[1] == 'b') { - opc = (struct m68hc11_opcode_def *) str_hash_find (m68hc11_hash, &name[1]); + opc = (struct m68hc11_opcode_def *) str_hash_find (m68hc11_hash, + &name[1]); if (opc && (!(opc->format & M6811_OP_JUMP_REL) || (opc->format & M6811_OP_BITMASK))) @@ -3509,7 +3510,7 @@ md_assemble (char *str) name[nlen++] = TOLOWER (*op_end++); name[nlen] = 0; opc = (struct m68hc11_opcode_def *) str_hash_find (m68hc11_hash, - name); + name); } } } diff --git a/gas/config/tc-m68k.c b/gas/config/tc-m68k.c index 2416652..7a3ccc4 100644 --- a/gas/config/tc-m68k.c +++ b/gas/config/tc-m68k.c @@ -4570,18 +4570,20 @@ md_begin (void) } while (slak); - str_hash_insert (op_hash, ins->name, (char *) hack); + if (str_hash_insert (op_hash, ins->name, hack, 0) != NULL) + as_fatal (_("duplicate %s"), ins->name); } for (i = 0; i < m68k_numaliases; i++) { const char *name = m68k_opcode_aliases[i].primary; const char *alias = m68k_opcode_aliases[i].alias; - void *val = (void *)str_hash_find (op_hash, name); + void *val = (void *) str_hash_find (op_hash, name); if (!val) as_fatal (_("Internal Error: Can't find %s in hash table"), name); - str_hash_insert (op_hash, alias, val); + if (str_hash_insert (op_hash, alias, val, 0) != NULL) + as_fatal (_("duplicate %s"), alias); } /* In MRI mode, all unsized branches are variable sized. Normally, @@ -4614,11 +4616,11 @@ md_begin (void) { const char *name = mri_aliases[i].primary; const char *alias = mri_aliases[i].alias; - void *val = (void *)str_hash_find (op_hash, name); + void *val = (void *) str_hash_find (op_hash, name); if (!val) as_fatal (_("Internal Error: Can't find %s in hash table"), name); - str_hash_insert (op_hash, alias, val); + str_hash_insert (op_hash, alias, val, 1); } } @@ -4674,7 +4676,7 @@ md_begin (void) { hack = XOBNEW (&robyn, struct m68k_incant); str_hash_insert (op_hash, - mote_pseudo_table[n].poc_name, (char *) hack); + mote_pseudo_table[n].poc_name, hack, 0); hack->m_operands = 0; hack->m_opnum = n; n++; diff --git a/gas/config/tc-mcore.c b/gas/config/tc-mcore.c index a0927db..57300db 100644 --- a/gas/config/tc-mcore.c +++ b/gas/config/tc-mcore.c @@ -465,7 +465,8 @@ md_begin (void) if (! streq (prev_name, mcore_table[i].name)) { prev_name = mcore_table[i].name; - str_hash_insert (opcode_hash_control, mcore_table[i].name, (char *) &mcore_table[i]); + str_hash_insert (opcode_hash_control, mcore_table[i].name, + &mcore_table[i], 0); } } } diff --git a/gas/config/tc-microblaze.c b/gas/config/tc-microblaze.c index fe0c770..22316b6 100644 --- a/gas/config/tc-microblaze.c +++ b/gas/config/tc-microblaze.c @@ -417,7 +417,7 @@ md_begin (void) /* Insert unique names into hash table. */ for (opcode = opcodes; opcode->name; opcode ++) - str_hash_insert (opcode_hash_control, opcode->name, (char *) opcode); + str_hash_insert (opcode_hash_control, opcode->name, opcode, 0); } /* Try to parse a reg name. */ @@ -1072,9 +1072,13 @@ md_assemble (char * str) count = 32 - reg1; if (streq (name, "lmi")) - opcode = (struct op_code_struct *) str_hash_find (opcode_hash_control, "lwi"); + opcode + = (struct op_code_struct *) str_hash_find (opcode_hash_control, + "lwi"); else - opcode = (struct op_code_struct *) str_hash_find (opcode_hash_control, "swi"); + opcode + = (struct op_code_struct *) str_hash_find (opcode_hash_control, + "swi"); if (opcode == NULL) { as_bad (_("unknown opcode \"%s\""), "lwi"); @@ -1106,7 +1110,9 @@ md_assemble (char * str) if ((temp != 0) && (temp != 0xFFFF8000)) { /* Needs an immediate inst. */ - opcode1 = (struct op_code_struct *) str_hash_find (opcode_hash_control, "imm"); + opcode1 + = (struct op_code_struct *) str_hash_find (opcode_hash_control, + "imm"); if (opcode1 == NULL) { as_bad (_("unknown opcode \"%s\""), "imm"); @@ -1559,7 +1565,9 @@ md_assemble (char * str) if ((temp != 0) && (temp != 0xFFFF8000)) { /* Needs an immediate inst. */ - opcode1 = (struct op_code_struct *) str_hash_find (opcode_hash_control, "imm"); + opcode1 + = (struct op_code_struct *) str_hash_find (opcode_hash_control, + "imm"); if (opcode1 == NULL) { as_bad (_("unknown opcode \"%s\""), "imm"); @@ -1625,7 +1633,9 @@ md_assemble (char * str) if ((temp != 0) && (temp != 0xFFFF8000)) { /* Needs an immediate inst. */ - opcode1 = (struct op_code_struct *) str_hash_find (opcode_hash_control, "imm"); + opcode1 + = (struct op_code_struct *) str_hash_find (opcode_hash_control, + "imm"); if (opcode1 == NULL) { as_bad (_("unknown opcode \"%s\""), "imm"); @@ -1698,7 +1708,9 @@ md_assemble (char * str) if ((temp != 0) && (temp != 0xFFFF8000)) { /* Needs an immediate inst. */ - opcode1 = (struct op_code_struct *) str_hash_find (opcode_hash_control, "imm"); + opcode1 + = (struct op_code_struct *) str_hash_find (opcode_hash_control, + "imm"); if (opcode1 == NULL) { as_bad (_("unknown opcode \"%s\""), "imm"); @@ -2119,7 +2131,8 @@ md_apply_fix (fixS * fixP, buf[i + INST_WORD_SIZE] = buf[i]; /* Generate the imm instruction. */ - opcode1 = (struct op_code_struct *) str_hash_find (opcode_hash_control, "imm"); + opcode1 + = (struct op_code_struct *) str_hash_find (opcode_hash_control, "imm"); if (opcode1 == NULL) { as_bad (_("unknown opcode \"%s\""), "imm"); @@ -2167,7 +2180,8 @@ md_apply_fix (fixS * fixP, buf[i + INST_WORD_SIZE] = buf[i]; /* Generate the imm instruction. */ - opcode1 = (struct op_code_struct *) str_hash_find (opcode_hash_control, "imm"); + opcode1 + = (struct op_code_struct *) str_hash_find (opcode_hash_control, "imm"); if (opcode1 == NULL) { as_bad (_("unknown opcode \"%s\""), "imm"); diff --git a/gas/config/tc-mips.c b/gas/config/tc-mips.c index ebcc633..b178682 100644 --- a/gas/config/tc-mips.c +++ b/gas/config/tc-mips.c @@ -3694,7 +3694,8 @@ md_begin (void) { const char *name = mips_opcodes[i].name; - str_hash_insert (op_hash, name, (void *) &mips_opcodes[i]); + if (str_hash_insert (op_hash, name, &mips_opcodes[i], 0) != NULL) + as_fatal (_("duplicate %s"), name); do { if (!validate_mips_insn (&mips_opcodes[i], 0xffffffff, @@ -3726,7 +3727,8 @@ md_begin (void) { const char *name = mips16_opcodes[i].name; - str_hash_insert (mips16_op_hash, name, (void *) &mips16_opcodes[i]); + if (str_hash_insert (mips16_op_hash, name, &mips16_opcodes[i], 0)) + as_fatal (_("duplicate %s"), name); do { if (!validate_mips16_insn (&mips16_opcodes[i], &mips16_operands[i])) @@ -3751,8 +3753,8 @@ md_begin (void) { const char *name = micromips_opcodes[i].name; - str_hash_insert (micromips_op_hash, name, - (void *) µmips_opcodes[i]); + if (str_hash_insert (micromips_op_hash, name, µmips_opcodes[i], 0)) + as_fatal (_("duplicate %s"), name); do { struct mips_cl_insn *micromips_nop_insn; diff --git a/gas/config/tc-mmix.c b/gas/config/tc-mmix.c index 82a69f1..c469a62 100644 --- a/gas/config/tc-mmix.c +++ b/gas/config/tc-mmix.c @@ -775,7 +775,7 @@ mmix_md_begin (void) = bfd_make_section_old_way (stdoutput, MMIX_REG_SECTION_NAME); for (opcode = mmix_opcodes; opcode->name; opcode++) - str_hash_insert (mmix_opcode_hash, opcode->name, (char *) opcode); + str_hash_insert (mmix_opcode_hash, opcode->name, opcode, 0); /* We always insert the ordinary registers 0..255 as registers. */ for (i = 0; i < 256; i++) diff --git a/gas/config/tc-mn10200.c b/gas/config/tc-mn10200.c index 19cfc39..447f02a 100644 --- a/gas/config/tc-mn10200.c +++ b/gas/config/tc-mn10200.c @@ -698,7 +698,7 @@ md_begin (void) if (strcmp (prev_name, op->name)) { prev_name = (char *) op->name; - str_hash_insert (mn10200_hash, op->name, (char *) op); + str_hash_insert (mn10200_hash, op->name, op, 0); } op++; } diff --git a/gas/config/tc-mn10300.c b/gas/config/tc-mn10300.c index ae5ad9d..a2567e4 100644 --- a/gas/config/tc-mn10300.c +++ b/gas/config/tc-mn10300.c @@ -924,7 +924,7 @@ md_begin (void) if (strcmp (prev_name, op->name)) { prev_name = (char *) op->name; - str_hash_insert (mn10300_hash, op->name, (char *) op); + str_hash_insert (mn10300_hash, op->name, op, 0); } op++; } diff --git a/gas/config/tc-moxie.c b/gas/config/tc-moxie.c index 580b6a4..b539d26 100644 --- a/gas/config/tc-moxie.c +++ b/gas/config/tc-moxie.c @@ -66,13 +66,13 @@ md_begin (void) /* Insert names into hash table. */ for (count = 0, opcode = moxie_form1_opc_info; count++ < 64; opcode++) - str_hash_insert (opcode_hash_control, opcode->name, (char *) opcode); + str_hash_insert (opcode_hash_control, opcode->name, opcode, 0); for (count = 0, opcode = moxie_form2_opc_info; count++ < 4; opcode++) - str_hash_insert (opcode_hash_control, opcode->name, (char *) opcode); + str_hash_insert (opcode_hash_control, opcode->name, opcode, 0); for (count = 0, opcode = moxie_form3_opc_info; count++ < 10; opcode++) - str_hash_insert (opcode_hash_control, opcode->name, (char *) opcode); + str_hash_insert (opcode_hash_control, opcode->name, opcode, 0); bfd_set_arch_mach (stdoutput, TARGET_ARCH, 0); } diff --git a/gas/config/tc-msp430.c b/gas/config/tc-msp430.c index 92ede74..2738937 100644 --- a/gas/config/tc-msp430.c +++ b/gas/config/tc-msp430.c @@ -1828,8 +1828,7 @@ md_begin (void) msp430_hash = str_htab_create (); for (opcode = msp430_opcodes; opcode->name; opcode++) - if (str_hash_find (msp430_hash, opcode->name) == NULL) - str_hash_insert (msp430_hash, opcode->name, (char *) opcode); + str_hash_insert (msp430_hash, opcode->name, opcode, 0); bfd_set_arch_mach (stdoutput, TARGET_ARCH, target_is_430x () ? bfd_mach_msp430x : bfd_mach_msp11); diff --git a/gas/config/tc-nds32.c b/gas/config/tc-nds32.c index 900f715..62bbad7 100644 --- a/gas/config/tc-nds32.c +++ b/gas/config/tc-nds32.c @@ -3432,21 +3432,12 @@ static struct nds32_pseudo_opcode nds32_pseudo_opcode_table[] = static void nds32_init_nds32_pseudo_opcodes (void) { - struct nds32_pseudo_opcode *opcode = nds32_pseudo_opcode_table; + struct nds32_pseudo_opcode *opcode; nds32_pseudo_opcode_hash = str_htab_create (); - for ( ; opcode->opcode; opcode++) - { - void *op; - - op = str_hash_find (nds32_pseudo_opcode_hash, opcode->opcode); - if (op != NULL) - { - as_warn (_("Duplicated pseudo-opcode %s."), opcode->opcode); - continue; - } - str_hash_insert (nds32_pseudo_opcode_hash, opcode->opcode, opcode); - } + for (opcode = nds32_pseudo_opcode_table; opcode->opcode; opcode++) + if (str_hash_insert (nds32_pseudo_opcode_hash, opcode->opcode, opcode, 0)) + as_fatal (_("duplicate %s"), opcode->opcode); } static struct nds32_pseudo_opcode * @@ -4296,7 +4287,7 @@ nds32_relax_hint (int mode ATTRIBUTE_UNUSED) { relocs = XNEW (struct nds32_relocs_pattern); memset (relocs, 0, sizeof (struct nds32_relocs_pattern)); - str_hash_insert (nds32_hint_hash, name, relocs); + str_hash_insert (nds32_hint_hash, name, relocs, 0); } else { @@ -4625,12 +4616,12 @@ md_begin (void) /* Initial general purpose registers hash table. */ nds32_gprs_hash = str_htab_create (); for (k = keyword_gpr; k->name; k++) - str_hash_insert (nds32_gprs_hash, k->name, k); + str_hash_insert (nds32_gprs_hash, k->name, k, 0); /* Initial branch hash table. */ nds32_relax_info_hash = str_htab_create (); for (relax_info = relax_table; relax_info->opcode; relax_info++) - str_hash_insert (nds32_relax_info_hash, relax_info->opcode, relax_info); + str_hash_insert (nds32_relax_info_hash, relax_info->opcode, relax_info, 0); /* Initial relax hint hash table. */ nds32_hint_hash = str_htab_create (); @@ -5940,7 +5931,7 @@ nds32_match_hint_insn (struct nds32_opcode *opcode, uint32_t seq) /* Append relax relocation for link time relaxing. */ static void -nds32_elf_append_relax_relocs (const char *key, void *value) +nds32_elf_append_relax_relocs (const char *key, const void *value) { struct nds32_relocs_pattern *relocs_pattern = (struct nds32_relocs_pattern *) value; diff --git a/gas/config/tc-nios2.c b/gas/config/tc-nios2.c index a8bbe5bf..467e2c9 100644 --- a/gas/config/tc-nios2.c +++ b/gas/config/tc-nios2.c @@ -3624,16 +3624,20 @@ md_begin (void) nios2_ps_hash = str_htab_create (); for (i = 0; i < nios2_num_opcodes; ++i) - str_hash_insert (nios2_opcode_hash, nios2_opcodes[i].name, - (PTR) & nios2_opcodes[i]); + if (str_hash_insert (nios2_opcode_hash, nios2_opcodes[i].name, + &nios2_opcodes[i], 0) != NULL) + as_fatal (_("duplicate %s"), nios2_opcodes[i].name); for (i = 0; i < nios2_num_regs; ++i) - str_hash_insert (nios2_reg_hash, nios2_regs[i].name, - (PTR) & nios2_regs[i]); + if (str_hash_insert (nios2_reg_hash, nios2_regs[i].name, + &nios2_regs[i], 0) != NULL) + as_fatal (_("duplicate %s"), nios2_regs[i].name); for (i = 0; i < nios2_num_ps_insn_info_structs; ++i) - str_hash_insert (nios2_ps_hash, nios2_ps_insn_info_structs[i].pseudo_insn, - (PTR) & nios2_ps_insn_info_structs[i]); + if (str_hash_insert (nios2_ps_hash, + nios2_ps_insn_info_structs[i].pseudo_insn, + &nios2_ps_insn_info_structs[i], 0) != NULL) + as_fatal (_("duplicate %s"), nios2_ps_insn_info_structs[i].pseudo_insn); /* Assembler option defaults. */ nios2_as_options.noat = FALSE; diff --git a/gas/config/tc-ns32k.c b/gas/config/tc-ns32k.c index dfa8b42..531fd6f 100644 --- a/gas/config/tc-ns32k.c +++ b/gas/config/tc-ns32k.c @@ -1103,7 +1103,8 @@ parse (const char *line, int recursive_level) c = *lineptr; *(char *) lineptr = '\0'; - if (!(desc = (struct ns32k_opcode *) str_hash_find (inst_hash_handle, line))) + desc = (struct ns32k_opcode *) str_hash_find (inst_hash_handle, line); + if (!desc) as_fatal (_("No such opcode")); *(char *) lineptr = c; @@ -1901,7 +1902,8 @@ md_begin (void) endop = ns32k_opcodes + sizeof (ns32k_opcodes) / sizeof (ns32k_opcodes[0]); for (ptr = ns32k_opcodes; ptr < endop; ptr++) - str_hash_insert (inst_hash_handle, ptr->name, (char *) ptr); + if (str_hash_insert (inst_hash_handle, ptr->name, ptr, 0) != NULL) + as_fatal (_("duplicate %s"), ptr->name); /* Some private space please! */ freeptr_static = XNEWVEC (char, PRIVATE_SIZE); diff --git a/gas/config/tc-pdp11.c b/gas/config/tc-pdp11.c index 1818d2f..9a24978 100644 --- a/gas/config/tc-pdp11.c +++ b/gas/config/tc-pdp11.c @@ -193,9 +193,9 @@ md_begin (void) as_fatal (_("Virtual memory exhausted")); for (i = 0; i < pdp11_num_opcodes; i++) - str_hash_insert (insn_hash, pdp11_opcodes[i].name, (void *) (pdp11_opcodes + i)); + str_hash_insert (insn_hash, pdp11_opcodes[i].name, pdp11_opcodes + i, 0); for (i = 0; i < pdp11_num_aliases; i++) - str_hash_insert (insn_hash, pdp11_aliases[i].name, (void *) (pdp11_aliases + i)); + str_hash_insert (insn_hash, pdp11_aliases[i].name, pdp11_aliases + i, 0); } void diff --git a/gas/config/tc-pj.c b/gas/config/tc-pj.c index 5c99248..bc4b8cb 100644 --- a/gas/config/tc-pj.c +++ b/gas/config/tc-pj.c @@ -176,7 +176,7 @@ fake_opcode (const char *name, fake->opcode = -1; fake->opcode_next = -1; fake->u.func = func; - str_hash_insert (opcode_hash_control, name, (char *) fake); + str_hash_insert (opcode_hash_control, name, fake, 0); } /* Enter another entry into the opcode hash table so the same opcode @@ -186,7 +186,7 @@ static void alias (const char *new_name, const char *old) { str_hash_insert (opcode_hash_control, new_name, - (char *) str_hash_find (opcode_hash_control, old)); + str_hash_find (opcode_hash_control, old), 0); } /* This function is called once, at assembler startup time. It sets @@ -201,7 +201,7 @@ md_begin (void) /* Insert names into hash table. */ for (opcode = pj_opc_info; opcode->u.name; opcode++) - str_hash_insert (opcode_hash_control, opcode->u.name, (char *) opcode); + str_hash_insert (opcode_hash_control, opcode->u.name, opcode, 0); /* Insert the only fake opcode. */ fake_opcode ("ipush", ipush_code); diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c index 052f64a..1ff1cd9 100644 --- a/gas/config/tc-ppc.c +++ b/gas/config/tc-ppc.c @@ -1682,13 +1682,17 @@ ppc_setup_opcodes (void) } if ((ppc_cpu & op->flags) != 0 - && !(ppc_cpu & op->deprecated)) - str_hash_insert (ppc_hash, op->name, (void *) op); + && !(ppc_cpu & op->deprecated) + && str_hash_insert (ppc_hash, op->name, op, 0) != NULL) + { + as_bad (_("duplicate %s"), op->name); + bad_insn = TRUE; + } } if ((ppc_cpu & PPC_OPCODE_ANY) != 0) for (op = powerpc_opcodes; op < op_end; op++) - str_hash_insert (ppc_hash, op->name, (void *) op); + str_hash_insert (ppc_hash, op->name, op, 0); op_end = prefix_opcodes + prefix_num_opcodes; for (op = prefix_opcodes; op < op_end; op++) @@ -1716,13 +1720,17 @@ ppc_setup_opcodes (void) } if ((ppc_cpu & op->flags) != 0 - && !(ppc_cpu & op->deprecated)) - str_hash_insert (ppc_hash, op->name, (void *) op); + && !(ppc_cpu & op->deprecated) + && str_hash_insert (ppc_hash, op->name, op, 0) != NULL) + { + as_bad (_("duplicate %s"), op->name); + bad_insn = TRUE; + } } if ((ppc_cpu & PPC_OPCODE_ANY) != 0) for (op = prefix_opcodes; op < op_end; op++) - str_hash_insert (ppc_hash, op->name, (void *) op); + str_hash_insert (ppc_hash, op->name, op, 0); op_end = vle_opcodes + vle_num_opcodes; for (op = vle_opcodes; op < op_end; op++) @@ -1751,8 +1759,12 @@ ppc_setup_opcodes (void) } if ((ppc_cpu & op->flags) != 0 - && !(ppc_cpu & op->deprecated)) - str_hash_insert (ppc_hash, op->name, (void *) op); + && !(ppc_cpu & op->deprecated) + && str_hash_insert (ppc_hash, op->name, op, 0) != NULL) + { + as_bad (_("duplicate %s"), op->name); + bad_insn = TRUE; + } } /* SPE2 instructions */ @@ -1785,12 +1797,17 @@ ppc_setup_opcodes (void) bad_insn |= insn_validate (op); } - if ((ppc_cpu & op->flags) != 0 && !(ppc_cpu & op->deprecated)) - str_hash_insert (ppc_hash, op->name, (void *) op); + if ((ppc_cpu & op->flags) != 0 + && !(ppc_cpu & op->deprecated) + && str_hash_insert (ppc_hash, op->name, op, 0) != NULL) + { + as_bad (_("duplicate %s"), op->name); + bad_insn = TRUE; + } } for (op = spe2_opcodes; op < op_end; op++) - str_hash_insert (ppc_hash, op->name, (void *) op); + str_hash_insert (ppc_hash, op->name, op, 0); } /* Insert the macros into a hash table. */ @@ -1798,10 +1815,13 @@ ppc_setup_opcodes (void) macro_end = powerpc_macros + powerpc_num_macros; for (macro = powerpc_macros; macro < macro_end; macro++) - { - if ((macro->flags & ppc_cpu) != 0 || (ppc_cpu & PPC_OPCODE_ANY) != 0) - str_hash_insert (ppc_macro_hash, macro->name, (void *) macro); - } + if (((macro->flags & ppc_cpu) != 0 + || (ppc_cpu & PPC_OPCODE_ANY) != 0) + && str_hash_insert (ppc_macro_hash, macro->name, macro, 0) != NULL) + { + as_bad (_("duplicate %s"), macro->name); + bad_insn = TRUE; + } if (bad_insn) abort (); @@ -3116,7 +3136,8 @@ md_assemble (char *str) { const struct powerpc_macro *macro; - macro = (const struct powerpc_macro *) str_hash_find (ppc_macro_hash, str); + macro = (const struct powerpc_macro *) str_hash_find (ppc_macro_hash, + str); if (macro == (const struct powerpc_macro *) NULL) as_bad (_("unrecognized opcode: `%s'"), str); else diff --git a/gas/config/tc-pru.c b/gas/config/tc-pru.c index 9ec01e6..25df0a3 100644 --- a/gas/config/tc-pru.c +++ b/gas/config/tc-pru.c @@ -1564,12 +1564,13 @@ md_begin (void) pru_reg_hash = str_htab_create (); for (i = 0; i < NUMOPCODES; ++i) - str_hash_insert (pru_opcode_hash, pru_opcodes[i].name, - (PTR) & pru_opcodes[i]); + if (str_hash_insert (pru_opcode_hash, pru_opcodes[i].name, + &pru_opcodes[i], 0) != NULL) + as_fatal (_("duplicate %s"), pru_opcodes[i].name); for (i = 0; i < pru_num_regs; ++i) - str_hash_insert (pru_reg_hash, pru_regs[i].name, - (PTR) & pru_regs[i]); + if (str_hash_insert (pru_reg_hash, pru_regs[i].name, &pru_regs[i], 0)) + as_fatal (_("duplicate %s"), pru_regs[i].name); linkrelax = pru_opt.link_relax; /* Initialize the alignment data. */ diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c index 82b681e..bcdbc3a 100644 --- a/gas/config/tc-riscv.c +++ b/gas/config/tc-riscv.c @@ -253,7 +253,8 @@ init_ext_version_hash (const struct riscv_ext_version *table) while (table[i].name) { const char *name = table[i].name; - str_hash_insert (hash, name, (void *) &table[i]); + if (str_hash_insert (hash, name, &table[i], 0) != NULL) + as_fatal (_("duplicate %s"), name); i++; while (table[i].name @@ -558,7 +559,8 @@ init_opcode_names_hash (void) const struct opcode_name_t *opcode; for (opcode = &opcode_name_list[0]; opcode->name != NULL; ++opcode) - str_hash_insert (opcode_names_hash, opcode->name, (void *)opcode); + if (str_hash_insert (opcode_names_hash, opcode->name, opcode, 0) != NULL) + as_fatal (_("duplicate %s"), opcode->name); } /* Find `s` is a valid opcode name or not, @@ -614,7 +616,8 @@ static void hash_reg_name (enum reg_class class, const char *name, unsigned n) { void *hash = ENCODE_REG_HASH (class, n); - str_hash_insert (reg_names_hash, name, hash); + if (str_hash_insert (reg_names_hash, name, hash, 0) != NULL) + as_fatal (_("duplicate %s"), name); } static void @@ -665,7 +668,7 @@ riscv_init_csr_hash (const char *name, Otherwise, attach the extra information to the entry which is already in the hash table. */ if (pre_entry == NULL) - str_hash_insert (csr_extra_hash, name, (void *) entry); + str_hash_insert (csr_extra_hash, name, entry, 0); else pre_entry->next = entry; } @@ -998,7 +1001,8 @@ init_opcode_hash (const struct riscv_opcode *opcodes, while (opcodes[i].name) { const char *name = opcodes[i].name; - str_hash_insert (hash, name, (void *) &opcodes[i]); + if (str_hash_insert (hash, name, &opcodes[i], 0) != NULL) + as_fatal (_("duplicate %s"), name); do { diff --git a/gas/config/tc-s390.c b/gas/config/tc-s390.c index f66e90e..427a599 100644 --- a/gas/config/tc-s390.c +++ b/gas/config/tc-s390.c @@ -530,8 +530,12 @@ s390_setup_opcodes (void) f = (op->flags & S390_INSTR_FLAG_FACILITY_MASK); use_opcode = ((f & current_flags) == f); } - if (use_opcode) - str_hash_insert (s390_opcode_hash, op->name, (void *) op); + if (use_opcode + && str_hash_insert (s390_opcode_hash, op->name, op, 0) != NULL) + { + as_bad (_("duplicate %s"), op->name); + dup_insn = TRUE; + } while (op < op_end - 1 && strcmp (op->name, op[1].name) == 0) op++; @@ -566,7 +570,8 @@ md_begin (void) op_end = s390_opformats + s390_num_opformats; for (op = s390_opformats; op < op_end; op++) - str_hash_insert (s390_opformat_hash, op->name, (void *) op); + if (str_hash_insert (s390_opformat_hash, op->name, op, 0) != NULL) + as_fatal (_("duplicate %s"), op->name); s390_setup_opcodes (); diff --git a/gas/config/tc-score.c b/gas/config/tc-score.c index 380d636..739df15 100644 --- a/gas/config/tc-score.c +++ b/gas/config/tc-score.c @@ -2203,7 +2203,8 @@ s3_dependency_type_from_insn (char *insn_name) const struct s3_insn_to_dependency *tmp; strcpy (name, insn_name); - tmp = (const struct s3_insn_to_dependency *) str_hash_find (s3_dependency_insn_hsh, name); + tmp = (const struct s3_insn_to_dependency *) + str_hash_find (s3_dependency_insn_hsh, name); if (tmp) return tmp->type; @@ -2662,7 +2663,8 @@ s3_parse_16_32_inst (char *insnstr, bfd_boolean gen_frag_p) c = *p; *p = '\0'; - opcode = (const struct s3_asm_opcode *) str_hash_find (s3_score_ops_hsh, operator); + opcode = (const struct s3_asm_opcode *) str_hash_find (s3_score_ops_hsh, + operator); *p = c; memset (&s3_inst, '\0', sizeof (s3_inst)); @@ -2708,7 +2710,8 @@ s3_parse_48_inst (char *insnstr, bfd_boolean gen_frag_p) c = *p; *p = '\0'; - opcode = (const struct s3_asm_opcode *) str_hash_find (s3_score_ops_hsh, operator); + opcode = (const struct s3_asm_opcode *) str_hash_find (s3_score_ops_hsh, + operator); *p = c; memset (&s3_inst, '\0', sizeof (s3_inst)); @@ -6265,8 +6268,8 @@ s3_insert_reg (const struct s3_reg_entry *r, htab_t htab) } buf2[i] = '\0'; - str_hash_insert (htab, buf, (void *) r); - str_hash_insert (htab, buf2, (void *) r); + str_hash_insert (htab, buf, r, 0); + str_hash_insert (htab, buf2, r, 0); } static void @@ -6310,7 +6313,7 @@ s3_build_score_ops_hsh (void) new_opcode->type = insn->type; new_opcode->bitmask = insn->bitmask; str_hash_insert (s3_score_ops_hsh, new_opcode->template_name, - (void *) new_opcode); + new_opcode, 0); } } @@ -6336,8 +6339,7 @@ s3_build_dependency_insn_hsh (void) 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, - (void *) new_i2n); + 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 2c77d30..aba8b6c 100644 --- a/gas/config/tc-score7.c +++ b/gas/config/tc-score7.c @@ -2321,7 +2321,8 @@ s7_dependency_type_from_insn (char *insn_name) const struct s7_insn_to_dependency *tmp; strcpy (name, insn_name); - tmp = (const struct s7_insn_to_dependency *) str_hash_find (s7_dependency_insn_hsh, name); + tmp = (const struct s7_insn_to_dependency *) + str_hash_find (s7_dependency_insn_hsh, name); if (tmp) return tmp->type; @@ -2789,7 +2790,8 @@ s7_parse_16_32_inst (char *insnstr, bfd_boolean gen_frag_p) c = *p; *p = '\0'; - opcode = (const struct s7_asm_opcode *) str_hash_find (s7_score_ops_hsh, operator); + opcode = (const struct s7_asm_opcode *) str_hash_find (s7_score_ops_hsh, + operator); *p = c; memset (&s7_inst, '\0', sizeof (s7_inst)); @@ -5104,7 +5106,7 @@ s7_build_score_ops_hsh (void) new_opcode->type = insn->type; new_opcode->bitmask = insn->bitmask; str_hash_insert (s7_score_ops_hsh, new_opcode->template_name, - (void *) new_opcode); + new_opcode, 0); } } @@ -5130,8 +5132,7 @@ s7_build_dependency_insn_hsh (void) 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, - (void *) new_i2d); + str_hash_insert (s7_dependency_insn_hsh, new_i2d->insn_name, new_i2d, 0); } } @@ -5359,8 +5360,8 @@ s7_insert_reg (const struct s7_reg_entry *r, htab_t htab) } buf2[i] = '\0'; - str_hash_insert (htab, buf, (void *) r); - str_hash_insert (htab, buf2, (void *) r); + str_hash_insert (htab, buf, r, 0); + str_hash_insert (htab, buf2, r, 0); } static void diff --git a/gas/config/tc-sh.c b/gas/config/tc-sh.c index db5a7b9..e1e509d 100644 --- a/gas/config/tc-sh.c +++ b/gas/config/tc-sh.c @@ -574,7 +574,7 @@ md_begin (void) if (!SH_MERGE_ARCH_SET_VALID (opcode->arch, target_arch)) continue; prev_name = opcode->name; - str_hash_insert (opcode_hash_control, opcode->name, (char *) opcode); + str_hash_insert (opcode_hash_control, opcode->name, opcode, 0); } } } diff --git a/gas/config/tc-sparc.c b/gas/config/tc-sparc.c index 58254c3..d48112e 100644 --- a/gas/config/tc-sparc.c +++ b/gas/config/tc-sparc.c @@ -956,7 +956,11 @@ md_begin (void) while (i < (unsigned int) sparc_num_opcodes) { const char *name = sparc_opcodes[i].name; - str_hash_insert (op_hash, name, (void *) &sparc_opcodes[i]); + if (str_hash_insert (op_hash, name, &sparc_opcodes[i], 0) != NULL) + { + as_bad (_("duplicate %s"), name); + lose = 1; + } do { if (sparc_opcodes[i].match & sparc_opcodes[i].lose) @@ -984,9 +988,11 @@ md_begin (void) name, native_op_table[i].name); lose = 1; } - else - str_hash_insert (op_hash, native_op_table[i].name, - (void *) insn); + else if (str_hash_insert (op_hash, native_op_table[i].name, insn, 0)) + { + as_bad (_("duplicate %s"), native_op_table[i].name); + lose = 1; + } } if (lose) diff --git a/gas/config/tc-spu.c b/gas/config/tc-spu.c index d50bd33..e2ddf0c 100644 --- a/gas/config/tc-spu.c +++ b/gas/config/tc-spu.c @@ -112,17 +112,12 @@ md_begin (void) { int i; - /* initialize hash table */ - op_hash = str_htab_create (); - /* loop until you see the end of the list */ - + /* Hash each mnemonic and record its position. There are + duplicates, keep just the first. */ for (i = 0; i < spu_num_opcodes; i++) - /* hash each mnemonic and record its position */ - if (str_hash_find (op_hash, spu_opcodes[i].mnemonic) == NULL) - str_hash_insert (op_hash, spu_opcodes[i].mnemonic, - (void *) &spu_opcodes[i]); + str_hash_insert (op_hash, spu_opcodes[i].mnemonic, &spu_opcodes[i], 0); } const char *md_shortopts = ""; diff --git a/gas/config/tc-tic30.c b/gas/config/tc-tic30.c index 1d8c370..1490c67 100644 --- a/gas/config/tc-tic30.c +++ b/gas/config/tc-tic30.c @@ -117,8 +117,8 @@ md_begin (void) const insn_template *current_optab = tic30_optab; for (; current_optab < tic30_optab_end; current_optab++) - str_hash_insert (op_hash, current_optab->name, - (char *) current_optab); + if (str_hash_insert (op_hash, current_optab->name, current_optab, 0)) + as_fatal (_("duplicate %s"), current_optab->name); } parop_hash = str_htab_create (); @@ -127,8 +127,8 @@ md_begin (void) const partemplate *current_parop = tic30_paroptab; for (; current_parop < tic30_paroptab_end; current_parop++) - str_hash_insert (parop_hash, current_parop->name, - (char *) current_parop); + if (str_hash_insert (parop_hash, current_parop->name, current_parop, 0)) + as_fatal (_("duplicate %s"), current_parop->name); } reg_hash = str_htab_create (); @@ -137,8 +137,8 @@ md_begin (void) const reg *current_reg = tic30_regtab; for (; current_reg < tic30_regtab_end; current_reg++) - str_hash_insert (reg_hash, current_reg->name, - (char *) current_reg); + if (str_hash_insert (reg_hash, current_reg->name, current_reg, 0)) + as_fatal (_("duplicate %s"), current_reg->name); } ind_hash = str_htab_create (); @@ -147,8 +147,8 @@ md_begin (void) const ind_addr_type *current_ind = tic30_indaddr_tab; for (; current_ind < tic30_indaddrtab_end; current_ind++) - str_hash_insert (ind_hash, current_ind->syntax, - (char *) current_ind); + if (str_hash_insert (ind_hash, current_ind->syntax, current_ind, 0)) + as_fatal (_("duplicate %s"), current_ind->syntax); } /* Fill in lexical tables: opcode_chars, operand_chars, space_chars. */ diff --git a/gas/config/tc-tic4x.c b/gas/config/tc-tic4x.c index a6db990..f1eb5bf 100644 --- a/gas/config/tc-tic4x.c +++ b/gas/config/tc-tic4x.c @@ -727,7 +727,7 @@ tic4x_asg (int x ATTRIBUTE_UNUSED) c = get_symbol_name (&name); /* Get terminator. */ str = xstrdup (str); name = xstrdup (name); - str_hash_insert (tic4x_asg_hash, name, str); + str_hash_insert (tic4x_asg_hash, name, str, 1); (void) restore_line_pointer (c); demand_empty_rest_of_line (); } @@ -1215,7 +1215,9 @@ tic4x_inst_insert (const tic4x_inst_t *inst) if (!strcmp (inst->name, prev_name) || inst->name[0] == '\0') return; - str_hash_insert (tic4x_op_hash, inst->name, (void *) inst); + if (str_hash_insert (tic4x_op_hash, inst->name, inst, 0) != NULL) + as_fatal (_("duplicate %s"), inst->name); + strcpy (prev_name, inst->name); } diff --git a/gas/config/tc-tic54x.c b/gas/config/tc-tic54x.c index 6412d38..62d49d9 100644 --- a/gas/config/tc-tic54x.c +++ b/gas/config/tc-tic54x.c @@ -567,7 +567,7 @@ stag_add_field_symbols (struct stag *stag, replacement = concat (S_GET_NAME (rootsym), "+", root_stag_name, name + strlen (S_GET_NAME (rootsym)), NULL); - str_hash_insert (subsym_hash[0], name, replacement); + str_hash_insert (subsym_hash[0], name, replacement, 0); } /* Recurse if the field is a structure. @@ -738,7 +738,7 @@ tic54x_endstruct (int is_union) /* Nested .structs don't get put in the stag table. */ if (current_stag->outer == NULL) { - str_hash_insert (stag_hash, current_stag->name, current_stag); + str_hash_insert (stag_hash, current_stag->name, current_stag, 0); stag_add_field_symbols (current_stag, path, S_GET_VALUE (current_stag->sym), NULL, NULL); @@ -2236,7 +2236,7 @@ tic54x_var (int ignore ATTRIBUTE_UNUSED) c = get_symbol_name (&name); /* .var symbols start out with a null string. */ name = xstrdup (name); - str_hash_insert (subsym_hash[macro_level], name, empty); + str_hash_insert (subsym_hash[macro_level], name, empty, 0); c = restore_line_pointer (c); if (c == ',') { @@ -2521,7 +2521,7 @@ tic54x_macro_info (const macro_entry *macro) name[entry->name.len] = '\0'; value[entry->actual.len] = '\0'; - str_hash_insert (subsym_hash[macro_level], name, value); + str_hash_insert (subsym_hash[macro_level], name, value, 0); } } @@ -2991,18 +2991,12 @@ md_begin (void) op_hash = str_htab_create (); for (tm = (insn_template *) tic54x_optab; tm->name; tm++) - { - if (str_hash_find (op_hash, tm->name)) - continue; - str_hash_insert (op_hash, tm->name, (char *) tm); - } + str_hash_insert (op_hash, tm->name, tm, 0); + parop_hash = str_htab_create (); for (tm = (insn_template *) tic54x_paroptab; tm->name; tm++) - { - if (str_hash_find (parop_hash, tm->name)) - continue; - str_hash_insert (parop_hash, tm->name, (char *) tm); - } + str_hash_insert (parop_hash, tm->name, tm, 0); + reg_hash = str_htab_create (); for (sym = (tic54x_symbol *) regs; sym->name; sym++) { @@ -3011,51 +3005,48 @@ md_begin (void) &zero_address_frag, sym->value); SF_SET_LOCAL (symbolP); symbol_table_insert (symbolP); - str_hash_insert (reg_hash, sym->name, (char *) sym); + str_hash_insert (reg_hash, sym->name, sym, 0); } for (sym = (tic54x_symbol *) mmregs; sym->name; sym++) - str_hash_insert (reg_hash, sym->name, (char *) sym); + str_hash_insert (reg_hash, sym->name, sym, 0); mmreg_hash = str_htab_create (); for (sym = (tic54x_symbol *) mmregs; sym->name; sym++) - str_hash_insert (mmreg_hash, sym->name, (char *) sym); + str_hash_insert (mmreg_hash, sym->name, sym, 0); cc_hash = str_htab_create (); for (sym = (tic54x_symbol *) condition_codes; sym->name; sym++) - str_hash_insert (cc_hash, sym->name, (char *) sym); + str_hash_insert (cc_hash, sym->name, sym, 0); cc2_hash = str_htab_create (); for (sym = (tic54x_symbol *) cc2_codes; sym->name; sym++) - str_hash_insert (cc2_hash, sym->name, (char *) sym); + str_hash_insert (cc2_hash, sym->name, sym, 0); cc3_hash = str_htab_create (); for (sym = (tic54x_symbol *) cc3_codes; sym->name; sym++) - str_hash_insert (cc3_hash, sym->name, (char *) sym); + str_hash_insert (cc3_hash, sym->name, sym, 0); sbit_hash = str_htab_create (); for (sym = (tic54x_symbol *) status_bits; sym->name; sym++) - str_hash_insert (sbit_hash, sym->name, (char *) sym); + str_hash_insert (sbit_hash, sym->name, sym, 0); misc_symbol_hash = str_htab_create (); for (symname = (char **) misc_symbols; *symname; symname++) - str_hash_insert (misc_symbol_hash, *symname, *symname); + str_hash_insert (misc_symbol_hash, *symname, *symname, 0); /* Only the base substitution table and local label table are initialized; the others (for local macro substitution) get instantiated as needed. */ local_label_hash[0] = str_htab_create (); subsym_hash[0] = str_htab_create (); for (subsym_proc = subsym_procs; subsym_proc->name; subsym_proc++) - str_hash_insert (subsym_hash[0], subsym_proc->name, - (char *) subsym_proc); + str_hash_insert (subsym_hash[0], subsym_proc->name, subsym_proc, 0); math_hash = str_htab_create (); for (math_proc = math_procs; math_proc->name; math_proc++) { /* Insert into the main subsym hash for recognition; insert into the math hash to actually store information. */ - str_hash_insert (subsym_hash[0], math_proc->name, - (char *) math_proc); - str_hash_insert (math_hash, math_proc->name, - (char *) math_proc); + str_hash_insert (subsym_hash[0], math_proc->name, math_proc, 0); + str_hash_insert (math_hash, math_proc->name, math_proc, 0); } subsym_recurse_hash = str_htab_create (); stag_hash = str_htab_create (); @@ -4170,7 +4161,7 @@ tic54x_parse_insn (tic54x_insn *insn, char *line) if (optimize_insn (insn)) { insn->tm = (insn_template *) str_hash_find (op_hash, - insn->mnemonic); + insn->mnemonic); continue; } @@ -4335,8 +4326,12 @@ subsym_create_or_replace (char *name, char *value) int i; for (i = macro_level; i > 0; i--) - str_hash_insert (subsym_hash[i], name, value); - str_hash_insert (subsym_hash[0], name, value); + if (str_hash_find (subsym_hash[i], name)) + { + str_hash_insert (subsym_hash[i], name, value, 1); + return; + } + str_hash_insert (subsym_hash[0], name, value, 1); } /* Look up the substitution string replacement for the given symbol. @@ -4495,7 +4490,8 @@ subsym_substitute (char *line, int forced) value[strlen (value) - 1] = '\0'; sprintf (digit, ".%d", local_label_id++); strcat (value, digit); - str_hash_insert (local_label_hash[macro_level], namecopy, value); + str_hash_insert (local_label_hash[macro_level], + namecopy, value, 0); } /* Indicate where to continue looking for substitutions. */ ptr = tail; @@ -4616,7 +4612,7 @@ subsym_substitute (char *line, int forced) try to replace a symbol once. */ if (recurse) { - str_hash_insert (subsym_recurse_hash, name, name); + str_hash_insert (subsym_recurse_hash, name, name, 0); value = subsym_substitute (value, macro_level > 0); str_hash_delete (subsym_recurse_hash, name); } @@ -5007,18 +5003,20 @@ tic54x_undefined_symbol (char *name) tic54x_symbol *sym; /* Not sure how to handle predefined symbols. */ - if ((sym = (tic54x_symbol *) str_hash_find (cc_hash, name)) != NULL || - (sym = (tic54x_symbol *) str_hash_find (cc2_hash, name)) != NULL || - (sym = (tic54x_symbol *) str_hash_find (cc3_hash, name)) != NULL || - (sym = (tic54x_symbol *) str_hash_find (misc_symbol_hash, name)) != NULL || - (sym = (tic54x_symbol *) str_hash_find (sbit_hash, name)) != NULL) + if ((sym = (tic54x_symbol *) str_hash_find (cc_hash, name)) != NULL + || (sym = (tic54x_symbol *) str_hash_find (cc2_hash, name)) != NULL + || (sym = (tic54x_symbol *) str_hash_find (cc3_hash, name)) != NULL + || (sym = (tic54x_symbol *) str_hash_find (misc_symbol_hash, + name)) != NULL + || (sym = (tic54x_symbol *) str_hash_find (sbit_hash, name)) != NULL) { return symbol_new (name, reg_section, &zero_address_frag, sym->value); } - if ((sym = (tic54x_symbol *) str_hash_find (reg_hash, name)) != NULL || - (sym = (tic54x_symbol *) str_hash_find (mmreg_hash, name)) != NULL || - !strcasecmp (name, "a") || !strcasecmp (name, "b")) + if ((sym = (tic54x_symbol *) str_hash_find (reg_hash, name)) != NULL + || (sym = (tic54x_symbol *) str_hash_find (mmreg_hash, name)) != NULL + || !strcasecmp (name, "a") + || !strcasecmp (name, "b")) { return symbol_new (name, reg_section, &zero_address_frag, sym ? sym->value : 0); diff --git a/gas/config/tc-tic6x.c b/gas/config/tc-tic6x.c index fa54f87..3295d95 100644 --- a/gas/config/tc-tic6x.c +++ b/gas/config/tc-tic6x.c @@ -764,7 +764,7 @@ md_begin (void) opc->id = id; opc->next = str_hash_find (opcode_hash, tic6x_opcode_table[id].name); - str_hash_insert (opcode_hash, tic6x_opcode_table[id].name, opc); + str_hash_insert (opcode_hash, tic6x_opcode_table[id].name, opc, 1); } /* Save the current subseg so we can restore it [it's the default one and diff --git a/gas/config/tc-tilegx.c b/gas/config/tc-tilegx.c index 2220af4..fb5d45e 100644 --- a/gas/config/tc-tilegx.c +++ b/gas/config/tc-tilegx.c @@ -275,7 +275,7 @@ md_begin (void) /* Initialize special operator hash table. */ special_operator_hash = str_htab_create (); #define INSERT_SPECIAL_OP(name) \ - str_hash_insert (special_operator_hash, #name, (void *)O_##name) + str_hash_insert (special_operator_hash, #name, (void *) O_##name, 0) INSERT_SPECIAL_OP (hw0); INSERT_SPECIAL_OP (hw1); @@ -285,7 +285,7 @@ md_begin (void) INSERT_SPECIAL_OP (hw1_last); INSERT_SPECIAL_OP (hw2_last); /* hw3_last is a convenience alias for the equivalent hw3. */ - str_hash_insert (special_operator_hash, "hw3_last", (void*)O_hw3); + str_hash_insert (special_operator_hash, "hw3_last", (void *) O_hw3, 0); INSERT_SPECIAL_OP (hw0_got); INSERT_SPECIAL_OP (hw0_last_got); INSERT_SPECIAL_OP (hw1_last_got); @@ -312,14 +312,14 @@ md_begin (void) /* Initialize op_hash hash table. */ op_hash = str_htab_create (); for (op = &tilegx_opcodes[0]; op->name != NULL; op++) - str_hash_insert (op_hash, op->name, (void *)op); + if (str_hash_insert (op_hash, op->name, op, 0) != NULL) + as_fatal (_("duplicate %s"), op->name); /* Initialize the spr hash table. */ parsing_spr = 0; spr_hash = str_htab_create (); for (i = 0; i < tilegx_num_sprs; i++) - str_hash_insert (spr_hash, tilegx_sprs[i].name, - (void *) &tilegx_sprs[i]); + str_hash_insert (spr_hash, tilegx_sprs[i].name, &tilegx_sprs[i], 0); /* Set up the main_reg_hash table. We use this instead of creating a symbol in the register section to avoid ambiguities @@ -330,13 +330,13 @@ md_begin (void) char buf[64]; str_hash_insert (main_reg_hash, tilegx_register_names[i], - (void *) (long) (i | CANONICAL_REG_NAME_FLAG)); + (void *) (long) (i | CANONICAL_REG_NAME_FLAG), 0); /* See if we should insert a noncanonical alias, like r63. */ sprintf (buf, "r%d", i); if (strcmp (buf, tilegx_register_names[i]) != 0) str_hash_insert (main_reg_hash, xstrdup (buf), - (void *) (long) (i | NONCANONICAL_REG_NAME_FLAG)); + (void *) (long) (i | NONCANONICAL_REG_NAME_FLAG), 0); } } @@ -1239,7 +1239,7 @@ md_assemble (char *str) old_char = str[opname_len]; str[opname_len] = '\0'; - op = str_hash_find(op_hash, str); + op = str_hash_find (op_hash, str); str[opname_len] = old_char; if (op == NULL) { diff --git a/gas/config/tc-tilepro.c b/gas/config/tc-tilepro.c index cf44ad1..4468447 100644 --- a/gas/config/tc-tilepro.c +++ b/gas/config/tc-tilepro.c @@ -218,7 +218,7 @@ md_begin (void) /* Initialize special operator hash table. */ special_operator_hash = str_htab_create (); #define INSERT_SPECIAL_OP(name) \ - str_hash_insert (special_operator_hash, #name, (void *)O_##name) + str_hash_insert (special_operator_hash, #name, (void *) O_##name, 0) INSERT_SPECIAL_OP(lo16); INSERT_SPECIAL_OP(hi16); @@ -248,14 +248,14 @@ md_begin (void) /* Initialize op_hash hash table. */ op_hash = str_htab_create (); for (op = &tilepro_opcodes[0]; op->name != NULL; op++) - str_hash_insert (op_hash, op->name, (void *)op); + if (str_hash_insert (op_hash, op->name, op, 0) != NULL) + as_fatal (_("duplicate %s"), op->name); /* Initialize the spr hash table. */ parsing_spr = 0; spr_hash = str_htab_create (); for (i = 0; i < tilepro_num_sprs; i++) - str_hash_insert (spr_hash, tilepro_sprs[i].name, - (void *) &tilepro_sprs[i]); + str_hash_insert (spr_hash, tilepro_sprs[i].name, &tilepro_sprs[i], 0); /* Set up the main_reg_hash table. We use this instead of * creating a symbol in the register section to avoid ambiguities @@ -266,28 +266,28 @@ md_begin (void) char buf[64]; str_hash_insert (main_reg_hash, tilepro_register_names[i], - (void *) (long)(i | CANONICAL_REG_NAME_FLAG)); + (void *) (long) (i | CANONICAL_REG_NAME_FLAG), 0); /* See if we should insert a noncanonical alias, like r63. */ sprintf (buf, "r%d", i); if (strcmp (buf, tilepro_register_names[i]) != 0) str_hash_insert (main_reg_hash, xstrdup (buf), - (void *) (long)(i | NONCANONICAL_REG_NAME_FLAG)); + (void *) (long) (i | NONCANONICAL_REG_NAME_FLAG), 0); } /* Insert obsolete backwards-compatibility register names. */ str_hash_insert (main_reg_hash, "io0", - (void *) (long) (TREG_IDN0 | CANONICAL_REG_NAME_FLAG)); + (void *) (long) (TREG_IDN0 | CANONICAL_REG_NAME_FLAG), 0); str_hash_insert (main_reg_hash, "io1", - (void *) (long) (TREG_IDN1 | CANONICAL_REG_NAME_FLAG)); + (void *) (long) (TREG_IDN1 | CANONICAL_REG_NAME_FLAG), 0); str_hash_insert (main_reg_hash, "us0", - (void *) (long) (TREG_UDN0 | CANONICAL_REG_NAME_FLAG)); + (void *) (long) (TREG_UDN0 | CANONICAL_REG_NAME_FLAG), 0); str_hash_insert (main_reg_hash, "us1", - (void *) (long) (TREG_UDN1 | CANONICAL_REG_NAME_FLAG)); + (void *) (long) (TREG_UDN1 | CANONICAL_REG_NAME_FLAG), 0); str_hash_insert (main_reg_hash, "us2", - (void *) (long) (TREG_UDN2 | CANONICAL_REG_NAME_FLAG)); + (void *) (long) (TREG_UDN2 | CANONICAL_REG_NAME_FLAG), 0); str_hash_insert (main_reg_hash, "us3", - (void *) (long) (TREG_UDN3 | CANONICAL_REG_NAME_FLAG)); + (void *) (long) (TREG_UDN3 | CANONICAL_REG_NAME_FLAG), 0); } @@ -1121,7 +1121,7 @@ md_assemble (char *str) old_char = str[opname_len]; str[opname_len] = '\0'; - op = str_hash_find(op_hash, str); + op = str_hash_find (op_hash, str); str[opname_len] = old_char; if (op == NULL) { diff --git a/gas/config/tc-v850.c b/gas/config/tc-v850.c index cd5bada..865d45c 100644 --- a/gas/config/tc-v850.c +++ b/gas/config/tc-v850.c @@ -1964,8 +1964,7 @@ md_begin (void) if (strcmp (prev_name, op->name)) { prev_name = (char *) op->name; - if (str_hash_find (v850_hash, op->name) == NULL) - str_hash_insert (v850_hash, op->name, (char *) op); + str_hash_insert (v850_hash, op->name, op, 0); } op++; } diff --git a/gas/config/tc-vax.c b/gas/config/tc-vax.c index 04a955f..016acaa 100644 --- a/gas/config/tc-vax.c +++ b/gas/config/tc-vax.c @@ -961,11 +961,13 @@ vip_begin (int synthetic_too, /* 1 means include jXXX op-codes. */ op_hash = str_htab_create (); for (vP = votstrs; *vP->vot_name; vP++) - str_hash_insert (op_hash, vP->vot_name, (void *) &vP->vot_detail); + if (str_hash_insert (op_hash, vP->vot_name, &vP->vot_detail, 0) != NULL) + as_fatal (_("duplicate %s"), vP->vot_name); if (synthetic_too) for (vP = synthetic_votstrs; *vP->vot_name; vP++) - str_hash_insert (op_hash, vP->vot_name, (void *) &vP->vot_detail); + if (str_hash_insert (op_hash, vP->vot_name, &vP->vot_detail, 0) != NULL) + as_fatal (_("duplicate %s"), vP->vot_name); #ifndef CONST_TABLE vip_op_defaults (immediate, indirect, displen); diff --git a/gas/config/tc-wasm32.c b/gas/config/tc-wasm32.c index fce12a9..b501255 100644 --- a/gas/config/tc-wasm32.c +++ b/gas/config/tc-wasm32.c @@ -164,7 +164,7 @@ md_begin (void) provides a quick index to the first opcode with a particular name in the opcode table. */ for (opcode = wasm32_opcodes; opcode->name; opcode++) - str_hash_insert (wasm32_hash, opcode->name, (char *) opcode); + str_hash_insert (wasm32_hash, opcode->name, opcode, 0); linkrelax = 0; flag_sectname_subst = 1; diff --git a/gas/config/tc-xgate.c b/gas/config/tc-xgate.c index 4b9adf3..b936865 100644 --- a/gas/config/tc-xgate.c +++ b/gas/config/tc-xgate.c @@ -342,8 +342,7 @@ md_begin (void) j++; op_handles[j].name = xgate_opcode_ptr->name; op_handles[j].opc0[0] = xgate_opcode_ptr; - str_hash_insert (xgate_hash, (char *) op_handles[j].name, - (char *) &(op_handles[j])); + str_hash_insert (xgate_hash, op_handles[j].name, &op_handles[j], 0); } op_handles[j].number_of_modes = handle_enum; prev_op_name = op_handles[j].name; @@ -492,11 +491,10 @@ md_assemble (char *input_line) if (!op_name[0]) as_bad (_("opcode missing or not found on input line")); - if (!(opcode_handle = (struct xgate_opcode_handle *) str_hash_find (xgate_hash, - op_name))) - { - as_bad (_("opcode %s not found in opcode hash table"), op_name); - } + opcode_handle = (struct xgate_opcode_handle *) str_hash_find (xgate_hash, + op_name); + if (!opcode_handle) + as_bad (_("opcode %s not found in opcode hash table"), op_name); else { /* Parse operands so we can find the proper opcode bin. */ @@ -543,8 +541,10 @@ md_assemble (char *input_line) input_line = macro_inline; /* Rewind. */ p = extract_word (p, op_name, 10); - if (!(opcode_handle = (struct xgate_opcode_handle *) - str_hash_find (xgate_hash, op_name))) + opcode_handle + = (struct xgate_opcode_handle *) str_hash_find (xgate_hash, + op_name); + if (!opcode_handle) { as_bad (_(": processing macro, real opcode handle" " not found in hash")); diff --git a/gas/config/tc-z8k.c b/gas/config/tc-z8k.c index 1886043..60e1d05 100644 --- a/gas/config/tc-z8k.c +++ b/gas/config/tc-z8k.c @@ -151,7 +151,7 @@ md_begin (void) { /* Only enter unique codes into the table. */ if (idx != opcode->idx) - str_hash_insert (opcode_hash_control, opcode->name, (char *) opcode); + str_hash_insert (opcode_hash_control, opcode->name, opcode, 0); idx = opcode->idx; } @@ -166,7 +166,7 @@ md_begin (void) fake_opcode->name = md_pseudo_table[idx].poc_name; fake_opcode->func = (void *) (md_pseudo_table + idx); fake_opcode->opcode = 250; - str_hash_insert (opcode_hash_control, fake_opcode->name, fake_opcode); + str_hash_insert (opcode_hash_control, fake_opcode->name, fake_opcode, 0); } } diff --git a/gas/dw2gencfi.c b/gas/dw2gencfi.c index 964a779..8fc956c 100644 --- a/gas/dw2gencfi.c +++ b/gas/dw2gencfi.c @@ -348,7 +348,7 @@ dwcfi_hash_find_or_make (segT cseg, const char *base_name, int flags) { item = alloc_debugseg_item (make_debug_seg (cseg, name, flags), 0, name); - str_hash_insert (dwcfi_hash, item->seg_name, (char *) item); + str_hash_insert (dwcfi_hash, item->seg_name, item, 0); } else free (name); diff --git a/gas/ecoff.c b/gas/ecoff.c index 8f884bb..69af2ce 100644 --- a/gas/ecoff.c +++ b/gas/ecoff.c @@ -1578,7 +1578,8 @@ add_string (varray_t *vp, /* string obstack */ strcpy (hash_ptr->string, str); - str_hash_insert (hash_tbl, str, (char *) hash_ptr); + if (str_hash_insert (hash_tbl, str, hash_ptr, 0) != NULL) + as_fatal (_("duplicate %s"), str); } if (ret_hash != (shash_t **) NULL) @@ -2030,7 +2031,7 @@ get_tag (const char *tag, /* tag name */ perm = xstrdup (tag); hash_ptr = allocate_shash (); - str_hash_insert (tag_hash, perm, (char *) hash_ptr); + str_hash_insert (tag_hash, perm, hash_ptr, 0); hash_ptr->string = perm; } @@ -20,16 +20,26 @@ #include "as.h" -/* Insert ELEMENT into HTAB. If the element exists, it is overwritten. */ +/* Insert ELEMENT into HTAB. If REPLACE is non-zero existing elements + are overwritten. If ELEMENT already exists, a pointer to the slot + is returned. Otherwise NULL is returned. */ -void -htab_insert (htab_t htab, PTR element) +void ** +htab_insert (htab_t htab, void *element, int replace) { void **slot = htab_find_slot (htab, element, INSERT); - if (slot != NULL && htab->del_f) - (*htab->del_f) (*slot); - + if (*slot != NULL) + { + if (replace) + { + if (htab->del_f) + (*htab->del_f) (*slot); + *slot = element; + } + return slot; + } *slot = element; + return NULL; } /* Print statistics about a hash table. */ @@ -21,9 +21,11 @@ #ifndef HASH_H #define HASH_H -/* Insert ELEMENT into HTAB. If the element exists, it is overwritten. */ +/* Insert ELEMENT into HTAB. If REPLACE is non-zero existing elements + are overwritten. If ELEMENT already exists, a pointer to the slot + is returned. Otherwise NULL is returned. */ -extern void htab_insert (htab_t, void *); +extern void **htab_insert (htab_t, void * /* element */, int /* replace */); /* Print statistics about a hash table. */ @@ -34,7 +36,7 @@ extern void htab_print_statistics (FILE *f, const char *name, htab_t table); struct string_tuple { const char *key; - char *value; + const void *value; }; typedef struct string_tuple string_tuple_t; @@ -60,7 +62,7 @@ eq_string_tuple (const void *a, const void *b) } static inline string_tuple_t * -string_tuple_alloc (const char *key, char *value) +string_tuple_alloc (const char *key, const void *value) { string_tuple_t *tuple = XNEW (string_tuple_t); tuple->key = key; @@ -73,7 +75,7 @@ str_hash_find (htab_t table, const char *key) { string_tuple_t needle = { key, NULL }; string_tuple_t *tuple = htab_find (table, &needle); - return tuple != NULL ? tuple->value : NULL; + return tuple != NULL ? (void *) tuple->value : NULL; } static inline void * @@ -85,7 +87,7 @@ str_hash_find_n (htab_t table, const char *key, size_t n) string_tuple_t needle = { tmp, NULL }; string_tuple_t *tuple = htab_find (table, &needle); free (tmp); - return tuple != NULL ? tuple->value : NULL; + return tuple != NULL ? (void *) tuple->value : NULL; } static inline void @@ -95,10 +97,14 @@ str_hash_delete (htab_t table, const char *key) htab_remove_elt (table, &needle); } -static inline void -str_hash_insert (htab_t table, const char *key, void *value) +static inline void ** +str_hash_insert (htab_t table, const char *key, const void *value, int replace) { - htab_insert (table, string_tuple_alloc (key, value)); + string_tuple_t *elt = string_tuple_alloc (key, value); + void **slot = htab_insert (table, elt, replace); + if (slot && !replace) + free (elt); + return slot; } static inline htab_t diff --git a/gas/macro.c b/gas/macro.c index d99430e..3123ddf 100644 --- a/gas/macro.c +++ b/gas/macro.c @@ -505,6 +505,7 @@ do_formals (macro_entry *macro, size_t idx, sb *in) { formal_entry *formal = new_formal (); size_t cidx; + formal_hash_entry_t *elt; idx = get_token (idx, in, &formal->name); if (formal->name.len == 0) @@ -567,14 +568,15 @@ do_formals (macro_entry *macro, size_t idx, sb *in) } /* Add to macro's hash table. */ - if (formal_entry_find (macro->formal_hash, name) == NULL) - htab_insert (macro->formal_hash, formal_entry_alloc (name, formal)); - else - as_bad_where (macro->file, - macro->line, - _("A parameter named `%s' already exists for macro `%s'"), - name, - macro->name); + elt = formal_entry_alloc (name, formal); + if (htab_insert (macro->formal_hash, elt, 0) != NULL) + { + free (elt); + as_bad_where (macro->file, macro->line, + _("A parameter named `%s' " + "already exists for macro `%s'"), + name, macro->name); + } formal->index = macro->formal_count++; *p = formal; @@ -593,6 +595,7 @@ do_formals (macro_entry *macro, size_t idx, sb *in) if (macro_mri) { formal_entry *formal = new_formal (); + formal_hash_entry_t *elt; /* Add a special NARG formal, which macro_expand will set to the number of arguments. */ @@ -606,13 +609,14 @@ do_formals (macro_entry *macro, size_t idx, sb *in) sb_add_string (&formal->name, name); /* Add to macro's hash table. */ - if (formal_entry_find (macro->formal_hash, name)) - as_bad_where (macro->file, - macro->line, - _("Reserved word `%s' used as parameter in macro `%s'"), - name, - macro->name); - htab_insert (macro->formal_hash, formal_entry_alloc (name, formal)); + elt = formal_entry_alloc (name, formal); + if (htab_insert (macro->formal_hash, elt, 0) != NULL) + { + free (elt); + as_bad_where (macro->file, macro->line, + _("Reserved word `%s' used as parameter in macro `%s'"), + name, macro->name); + } formal->index = NARG_INDEX; *p = formal; @@ -709,10 +713,15 @@ define_macro (size_t idx, sb *in, sb *label, /* And stick it in the macro hash table. */ for (idx = 0; idx < name.len; idx++) name.ptr[idx] = TOLOWER (name.ptr[idx]); - if (macro_entry_find (macro_hash, macro->name)) - error = _("Macro `%s' was already defined"); if (!error) - htab_insert (macro_hash, macro_entry_alloc (macro->name, macro)); + { + macro_hash_entry_t *elt = macro_entry_alloc (macro->name, macro); + if (htab_insert (macro_hash, elt, 0) != NULL) + { + free (elt); + error = _("Macro `%s' was already defined"); + } + } if (namep != NULL) *namep = macro->name; @@ -911,10 +920,20 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals, { const char *name; formal_entry *f = new_formal (); + formal_hash_entry_t *elt; src = get_token (src, in, &f->name); name = sb_terminate (&f->name); - if (formal_entry_find (formal_hash, name) == NULL) + elt = formal_entry_alloc (name, f); + if (htab_insert (formal_hash, elt, 0) != NULL) + { + free (elt); + as_bad_where (macro->file, macro->line + macro_line, + _("`%s' was already used as parameter " + "(or another local) name"), name); + del_formal (f); + } + else { static int loccnt; char buf[20]; @@ -925,16 +944,6 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals, sprintf (buf, IS_ELF ? ".LL%04x" : "LL%04x", ++loccnt); sb_add_string (&f->actual, buf); - - htab_insert (formal_hash, formal_entry_alloc (name, f)); - } - else - { - as_bad_where (macro->file, - macro->line + macro_line, - _("`%s' was already used as parameter (or another local) name"), - name); - del_formal (f); } src = sb_skip_comma (src, in); @@ -1284,7 +1293,8 @@ delete_macro (const char *name) { char *copy; size_t i, len; - macro_entry *macro; + void **slot; + macro_hash_entry_t needle; len = strlen (name); copy = XNEWVEC (char, len + 1); @@ -1292,17 +1302,17 @@ delete_macro (const char *name) copy[i] = TOLOWER (name[i]); copy[i] = '\0'; - /* We can only ask hash_delete to free memory if we are deleting - macros in reverse order to their definition. - So just clear out the entry. */ - macro = macro_entry_find (macro_hash, copy); - if (macro) + needle.name = copy; + needle.macro = NULL; + slot = htab_find_slot (macro_hash, &needle, NO_INSERT); + if (slot) { - htab_insert (macro_hash, macro_entry_alloc (copy, NULL)); - free_macro (macro); + free_macro (((macro_hash_entry_t *) *slot)->macro); + htab_clear_slot (macro_hash, slot); } else as_warn (_("Attempt to purge non-existing macro `%s'"), copy); + free (copy); } /* Handle the MRI IRP and IRPC pseudo-ops. These are handled as a @@ -1334,7 +1344,7 @@ expand_irp (int irpc, size_t idx, sb *in, sb *out, size_t (*get_line) (sb *)) h = htab_create_alloc (16, hash_formal_entry, eq_formal_entry, NULL, xcalloc, free); - htab_insert (h, formal_entry_alloc (sb_terminate (&f.name), &f)); + htab_insert (h, formal_entry_alloc (sb_terminate (&f.name), &f), 0); f.index = 1; f.next = NULL; @@ -563,11 +563,14 @@ pop_insert (const pseudo_typeS *table) const pseudo_typeS *pop; for (pop = table; pop->poc_name; pop++) { - int exists = po_entry_find (po_hash, pop->poc_name) != NULL; - if (!pop_override_ok && exists) - as_fatal (_("error constructing %s pseudo-op table"), pop_table_name); - else if (!exists) - htab_insert (po_hash, po_entry_alloc (pop->poc_name, pop)); + po_entry_t *elt = po_entry_alloc (pop->poc_name, pop); + if (htab_insert (po_hash, elt, 0) != NULL) + { + free (elt); + if (!pop_override_ok) + as_fatal (_("error constructing %s pseudo-op table"), + pop_table_name); + } } } diff --git a/gas/symbols.c b/gas/symbols.c index e823726..50b23d6 100644 --- a/gas/symbols.c +++ b/gas/symbols.c @@ -364,7 +364,7 @@ local_symbol_make (const char *name, segT section, fragS *frag, valueT val) ret->section = section; ret->value = val; - htab_insert (sy_hash, ret); + htab_insert (sy_hash, ret, 1); return ret; } @@ -630,7 +630,7 @@ symbol_table_insert (symbolS *symbolP) { know (symbolP); - htab_insert (sy_hash, symbolP); + htab_insert (sy_hash, symbolP, 1); } /* If a symbol name does not exist, create it as undefined, and insert diff --git a/gas/testsuite/gas/ppc/dcbt.d b/gas/testsuite/gas/ppc/dcbt.d new file mode 100644 index 0000000..49311e8 --- /dev/null +++ b/gas/testsuite/gas/ppc/dcbt.d @@ -0,0 +1,9 @@ +#as: -mpower4 -many +#objdump: -dr -Mpower4 + +.* + +Disassembly of section \.text: + +.*: + 0: (7d 40 5a 2c|2c 5a 40 7d) dcbt 0,r11,10 diff --git a/gas/testsuite/gas/ppc/dcbt.s b/gas/testsuite/gas/ppc/dcbt.s new file mode 100644 index 0000000..d2686cf --- /dev/null +++ b/gas/testsuite/gas/ppc/dcbt.s @@ -0,0 +1,2 @@ + .text + dcbt 0,11,0b01010 diff --git a/gas/testsuite/gas/ppc/ppc.exp b/gas/testsuite/gas/ppc/ppc.exp index 47d3835..561b2b4 100644 --- a/gas/testsuite/gas/ppc/ppc.exp +++ b/gas/testsuite/gas/ppc/ppc.exp @@ -146,3 +146,5 @@ run_dump_test "stringop" run_dump_test "xvtlsbb" run_dump_test "rightmost" run_dump_test "scalarquad" + +run_dump_test "dcbt" |