diff options
author | Alan Modra <amodra@gmail.com> | 2020-08-22 17:59:57 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2020-08-23 21:38:05 +0930 |
commit | fe0e921f00237abd926cd9efaeedf758b17170de (patch) | |
tree | eb20c7e2834f06e114323d816077d4c99884a3ab /gas/config/tc-arm.c | |
parent | b8fff44e0e2e43e1823413eec7c5f6fa9d219ce7 (diff) | |
download | gdb-fe0e921f00237abd926cd9efaeedf758b17170de.zip gdb-fe0e921f00237abd926cd9efaeedf758b17170de.tar.gz gdb-fe0e921f00237abd926cd9efaeedf758b17170de.tar.bz2 |
PR26513, 629310abec breaks assembling PowerPC Linux kernels
Inserting with replacement is wrong for some gas hash table uses.
This patch implements an htab_insert that conditionally replaces, and
similarly for str_hash_insert. str_hash_insert with replace=0 is
roughly equivalent to the older hash_insert, and str_hash_insert with
replace=1 to the older hash_jam, but return values are different. I
found it useful to know whether the slot was occupied prior to
inserting/replacing. I've also reinstated the fatal errors on messing
up opcode tables with duplicates.
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.
Diffstat (limited to 'gas/config/tc-arm.c')
-rw-r--r-- | gas/config/tc-arm.c | 45 |
1 files changed, 23 insertions, 22 deletions
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 |