gas various other const pointer changes

This removes a bunch of casts involving const pointers, in some cases
by making variables const pointers so a cast is not needed.  In a
couple of places the cast hid errors with "&array" written rather than
"array", see iq2000_macro_defs and s_pru_align.  tc-xgate.c cmp_opcode
is changed to be the standard qsort predicate to avoid a function
cast.
diff --git a/gas/config/kvx-parse.c b/gas/config/kvx-parse.c
index 5995d62..06b21c9 100644
--- a/gas/config/kvx-parse.c
+++ b/gas/config/kvx-parse.c
@@ -68,7 +68,7 @@
   if (!relocs)
     return 0;
 
-  struct kvx_reloc **relocs_it = (struct kvx_reloc **) relocs;
+  const struct kvx_reloc **relocs_it = relocs;
   int has_only_one_p = relocs[0] && !relocs[1];
 
   while (*relocs_it)
@@ -101,15 +101,13 @@
   return 0;
 }
 
-struct pseudo_func *
-kvx_get_pseudo_func2 (symbolS * sym, struct kvx_reloc **relocs);
-struct pseudo_func *
-kvx_get_pseudo_func2 (symbolS *sym, struct kvx_reloc **relocs)
+static struct pseudo_func *
+kvx_get_pseudo_func2 (symbolS *sym, const struct kvx_reloc **relocs)
 {
   if (!relocs)
     return NULL;
 
-  struct kvx_reloc **relocs_it = (struct kvx_reloc **) relocs;
+  const struct kvx_reloc **relocs_it = relocs;
 
   for (int i = 0; i < 26; i++)
   {
diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c
index ff915b5..9342d11 100644
--- a/gas/config/obj-elf.c
+++ b/gas/config/obj-elf.c
@@ -942,13 +942,12 @@
 	      if (ISDIGIT (*str))
 		{
 		  char * end;
-		  struct elf_backend_data *bed;
+		  const struct elf_backend_data *bed;
 		  bfd_vma numeric_flags = strtoul (str, &end, 0);
 
 		  attr |= numeric_flags;
 
-		  bed = (struct elf_backend_data *)
-		    get_elf_backend_data (stdoutput);
+		  bed = get_elf_backend_data (stdoutput);
 
 		  if (bed->elf_osabi == ELFOSABI_NONE
 		      || bed->elf_osabi == ELFOSABI_STANDALONE
diff --git a/gas/config/tc-alpha.c b/gas/config/tc-alpha.c
index 613211c..98b93e6 100644
--- a/gas/config/tc-alpha.c
+++ b/gas/config/tc-alpha.c
@@ -2180,7 +2180,7 @@
     basereg = tok[2].X_add_number;
 
   lituse = load_expression (tok[0].X_add_number, &tok[1],
-			    &basereg, &newtok[1], (const char *) opname);
+			    &basereg, &newtok[1], opname);
 
   if (basereg == alpha_gp_register &&
       (symlen > 4 && strcmp (&symname [symlen - 4], "..lk") == 0))
@@ -2189,7 +2189,7 @@
   newtok[0] = tok[0];
   set_tok_preg (newtok[2], basereg);
 
-  assemble_tokens_to_insn ((const char *) opname, newtok, 3, &insn);
+  assemble_tokens_to_insn (opname, newtok, 3, &insn);
 
   if (lituse)
     {
@@ -2227,7 +2227,7 @@
 	as_bad (_("macro requires $at register while noat in effect"));
 
       lituse = load_expression (AXP_REG_AT, &tok[1],
-				&basereg, &newtok[1], (const char *) opname);
+				&basereg, &newtok[1], opname);
     }
   else
     {
@@ -2238,7 +2238,7 @@
   newtok[0] = tok[0];
   set_tok_preg (newtok[2], basereg);
 
-  assemble_tokens_to_insn ((const char *) opname, newtok, 3, &insn);
+  assemble_tokens_to_insn (opname, newtok, 3, &insn);
 
   if (lituse)
     {
@@ -2684,7 +2684,7 @@
 	}
     }
 
-  sym = symbol_find_or_make ((const char *) symname);
+  sym = symbol_find_or_make (symname);
 
   set_tok_reg (newtok[0], AXP_REG_AT);
   set_tok_sym (newtok[1], sym, 0);
@@ -2737,7 +2737,7 @@
   else
     rr = regno (tok[2].X_add_number);
 
-  sym = symbol_find_or_make ((const char *) symname);
+  sym = symbol_find_or_make (symname);
 
   /* Move the operands into the right place.  */
   if (yr == AXP_REG_T10 && xr == AXP_REG_T11)
@@ -2818,7 +2818,7 @@
 	     int ntok,
 	     const void * vopname)
 {
-  const char *opname = (const char *) vopname;
+  const char *opname = vopname;
   struct alpha_insn insn;
   expressionS newtok[3];
   int r, tokidx = 0;
@@ -2914,7 +2914,7 @@
 	     int ntok,
 	     const void * vopname)
 {
-  const char *opname = (const char *) vopname;
+  const char *opname = vopname;
   expressionS newtok[3];
   int r, tokidx = 0;
 
diff --git a/gas/config/tc-arc.c b/gas/config/tc-arc.c
index aa3a0b2..cd1ef33 100644
--- a/gas/config/tc-arc.c
+++ b/gas/config/tc-arc.c
@@ -3659,7 +3659,7 @@
 	  if (!nflg)
 	    continue;
 	  found_flag = false;
-	  unsigned * psflg = (unsigned *)r->flags;
+	  const unsigned *psflg = r->flags;
 	  do
 	    {
 	      tmp = false;
@@ -4673,7 +4673,7 @@
     as_warn ("%s", errmsg);
 
   /* Insert the extension instruction.  */
-  arc_insert_opcode ((const struct arc_opcode *) arc_ext_opcodes);
+  arc_insert_opcode (arc_ext_opcodes);
 
   create_extinst_section (&einsn);
 }
diff --git a/gas/config/tc-d10v.c b/gas/config/tc-d10v.c
index 448c9f3..3bdca91 100644
--- a/gas/config/tc-d10v.c
+++ b/gas/config/tc-d10v.c
@@ -275,7 +275,7 @@
 md_begin (void)
 {
   const char *prev_name = "";
-  struct d10v_opcode *opcode;
+  const struct d10v_opcode *opcode;
   d10v_hash = str_htab_create ();
 
   /* Insert unique names into hash table.  The D10v instruction set
@@ -325,7 +325,7 @@
 }
 
 static bfd_reloc_code_real_type
-get_reloc (struct d10v_operand *op)
+get_reloc (const struct d10v_operand *op)
 {
   int bits = op->bits;
 
@@ -564,7 +564,7 @@
 	  else
 	    {
 	      fixups->fix[fixups->fc].reloc =
-		get_reloc ((struct d10v_operand *) &d10v_operands[opcode->operands[i]]);
+		get_reloc (&d10v_operands[opcode->operands[i]]);
 
 	      /* Check that an immediate was passed to ops that expect one.  */
 	      if ((flags & OPERAND_NUM)
@@ -1521,7 +1521,7 @@
 	}
       else
 	fixP->fx_r_type =
-	  get_reloc ((struct d10v_operand *) &d10v_operands[op_type]);
+	  get_reloc (&d10v_operands[op_type]);
     }
 
   /* Fetch the instruction, insert the fully resolved operand
diff --git a/gas/config/tc-iq2000.c b/gas/config/tc-iq2000.c
index f0259f8..45976e7 100644
--- a/gas/config/tc-iq2000.c
+++ b/gas/config/tc-iq2000.c
@@ -198,29 +198,29 @@
 
 static iq2000_macro_defs_s iq2000_macro_defs[] =
 {
-  {"abs",   (const char **) & abs_expn,   (const char **) & abs_args},
-  {"la",    (const char **) & la_expn,    (const char **) & la_args},
-  {"bge",   (const char **) & bge_expn,   (const char **) & bxx_args},
-  {"bgeu",  (const char **) & bgeu_expn,  (const char **) & bxx_args},
-  {"bgt",   (const char **) & bgt_expn,   (const char **) & bxx_args},
-  {"bgtu",  (const char **) & bgtu_expn,  (const char **) & bxx_args},
-  {"ble",   (const char **) & ble_expn,   (const char **) & bxx_args},
-  {"bleu",  (const char **) & bleu_expn,  (const char **) & bxx_args},
-  {"blt",   (const char **) & blt_expn,   (const char **) & bxx_args},
-  {"bltu",  (const char **) & bltu_expn,  (const char **) & bxx_args},
-  {"sge",   (const char **) & sge_expn,   (const char **) & sxx_args},
-  {"sgeu",  (const char **) & sgeu_expn,  (const char **) & sxx_args},
-  {"sle",   (const char **) & sle_expn,   (const char **) & sxx_args},
-  {"sleu",  (const char **) & sleu_expn,  (const char **) & sxx_args},
-  {"sgt",   (const char **) & sgt_expn,   (const char **) & sxx_args},
-  {"sgtu",  (const char **) & sgtu_expn,  (const char **) & sxx_args},
-  {"seq",   (const char **) & seq_expn,   (const char **) & sxx_args},
-  {"sne",   (const char **) & sne_expn,   (const char **) & sxx_args},
-  {"neg",   (const char **) & neg_expn,   (const char **) & neg_args},
-  {"negu",  (const char **) & negu_expn,  (const char **) & neg_args},
-  {"li",    (const char **) & li_expn,    (const char **) & li_args},
-  {"ori32", (const char **) & ori32_expn, (const char **) & ai32_args},
-  {"andi32",(const char **) & andi32_expn,(const char **) & ai32_args},
+  {"abs",    &abs_expn,    abs_args},
+  {"la",     &la_expn,     la_args},
+  {"bge",    &bge_expn,    bxx_args},
+  {"bgeu",   &bgeu_expn,   bxx_args},
+  {"bgt",    &bgt_expn,    bxx_args},
+  {"bgtu",   &bgtu_expn,   bxx_args},
+  {"ble",    &ble_expn,    bxx_args},
+  {"bleu",   &bleu_expn,   bxx_args},
+  {"blt",    &blt_expn,    bxx_args},
+  {"bltu",   &bltu_expn,   bxx_args},
+  {"sge",    &sge_expn,    sxx_args},
+  {"sgeu",   &sgeu_expn,   sxx_args},
+  {"sle",    &sle_expn,    sxx_args},
+  {"sleu",   &sleu_expn,   sxx_args},
+  {"sgt",    &sgt_expn,    sxx_args},
+  {"sgtu",   &sgtu_expn,   sxx_args},
+  {"seq",    &seq_expn,    sxx_args},
+  {"sne",    &sne_expn,    sxx_args},
+  {"neg",    &neg_expn,    neg_args},
+  {"negu",   &negu_expn,   neg_args},
+  {"li",     &li_expn,     li_args},
+  {"ori32",  &ori32_expn,  ai32_args},
+  {"andi32", &andi32_expn, ai32_args},
 };
 
 static void
diff --git a/gas/config/tc-kvx.c b/gas/config/tc-kvx.c
index 501ce1d..59e2b29 100644
--- a/gas/config/tc-kvx.c
+++ b/gas/config/tc-kvx.c
@@ -700,7 +700,7 @@
   insn->immx1 = NOIMMX;
 
   struct token_list *tok_ = tok;
-  struct kvx_operand **format = (struct kvx_operand **) opcode->format;
+  struct kvx_operand *const *format = opcode->format;
 
   while (tok_)
     {
@@ -1441,8 +1441,8 @@
 static int
 kvxop_compar (const void *a, const void *b)
 {
-  const struct kvxopc *opa = (const struct kvxopc *) a;
-  const struct kvxopc *opb = (const struct kvxopc *) b;
+  const struct kvxopc *opa = a;
+  const struct kvxopc *opb = b;
   int res = strcmp (opa->as_op, opb->as_op);
 
   if (res)
diff --git a/gas/config/tc-metag.c b/gas/config/tc-metag.c
index bb8e897..e6ba16c 100644
--- a/gas/config/tc-metag.c
+++ b/gas/config/tc-metag.c
@@ -267,7 +267,7 @@
 
   entry.name = name;
 
-  reg = (const metag_reg *) htab_find (reg_htab, &entry);
+  reg = htab_find (reg_htab, &entry);
 
   return reg;
 }
@@ -4112,7 +4112,7 @@
   name[len] = '\0';
   entry.name = name;
 
-  _reg = (const metag_reg *) htab_find (dsp_regtab, &entry);
+  _reg = htab_find (dsp_regtab, &entry);
   if (!_reg)
     return NULL;
 
@@ -6003,7 +6003,7 @@
 
   entry.name = buf;
 
-  scond = (const split_condition *) htab_find (scond_htab, &entry);
+  scond = htab_find (scond_htab, &entry);
 
   if (!scond)
     return NULL;
@@ -6324,7 +6324,7 @@
   for (i = 0; i < num_templates; i++)
     {
       const insn_template *template = &metag_optab[i];
-      insn_templates **slot = NULL;
+      void **slot;
       insn_templates *new_entry;
 
       new_entry = XNEW (insn_templates);
@@ -6332,8 +6332,7 @@
       new_entry->template = template;
       new_entry->next = NULL;
 
-      slot = (insn_templates **) htab_find_slot (mnemonic_htab, new_entry,
-						 INSERT);
+      slot = htab_find_slot (mnemonic_htab, new_entry, INSERT);
 
       if (*slot)
 	{
@@ -6355,7 +6354,7 @@
 static hashval_t
 hash_regs (const void *p)
 {
-  metag_reg *rp = (metag_reg *)p;
+  const metag_reg *rp = p;
   char buf[MAX_REG_LEN];
 
   strupper (buf, rp->name);
@@ -6367,8 +6366,8 @@
 static int
 eq_regs (const void *a, const void *b)
 {
-  metag_reg *ra = (metag_reg *)a;
-  metag_reg *rb = (metag_reg *)b;
+  const metag_reg *ra = a;
+  const metag_reg *rb = b;
   return strcasecmp (ra->name, rb->name) == 0;
 }
 
diff --git a/gas/config/tc-nds32.c b/gas/config/tc-nds32.c
index dc5a8af..172132f 100644
--- a/gas/config/tc-nds32.c
+++ b/gas/config/tc-nds32.c
@@ -5209,7 +5209,7 @@
    elimination itself or not, we have to return the next instruction range.  */
 
 static int
-nds32_elf_sethi_range (struct nds32_relocs_pattern *pattern)
+nds32_elf_sethi_range (const struct nds32_relocs_pattern *pattern)
 {
   int range = 0;
   while (pattern)
@@ -5658,12 +5658,12 @@
 /* Find the relaxation pattern according to instructions.  */
 
 static bool
-nds32_find_reloc_table (struct nds32_relocs_pattern *relocs_pattern,
+nds32_find_reloc_table (const struct nds32_relocs_pattern *relocs_pattern,
 			struct nds32_relax_hint_table *hint_info)
 {
   unsigned int opcode, seq_size;
   enum nds32_br_range range;
-  struct nds32_relocs_pattern *pattern, *hi_pattern = NULL;
+  const struct nds32_relocs_pattern *pattern, *hi_pattern = NULL;
   const char *opc = NULL;
   relax_info_t *relax_info = NULL;
   nds32_relax_fixup_info_t *fixup_info, *hint_fixup;
@@ -5928,9 +5928,8 @@
 static void
 nds32_elf_append_relax_relocs (const char *key, const void *value)
 {
-  struct nds32_relocs_pattern *relocs_pattern =
-    (struct nds32_relocs_pattern *) value;
-  struct nds32_relocs_pattern *pattern_temp, *pattern_now;
+  const struct nds32_relocs_pattern *relocs_pattern = value;
+  const struct nds32_relocs_pattern *pattern_temp, *pattern_now;
   symbolS *sym, *hi_sym = NULL;
   expressionS exp;
   fragS *fragP;
@@ -6265,7 +6264,7 @@
 nds32_elf_append_relax_relocs_traverse (void **slot, void *arg ATTRIBUTE_UNUSED)
 {
   string_tuple_t *tuple = *((string_tuple_t **) slot);
-  nds32_elf_append_relax_relocs (tuple->key, (void *) tuple->value);
+  nds32_elf_append_relax_relocs (tuple->key, (const void *) tuple->value);
   return 1;
 }
 
diff --git a/gas/config/tc-pru.c b/gas/config/tc-pru.c
index a51c3d4..a6398fe 100644
--- a/gas/config/tc-pru.c
+++ b/gas/config/tc-pru.c
@@ -341,10 +341,10 @@
     {
       input_line_pointer++;
       fill = get_absolute_expression ();
-      pfill = (const char *) &fill;
+      pfill = &fill;
     }
   else if (subseg_text_p (now_seg))
-    pfill = (const char *) &nop;
+    pfill = nop;
   else
     {
       pfill = NULL;
diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index 6b8bde9..6db93fd 100644
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -4935,7 +4935,7 @@
 
 	  /* Record PCREL_HI20.  */
 	  if (!riscv_record_pcrel_fixup (riscv_pcrel_hi_fixup_hash,
-					 (const asection *) seg,
+					 seg,
 					 md_pcrel_from (fixP),
 					 fixP->fx_addsy,
 					 target))
@@ -4964,8 +4964,7 @@
 	 and set fx_done for -mno-relax.  */
       {
 	bfd_vma location_pcrel_hi = S_GET_VALUE (fixP->fx_addsy) + *valP;
-	riscv_pcrel_hi_fixup search =
-		{(const asection *) seg, location_pcrel_hi, 0, 0};
+	riscv_pcrel_hi_fixup search = {seg, location_pcrel_hi, 0, 0};
 	riscv_pcrel_hi_fixup *entry = htab_find (riscv_pcrel_hi_fixup_hash,
 						 &search);
 	if (entry && entry->symbol
diff --git a/gas/config/tc-score.c b/gas/config/tc-score.c
index 03f9559..47f3050 100644
--- a/gas/config/tc-score.c
+++ b/gas/config/tc-score.c
@@ -6477,17 +6477,16 @@
 }
 
 static valueT
-s3_normal_chars_to_number (char *buf, int n)
+s3_normal_chars_to_number (const char *buf, int n)
 {
   valueT result = 0;
-  unsigned char *where = (unsigned char *)buf;
 
   if (target_big_endian)
     {
       while (n--)
         {
           result <<= 8;
-          result |= (*where++ & 255);
+          result |= (*buf++ & 255);
         }
     }
   else
@@ -6495,7 +6494,7 @@
       while (n--)
         {
           result <<= 8;
-          result |= (where[n] & 255);
+          result |= (buf[n] & 255);
         }
     }
 
@@ -6528,7 +6527,7 @@
 static valueT
 s3_chars_to_number_littleendian (const void *p, int n)
 {
-  char *buf = (char *) p;
+  const char *buf = p;
   valueT result = 0;
 
   switch (n)
diff --git a/gas/config/tc-xgate.c b/gas/config/tc-xgate.c
index 9c77fef..8d1f474 100644
--- a/gas/config/tc-xgate.c
+++ b/gas/config/tc-xgate.c
@@ -104,7 +104,7 @@
 static char *extract_word (char *, char *, int);
 static struct xgate_opcode *xgate_find_match (struct xgate_opcode_handle *,
 					      int, s_operand [], unsigned int);
-static int cmp_opcode (struct xgate_opcode *, struct xgate_opcode *);
+static int cmp_opcode (const void *, const void *);
 static void xgate_print_table (void);
 static unsigned int xgate_get_operands (char *, s_operand []);
 static register_id reg_name_search (char *);
@@ -308,7 +308,7 @@
     xgate_op_table[i] = xgate_opcode_ptr[i];
 
   qsort (xgate_op_table, xgate_num_opcodes, sizeof (struct xgate_opcode),
-	 (int (*)(const void *, const void *)) cmp_opcode);
+	 cmp_opcode);
 
   /* Calculate number of handles since this will be
      smaller than the raw number of opcodes in the table.  */
@@ -896,8 +896,10 @@
 }
 
 static int
-cmp_opcode (struct xgate_opcode *op1, struct xgate_opcode *op2)
+cmp_opcode (const void *p1, const void *p2)
 {
+  const struct xgate_opcode *op1 = p1;
+  const struct xgate_opcode *op2 = p2;
   return strcmp (op1->name, op2->name);
 }
 
diff --git a/gas/symbols.c b/gas/symbols.c
index b76415a..94d0f4d 100644
--- a/gas/symbols.c
+++ b/gas/symbols.c
@@ -2172,10 +2172,10 @@
    If the name wasn't generated by foo_label_name(), then return it
    unaltered.  This is used for error messages.  */
 
-char *
-decode_local_label_name (char *s)
+const char *
+decode_local_label_name (const char *s)
 {
-  char *p;
+  const char *p;
   char *symbol_decode;
   unsigned int label_number;
   unsigned int instance_number;
@@ -2365,7 +2365,7 @@
 S_IS_DEFINED (const symbolS *s)
 {
   if (s->flags.local_symbol)
-    return ((struct local_symbol *) s)->section != undefined_section;
+    return ((const struct local_symbol *) s)->section != undefined_section;
   return s->bsym->section != undefined_section;
 }
 
@@ -2382,7 +2382,7 @@
 {
   segT sec;
   if (s->flags.local_symbol)
-    sec = ((struct local_symbol *) s)->section;
+    sec = ((const struct local_symbol *) s)->section;
   else
     {
       if ((strict
@@ -2456,7 +2456,7 @@
 S_CAN_BE_REDEFINED (const symbolS *s)
 {
   if (s->flags.local_symbol)
-    return (((struct local_symbol *) s)->frag
+    return (((const struct local_symbol *) s)->frag
 	    == &predefined_address_frag);
   /* Permit register names to be redefined.  */
   return s->x->value.X_op == O_register;
@@ -2488,7 +2488,7 @@
 S_GET_SEGMENT (const symbolS *s)
 {
   if (s->flags.local_symbol)
-    return ((struct local_symbol *) s)->section;
+    return ((const struct local_symbol *) s)->section;
   return s->bsym->section;
 }
 
diff --git a/gas/symbols.h b/gas/symbols.h
index 7524e2f..75d014c 100644
--- a/gas/symbols.h
+++ b/gas/symbols.h
@@ -54,7 +54,7 @@
 char * symbol_relc_make_expr  (expressionS *);
 char * symbol_relc_make_sym   (symbolS *);
 char * symbol_relc_make_value (offsetT);
-char *decode_local_label_name (char *s);
+const char *decode_local_label_name (const char *);
 symbolS *symbol_find (const char *name);
 symbolS *symbol_find_noref (const char *name, int noref);
 symbolS *symbol_find_exact (const char *name);
diff --git a/gas/write.c b/gas/write.c
index 353b11c..fcacf20 100644
--- a/gas/write.c
+++ b/gas/write.c
@@ -2379,7 +2379,7 @@
 	  if (name)
 	    {
 	      const char *name2 =
-		decode_local_label_name ((char *) S_GET_NAME (symp));
+		decode_local_label_name (S_GET_NAME (symp));
 	      /* They only differ if `name' is a fb or dollar local
 		 label name.  */
 	      if (name2 != name && ! S_IS_DEFINED (symp))