]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gas/config/tc-score7.c
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / gas / config / tc-score7.c
index 30b1128a6eb949aedca237288eb762a442fcede3..b1194b3da00670095bc65a1c6a11e1b29fbc02ab 100644 (file)
@@ -1,5 +1,5 @@
 /* tc-score7.c -- Assembler for Score7
-   Copyright 2009 Free Software Foundation, Inc.
+   Copyright (C) 2009-2021 Free Software Foundation, Inc.
    Contributed by:
    Brain.lin (brain.lin@sunplusct.com)
    Mei Ligang (ligang@sunnorth.com.cn)
@@ -27,7 +27,6 @@
 #include "subsegs.h"
 #include "safe-ctype.h"
 #include "opcode/score-inst.h"
-#include "struc-symbol.h"
 #include "libiberty.h"
 
 #ifdef OBJ_ELF
@@ -143,7 +142,6 @@ static void s7_do_lw_pic (char *);
 #define s7_GET_INSN_SIZE(type) ((s7_GET_INSN_CLASS (type) == INSN_CLASS_16) \
                              ? s7_INSN16_SIZE : s7_INSN_SIZE)
 
-#define s7_MAX_LITTLENUMS 6
 #define s7_INSN_NAME_LEN 16
 
 /* Relax will need some padding for alignment.  */
@@ -191,7 +189,7 @@ enum s7_insn_type_for_dependency
 
 struct s7_insn_to_dependency
 {
-  char *insn_name;
+  const char *insn_name;
   enum s7_insn_type_for_dependency type;
 };
 
@@ -324,7 +322,7 @@ static const struct s7_insn_to_dependency s7_insn_to_dependency_table[] =
   {"mvpl",      s7_D_cond_mv},
   {"mvvs",      s7_D_cond_mv},
   {"mvvc",      s7_D_cond_mv},
-  /* move spectial instruction.  */
+  /* move special instruction.  */
   {"mtcr",      s7_D_mtcr},
   {"mftlb",     s7_D_mftlb},
   {"mtptlb",    s7_D_mtptlb},
@@ -401,9 +399,9 @@ static const struct s7_data_dependency s7_data_dependency_table[] =
   {s7_D_mtcr, "cr1", s7_D_pce, "", 2, 1, 0},
   {s7_D_mtcr, "cr1", s7_D_cond_br, "", 1, 0, 1},
   {s7_D_mtcr, "cr1", s7_D_cond_mv, "", 1, 0, 1},
-  /* Status regiser.  */
+  /* Status register.  */
   {s7_D_mtcr, "cr0", s7_D_all_insn, "", 5, 4, 0},
-  /* CCR regiser.  */
+  /* CCR register.  */
   {s7_D_mtcr, "cr4", s7_D_all_insn, "", 6, 5, 0},
   /* EntryHi/EntryLo register.  */
   {s7_D_mftlb, "", s7_D_mtptlb, "", 1, 1, 1},
@@ -522,7 +520,7 @@ struct s7_reg_map
 {
   const struct s7_reg_entry *names;
   int max_regno;
-  struct hash_control *htab;
+  htab_t htab;
   const char *expected;
 };
 
@@ -533,8 +531,8 @@ static struct s7_reg_map s7_all_reg_maps[] =
   {s7_score_crn_table, 31, NULL, N_("S+core co-processor register expected")},
 };
 
-static struct hash_control *s7_score_ops_hsh = NULL;
-static struct hash_control *s7_dependency_insn_hsh = NULL;
+static htab_t s7_score_ops_hsh = NULL;
+static htab_t s7_dependency_insn_hsh = NULL;
 
 \f
 struct s7_datafield_range
@@ -597,7 +595,7 @@ static struct s7_datafield_range s7_score_df_range[] =
 struct s7_asm_opcode
 {
   /* Instruction name.  */
-  const char *template;
+  const char *template_name;
 
   /* Instruction Opcode.  */
   bfd_vma value;
@@ -1114,7 +1112,7 @@ s7_end_of_line (char *str)
 }
 
 static int
-s7_score_reg_parse (char **ccp, struct hash_control *htab)
+s7_score_reg_parse (char **ccp, htab_t htab)
 {
   char *start = *ccp;
   char c;
@@ -1131,7 +1129,7 @@ s7_score_reg_parse (char **ccp, struct hash_control *htab)
     c = *p++;
 
   *--p = 0;
-  reg = (struct s7_reg_entry *) hash_find (htab, start);
+  reg = (struct s7_reg_entry *) str_hash_find (htab, start);
   *p = c;
 
   if (reg)
@@ -1260,12 +1258,12 @@ static int
 s7_my_get_expression (expressionS * ep, char **str)
 {
   char *save_in;
-  segT seg;
 
   save_in = input_line_pointer;
   input_line_pointer = *str;
   s7_in_my_get_expression = 1;
-  seg = expression (ep);
+
+  (void) expression (ep);
   s7_in_my_get_expression = 0;
 
   if (ep->X_op == O_illegal)
@@ -2323,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 *) 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;
@@ -2491,7 +2490,7 @@ s7_handle_dependency (struct s7_score_it *theinst)
              if (remainder_bubbles <= 2)
                {
                  if (s7_warn_fix_data_dependency)
-                   as_warn (_("Fix data dependency: %s %s -- %s %s  (insert %d nop!/%d)"),
+                   as_warn (_("Fix data dependency: %s %s -- %s %s (insert %d nop!/%d)"),
                             s7_dependency_vector[i].name, s7_dependency_vector[i].reg,
                             s7_dependency_vector[0].name, s7_dependency_vector[0].reg,
                             remainder_bubbles, bubbles);
@@ -2510,7 +2509,7 @@ s7_handle_dependency (struct s7_score_it *theinst)
              else
                {
                  if (s7_warn_fix_data_dependency)
-                   as_warn (_("Fix data dependency: %s %s -- %s %s  (insert 1 pflush/%d)"),
+                   as_warn (_("Fix data dependency: %s %s -- %s %s (insert 1 pflush/%d)"),
                             s7_dependency_vector[i].name, s7_dependency_vector[i].reg,
                             s7_dependency_vector[0].name, s7_dependency_vector[0].reg,
                             bubbles);
@@ -2526,14 +2525,14 @@ s7_handle_dependency (struct s7_score_it *theinst)
             {
              if (warn_or_error)
                {
-                  as_bad (_("data dependency: %s %s -- %s %s  (%d/%d bubble)"),
+                  as_bad (_("data dependency: %s %s -- %s %s (%d/%d bubble)"),
                            s7_dependency_vector[i].name, s7_dependency_vector[i].reg,
                            s7_dependency_vector[0].name, s7_dependency_vector[0].reg,
                            remainder_bubbles, bubbles);
                }
              else
                {
-                  as_warn (_("data dependency: %s %s -- %s %s  (%d/%d bubble)"),
+                  as_warn (_("data dependency: %s %s -- %s %s (%d/%d bubble)"),
                            s7_dependency_vector[i].name, s7_dependency_vector[i].reg,
                            s7_dependency_vector[0].name, s7_dependency_vector[0].reg,
                            remainder_bubbles, bubbles);
@@ -2620,7 +2619,7 @@ s7_get_insn_class_from_type (enum score_insn_type type)
 }
 
 static unsigned long
-s7_adjust_paritybit (unsigned long m_code, enum insn_class class)
+s7_adjust_paritybit (unsigned long m_code, enum insn_class i_class)
 {
   unsigned long result = 0;
   unsigned long m_code_high = 0;
@@ -2628,22 +2627,22 @@ s7_adjust_paritybit (unsigned long m_code, enum insn_class class)
   unsigned long pb_high = 0;
   unsigned long pb_low = 0;
 
-  if (class == INSN_CLASS_32)
+  if (i_class == INSN_CLASS_32)
     {
       pb_high = 0x80000000;
       pb_low = 0x00008000;
     }
-  else if (class == INSN_CLASS_16)
+  else if (i_class == INSN_CLASS_16)
     {
       pb_high = 0;
       pb_low = 0;
     }
-  else if (class == INSN_CLASS_PCE)
+  else if (i_class == INSN_CLASS_PCE)
     {
       pb_high = 0;
       pb_low = 0x00008000;
     }
-  else if (class == INSN_CLASS_SYN)
+  else if (i_class == INSN_CLASS_SYN)
     {
       /* FIXME.  at this time, INSN_CLASS_SYN must be 32 bit, but, instruction type should
          be changed if macro instruction has been expanded.  */
@@ -2723,7 +2722,7 @@ s7_gen_insn_frag (struct s7_score_it *part_1, struct s7_score_it *part_2)
   /* Here, we must call frag_grow in order to keep the instruction frag type is
      rs_machine_dependent.
      For, frag_var may change frag_now->fr_type to rs_fill by calling frag_grow which
-     acturally will call frag_wane.
+     actually will call frag_wane.
      Calling frag_grow first will create a new frag_now which free size is 20 that is enough
      for frag_var.  */
   frag_grow (20);
@@ -2791,11 +2790,12 @@ s7_parse_16_32_inst (char *insnstr, bfd_boolean gen_frag_p)
   c = *p;
   *p = '\0';
 
-  opcode = (const struct s7_asm_opcode *) 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));
-  sprintf (s7_inst.str, "%s", insnstr);
+  strcpy (s7_inst.str, insnstr);
   if (opcode)
     {
       s7_inst.instruction = opcode->value;
@@ -2804,7 +2804,7 @@ s7_parse_16_32_inst (char *insnstr, bfd_boolean gen_frag_p)
       s7_inst.size = s7_GET_INSN_SIZE (s7_inst.type);
       s7_inst.relax_size = 0;
       s7_inst.bwarn = 0;
-      sprintf (s7_inst.name, "%s", opcode->template);
+      strcpy (s7_inst.name, opcode->template_name);
       strcpy (s7_inst.reg, "");
       s7_inst.error = NULL;
       s7_inst.reloc.type = BFD_RELOC_NONE;
@@ -3096,14 +3096,12 @@ s7_do_ldst_insn (char *str)
   int conflict_reg;
   int value;
   char * temp;
-  char *strbak;
   char *dataptr;
   int reg;
   int ldst_idx = 0;
 
   int hex_p = 0;
 
-  strbak = str;
   s7_skip_whitespace (str);
 
   if (((conflict_reg = s7_reg_required_here (&str, 20, s7_REG_TYPE_SCORE)) == (int) s7_FAIL)
@@ -3306,7 +3304,6 @@ s7_do_ldst_insn (char *str)
 
           if (s7_inst.reloc.exp.X_op == O_constant)
             {
-              int value;
               unsigned int data_type;
 
               if (pre_inc == 1)
@@ -4203,7 +4200,7 @@ s7_build_la_pic (int reg_rd, expressionS exp)
       /* Fix part
          For an external symbol: lw rD, <sym>($gp)
                                  (BFD_RELOC_SCORE_GOT15 or BFD_RELOC_SCORE_CALL15)  */
-      sprintf (tmp, "lw_pic r%d, %s", reg_rd, add_symbol->bsym->name);
+      sprintf (tmp, "lw_pic r%d, %s", reg_rd, S_GET_NAME (add_symbol));
       if (s7_append_insn (tmp, FALSE) == (int) s7_FAIL)
        return;
 
@@ -4217,7 +4214,7 @@ s7_build_la_pic (int reg_rd, expressionS exp)
         addi rD, <sym>       (BFD_RELOC_GOT_LO16) */
       s7_inst.reloc.type = BFD_RELOC_SCORE_GOT15;
       memcpy (&var_insts[0], &s7_inst, sizeof (struct s7_score_it));
-      sprintf (tmp, "addi_s_pic r%d, %s", reg_rd, add_symbol->bsym->name);
+      sprintf (tmp, "addi_s_pic r%d, %s", reg_rd, S_GET_NAME (add_symbol));
       if (s7_append_insn (tmp, FALSE) == (int) s7_FAIL)
        return;
 
@@ -4227,7 +4224,7 @@ s7_build_la_pic (int reg_rd, expressionS exp)
   else if (add_number >= -0x8000 && add_number <= 0x7fff)
     {
       /* Insn 1: lw rD, <sym>($gp)    (BFD_RELOC_SCORE_GOT15)  */
-      sprintf (tmp, "lw_pic r%d, %s", reg_rd, add_symbol->bsym->name);
+      sprintf (tmp, "lw_pic r%d, %s", reg_rd, S_GET_NAME (add_symbol));
       if (s7_append_insn (tmp, TRUE) == (int) s7_FAIL)
        return;
 
@@ -4244,7 +4241,8 @@ s7_build_la_pic (int reg_rd, expressionS exp)
 
       /* Var part
         For a local symbol: addi rD, <sym>+<constant>    (BFD_RELOC_GOT_LO16)  */
-      sprintf (tmp, "addi_s_pic r%d, %s + %d", reg_rd, add_symbol->bsym->name, (int) add_number);
+      sprintf (tmp, "addi_s_pic r%d, %s + %d", reg_rd,
+              S_GET_NAME (add_symbol), (int) add_number);
       if (s7_append_insn (tmp, FALSE) == (int) s7_FAIL)
        return;
 
@@ -4257,7 +4255,7 @@ s7_build_la_pic (int reg_rd, expressionS exp)
       int lo = add_number & 0x0000FFFF;
 
       /* Insn 1: lw rD, <sym>($gp)    (BFD_RELOC_SCORE_GOT15)  */
-      sprintf (tmp, "lw_pic r%d, %s", reg_rd, add_symbol->bsym->name);
+      sprintf (tmp, "lw_pic r%d, %s", reg_rd, S_GET_NAME (add_symbol));
       if (s7_append_insn (tmp, TRUE) == (int) s7_FAIL)
        return;
 
@@ -4274,7 +4272,7 @@ s7_build_la_pic (int reg_rd, expressionS exp)
 
       /* Var part
         For a local symbol: ldis r1, HI%<constant>
-         but, if lo is outof 16 bit, make hi plus 1  */
+         but, if lo is out of 16 bit, make hi plus 1  */
       if ((lo < -0x8000) || (lo > 0x7fff))
        {
          hi += 1;
@@ -4299,7 +4297,7 @@ s7_build_la_pic (int reg_rd, expressionS exp)
 
       /* Var part
         For a local symbol: addi r1, <sym>+LO%<constant>    (BFD_RELOC_GOT_LO16)  */
-      sprintf (tmp, "addi_u_pic r1, %s + %d", add_symbol->bsym->name, lo);
+      sprintf (tmp, "addi_u_pic r1, %s + %d", S_GET_NAME (add_symbol), lo);
       if (s7_append_insn (tmp, FALSE) == (int) s7_FAIL)
        return;
 
@@ -4664,7 +4662,7 @@ s7_build_lwst_pic (int reg_rd, expressionS exp, const char *insn_name)
       /* Fix part
          For an external symbol: lw rD, <sym>($gp)
                                  (BFD_RELOC_SCORE_GOT15)  */
-      sprintf (tmp, "lw_pic r1, %s", add_symbol->bsym->name);
+      sprintf (tmp, "lw_pic r1, %s", S_GET_NAME (add_symbol));
       if (s7_append_insn (tmp, FALSE) == (int) s7_FAIL)
         return;
 
@@ -4676,7 +4674,7 @@ s7_build_lwst_pic (int reg_rd, expressionS exp, const char *insn_name)
         addi rD, <sym>       (BFD_RELOC_GOT_LO16) */
       s7_inst.reloc.type = BFD_RELOC_SCORE_GOT15;
       memcpy (&var_insts[0], &s7_inst, sizeof (struct s7_score_it));
-      sprintf (tmp, "addi_s_pic r1, %s", add_symbol->bsym->name);
+      sprintf (tmp, "addi_s_pic r1, %s", S_GET_NAME (add_symbol));
       if (s7_append_insn (tmp, FALSE) == (int) s7_FAIL)
         return;
 
@@ -4789,7 +4787,8 @@ s7_do_macro_ldst_label (char *str)
         {
           int ldst_idx = 0;
           ldst_idx = s7_inst.instruction & OPC_PSEUDOLDST_MASK;
-          s7_build_lwst_pic (reg_rd, s7_inst.reloc.exp, s7_score_ldst_insns[ldst_idx * 3 + 0].template);
+          s7_build_lwst_pic (reg_rd, s7_inst.reloc.exp,
+                             s7_score_ldst_insns[ldst_idx * 3 + 0].template_name);
           return;
         }
       else
@@ -5092,20 +5091,22 @@ s7_build_score_ops_hsh (void)
   for (i = 0; i < sizeof (s7_score_insns) / sizeof (struct s7_asm_opcode); i++)
     {
       const struct s7_asm_opcode *insn = s7_score_insns + i;
-      unsigned len = strlen (insn->template);
-      struct s7_asm_opcode *new;
-      char *template;
-      new = obstack_alloc (&insn_obstack, sizeof (struct s7_asm_opcode));
-      template = obstack_alloc (&insn_obstack, len + 1);
-
-      strcpy (template, insn->template);
-      new->template = template;
-      new->parms = insn->parms;
-      new->value = insn->value;
-      new->relax_value = insn->relax_value;
-      new->type = insn->type;
-      new->bitmask = insn->bitmask;
-      hash_insert (s7_score_ops_hsh, new->template, (void *) new);
+      size_t len = strlen (insn->template_name);
+      struct s7_asm_opcode *new_opcode;
+      char *template_name;
+      new_opcode = (struct s7_asm_opcode *)
+          obstack_alloc (&insn_obstack, sizeof (struct s7_asm_opcode));
+      template_name = (char *) obstack_alloc (&insn_obstack, len + 1);
+
+      strcpy (template_name, insn->template_name);
+      new_opcode->template_name = template_name;
+      new_opcode->parms = insn->parms;
+      new_opcode->value = insn->value;
+      new_opcode->relax_value = insn->relax_value;
+      new_opcode->type = insn->type;
+      new_opcode->bitmask = insn->bitmask;
+      str_hash_insert (s7_score_ops_hsh, new_opcode->template_name,
+                      new_opcode, 0);
     }
 }
 
@@ -5119,15 +5120,19 @@ s7_build_dependency_insn_hsh (void)
   for (i = 0; i < ARRAY_SIZE (s7_insn_to_dependency_table); i++)
     {
       const struct s7_insn_to_dependency *tmp = s7_insn_to_dependency_table + i;
-      unsigned len = strlen (tmp->insn_name);
-      struct s7_insn_to_dependency *new;
+      size_t len = strlen (tmp->insn_name);
+      struct s7_insn_to_dependency *new_i2d;
+      char *insn_name;
 
-      new = obstack_alloc (&dependency_obstack, sizeof (struct s7_insn_to_dependency));
-      new->insn_name = obstack_alloc (&dependency_obstack, len + 1);
+      new_i2d = (struct s7_insn_to_dependency *)
+          obstack_alloc (&dependency_obstack,
+                         sizeof (struct s7_insn_to_dependency));
+      insn_name = (char *) obstack_alloc (&dependency_obstack, len + 1);
 
-      strcpy (new->insn_name, tmp->insn_name);
-      new->type = tmp->type;
-      hash_insert (s7_dependency_insn_hsh, new->insn_name, (void *) new);
+      strcpy (insn_name, tmp->insn_name);
+      new_i2d->insn_name = insn_name;
+      new_i2d->type = tmp->type;
+      str_hash_insert (s7_dependency_insn_hsh, new_i2d->insn_name, new_i2d, 0);
     }
 }
 
@@ -5184,7 +5189,7 @@ s7_pic_need_relax (symbolS *sym, asection *segtype)
   linkonce = FALSE;
   if (symsec != segtype && ! S_IS_LOCAL (sym))
     {
-      if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE) != 0)
+      if ((bfd_section_flags (symsec) & SEC_LINK_ONCE) != 0)
        linkonce = TRUE;
 
       /* The GNU toolchain uses an extension for ELF: a section
@@ -5196,10 +5201,10 @@ s7_pic_need_relax (symbolS *sym, asection *segtype)
     }
 
   /* This must duplicate the test in adjust_reloc_syms.  */
-  return (symsec != &bfd_und_section
-           && symsec != &bfd_abs_section
-         && ! bfd_is_com_section (symsec)
-           && !linkonce
+  return (!bfd_is_und_section (symsec)
+         && !bfd_is_abs_section (symsec)
+         && !bfd_is_com_section (symsec)
+         && !linkonce
 #ifdef OBJ_ELF
          /* A global or weak symbol is treated as external.  */
          && (OUTPUT_FLAVOR != bfd_target_elf_flavour
@@ -5221,7 +5226,7 @@ s7_judge_size_before_relax (fragS * fragp, asection *sec)
   if (change == 1)
     {
       /* Only at the first time determining whether s7_GP instruction relax should be done,
-         return the difference between insntruction size and instruction relax size.  */
+         return the difference between instruction size and instruction relax size.  */
       if (fragp->fr_opcode == NULL)
        {
          fragp->fr_fix = s7_RELAX_NEW (fragp->fr_subtype);
@@ -5238,8 +5243,6 @@ s7_b32_relax_to_b16 (fragS * fragp)
 {
   int grows = 0;
   int relaxable_p = 0;
-  int old;
-  int new;
   int frag_addr = fragp->fr_address + fragp->insn_addr;
 
   addressT symbol_address = 0;
@@ -5253,8 +5256,6 @@ s7_b32_relax_to_b16 (fragS * fragp)
      so in relax stage , it may be wrong to calculate the symbol's offset when the frag's section
      is different from the symbol's.  */
 
-  old = s7_RELAX_OLD (fragp->fr_subtype);
-  new = s7_RELAX_NEW (fragp->fr_subtype);
   relaxable_p = s7_RELAX_OPT (fragp->fr_subtype);
 
   s = fragp->fr_symbol;
@@ -5262,10 +5263,7 @@ s7_b32_relax_to_b16 (fragS * fragp)
   if (s == NULL)
     frag_addr = 0;
   else
-    {
-      if (s->bsym != 0)
-       symbol_address = (addressT) s->sy_frag->fr_address;
-    }
+    symbol_address = (addressT) symbol_get_frag (s)->fr_address;
 
   value = s7_md_chars_to_number (fragp->fr_literal, s7_INSN_SIZE);
 
@@ -5279,7 +5277,7 @@ s7_b32_relax_to_b16 (fragS * fragp)
     abs_value = 0xffffffff - abs_value + 1;
 
   /* Relax branch 32 to branch 16.  */
-  if (relaxable_p && (s->bsym != NULL) && ((abs_value & 0xffffff00) == 0)
+  if (relaxable_p && ((abs_value & 0xffffff00) == 0)
       && (S_IS_DEFINED (s) && !S_IS_COMMON (s) && !S_IS_EXTERNAL (s)))
     {
       /* do nothing.  */
@@ -5308,12 +5306,12 @@ s7_parse_pce_inst (char *insnstr)
   p = strstr (insnstr, "||");
   c = *p;
   *p = '\0';
-  sprintf (first, "%s", insnstr);
+  strcpy (first, insnstr);
 
   /* Get second part string of PCE.  */
   *p = c;
   p += 2;
-  sprintf (second, "%s", p);
+  strcpy (second, p);
 
   s7_parse_16_32_inst (first, FALSE);
   if (s7_inst.error)
@@ -5337,7 +5335,7 @@ s7_parse_pce_inst (char *insnstr)
       || ((pec_part_1.size == s7_INSN16_SIZE) && (s7_inst.size == s7_INSN_SIZE)))
     {
       s7_inst.error = _("pce instruction error (16 bit || 16 bit)'");
-      sprintf (s7_inst.str, insnstr);
+      strcpy (s7_inst.str, insnstr);
       return;
     }
 
@@ -5348,12 +5346,12 @@ s7_parse_pce_inst (char *insnstr)
 \f
 
 static void
-s7_insert_reg (const struct s7_reg_entry *r, struct hash_control *htab)
+s7_insert_reg (const struct s7_reg_entry *r, htab_t htab)
 {
   int i = 0;
   int len = strlen (r->name) + 2;
-  char *buf = xmalloc (len);
-  char *buf2 = xmalloc (len);
+  char *buf = XNEWVEC (char, len);
+  char *buf2 = XNEWVEC (char, len);
 
   strcpy (buf + i, r->name);
   for (i = 0; buf[i]; i++)
@@ -5362,8 +5360,8 @@ s7_insert_reg (const struct s7_reg_entry *r, struct hash_control *htab)
     }
   buf2[i] = '\0';
 
-  hash_insert (htab, buf, (void *) r);
-  hash_insert (htab, buf2, (void *) r);
+  str_hash_insert (htab, buf, r, 0);
+  str_hash_insert (htab, buf2, r, 0);
 }
 
 static void
@@ -5371,14 +5369,9 @@ s7_build_reg_hsh (struct s7_reg_map *map)
 {
   const struct s7_reg_entry *r;
 
-  if ((map->htab = hash_new ()) == NULL)
-    {
-      as_fatal (_("virtual memory exhausted"));
-    }
+  map->htab = str_htab_create ();
   for (r = map->names; r->name != NULL; r++)
-    {
-      s7_insert_reg (r, map->htab);
-    }
+    s7_insert_reg (r, map->htab);
 }
 
 \f
@@ -5402,7 +5395,7 @@ static void
 s7_s_section (int ignore)
 {
   obj_elf_section (ignore);
-  if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
+  if ((bfd_section_flags (now_seg) & SEC_CODE) != 0)
     record_alignment (now_seg, 2);
 
 }
@@ -5425,14 +5418,16 @@ s7_s_change_sec (int sec)
     {
     case 'r':
       seg = subseg_new (s7_RDATA_SECTION_NAME, (subsegT) get_absolute_expression ());
-      bfd_set_section_flags (stdoutput, seg, (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_RELOC | SEC_DATA));
+      bfd_set_section_flags (seg, (SEC_ALLOC | SEC_LOAD | SEC_READONLY
+                                  | SEC_RELOC | SEC_DATA));
       if (strcmp (TARGET_OS, "elf") != 0)
         record_alignment (seg, 4);
       demand_empty_rest_of_line ();
       break;
     case 's':
       seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
-      bfd_set_section_flags (stdoutput, seg, SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA);
+      bfd_set_section_flags (seg, (SEC_ALLOC | SEC_LOAD | SEC_RELOC
+                                  | SEC_DATA | SEC_SMALL_DATA));
       if (strcmp (TARGET_OS, "elf") != 0)
         record_alignment (seg, 4);
       demand_empty_rest_of_line ();
@@ -5471,10 +5466,9 @@ s7_get_symbol (void)
   char *name;
   symbolS *p;
 
-  name = input_line_pointer;
-  c = get_symbol_end ();
+  c = get_symbol_name (&name);
   p = (symbolS *) symbol_find_or_make (name);
-  *input_line_pointer = c;
+  (void) restore_line_pointer (c);
   return p;
 }
 
@@ -5543,17 +5537,10 @@ s7_s_score_ent (int aent)
   if (ISDIGIT (*input_line_pointer) || *input_line_pointer == '-')
     s7_get_number ();
 
-#ifdef BFD_ASSEMBLER
-  if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
-    maybe_text = 1;
-  else
-    maybe_text = 0;
-#else
-  if (now_seg != data_section && now_seg != bss_section)
+  if ((bfd_section_flags (now_seg) & SEC_CODE) != 0)
     maybe_text = 1;
   else
     maybe_text = 0;
-#endif
   if (!maybe_text)
     as_warn (_(".ent or .aent not in text section."));
   if (!aent && s7_cur_proc_ptr)
@@ -5642,7 +5629,6 @@ s7_s_score_end (int x ATTRIBUTE_UNUSED)
   /* Generate a .pdr section.  */
   segT saved_seg = now_seg;
   subsegT saved_subseg = now_subseg;
-  valueT dot;
   expressionS exp;
   char *fragp;
 
@@ -5654,17 +5640,10 @@ s7_s_score_end (int x ATTRIBUTE_UNUSED)
   else
     p = NULL;
 
-#ifdef BFD_ASSEMBLER
-  if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
+  if ((bfd_section_flags (now_seg) & SEC_CODE) != 0)
     maybe_text = 1;
   else
     maybe_text = 0;
-#else
-  if (now_seg != data_section && now_seg != bss_section)
-    maybe_text = 1;
-  else
-    maybe_text = 0;
-#endif
 
   if (!maybe_text)
     as_warn (_(".end not in text section"));
@@ -5693,7 +5672,7 @@ s7_s_score_end (int x ATTRIBUTE_UNUSED)
 
   else
     {
-      dot = frag_now_fix ();
+      (void) frag_now_fix ();
       gas_assert (s7_pdr_seg);
       subseg_set (s7_pdr_seg, 0);
       /* Write the symbol.  */
@@ -5955,8 +5934,7 @@ s7_s_score_lcomm (int bytes_p)
   segT bss_seg = bss_section;
   int needs_align = 0;
 
-  name = input_line_pointer;
-  c = get_symbol_end ();
+  c = get_symbol_name (&name);
   p = input_line_pointer;
   *p = c;
 
@@ -5967,7 +5945,7 @@ s7_s_score_lcomm (int bytes_p)
       return;
     }
 
-  SKIP_WHITESPACE ();
+  SKIP_WHITESPACE_AFTER_NAME ();
 
   /* Accept an optional comma after the name.  The comma used to be
      required, but Irix 5 cc does not generate it.  */
@@ -5995,14 +5973,13 @@ s7_s_score_lcomm (int bytes_p)
     {
       /* For Score and Alpha ECOFF or ELF, small objects are put in .sbss.  */
       if ((unsigned) temp <= bfd_get_gp_size (stdoutput))
-        {
-          bss_seg = subseg_new (".sbss", 1);
-          seg_info (bss_seg)->bss = 1;
-#ifdef BFD_ASSEMBLER
-          if (!bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
-            as_warn (_("error setting flags for \".sbss\": %s"), bfd_errmsg (bfd_get_error ()));
-#endif
-        }
+       {
+         bss_seg = subseg_new (".sbss", 1);
+         seg_info (bss_seg)->bss = 1;
+         if (!bfd_set_section_flags (bss_seg, SEC_ALLOC | SEC_SMALL_DATA))
+           as_warn (_("error setting flags for \".sbss\": %s"),
+                    bfd_errmsg (bfd_get_error ()));
+       }
     }
 #endif
 
@@ -6079,14 +6056,9 @@ s7_s_score_lcomm (int bytes_p)
   *p = c;
 
   if (
-#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT) \
-     || defined (OBJ_BOUT) || defined (OBJ_MAYBE_BOUT))
-#ifdef BFD_ASSEMBLER
+#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
        (OUTPUT_FLAVOR != bfd_target_aout_flavour
         || (S_GET_OTHER (symbolP) == 0 && S_GET_DESC (symbolP) == 0)) &&
-#else
-       (S_GET_OTHER (symbolP) == 0 && S_GET_DESC (symbolP) == 0) &&
-#endif
 #endif
        (S_GET_SEGMENT (symbolP) == bss_seg || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
     {
@@ -6139,13 +6111,11 @@ s7_begin (void)
   segT seg;
   subsegT subseg;
 
-  if ((s7_score_ops_hsh = hash_new ()) == NULL)
-    as_fatal (_("virtual memory exhausted"));
+  s7_score_ops_hsh = str_htab_create ();
 
   s7_build_score_ops_hsh ();
 
-  if ((s7_dependency_insn_hsh = hash_new ()) == NULL)
-    as_fatal (_("virtual memory exhausted"));
+  s7_dependency_insn_hsh = str_htab_create ();
 
   s7_build_dependency_insn_hsh ();
 
@@ -6159,8 +6129,8 @@ s7_begin (void)
   seg = now_seg;
   subseg = now_subseg;
   s7_pdr_seg = subseg_new (".pdr", (subsegT) 0);
-  (void) bfd_set_section_flags (stdoutput, s7_pdr_seg, SEC_READONLY | SEC_RELOC | SEC_DEBUGGING);
-  (void) bfd_set_section_alignment (stdoutput, s7_pdr_seg, 2);
+  bfd_set_section_flags (s7_pdr_seg, SEC_READONLY | SEC_RELOC | SEC_DEBUGGING);
+  bfd_set_section_alignment (s7_pdr_seg, 2);
   subseg_set (seg, subseg);
 
   if (s7_USE_GLOBAL_POINTER_OPT)
@@ -6187,11 +6157,11 @@ s7_assemble (char *str)
    instruction in the error message.  */
 
 static void
-s7_operand (expressionS * expr)
+s7_operand (expressionS * exp)
 {
   if (s7_in_my_get_expression)
     {
-      expr->X_op = O_illegal;
+      exp->X_op = O_illegal;
       if (s7_inst.error == NULL)
         {
           s7_inst.error = _("bad expression");
@@ -6211,11 +6181,11 @@ s7_operand (expressionS * expr)
    the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
    the byte sequence 99 99 f1 3f 9a 99 99 99.  */
 
-static char *
+static const char *
 s7_atof (int type, char *litP, int *sizeP)
 {
   int prec;
-  LITTLENUM_TYPE words[s7_MAX_LITTLENUMS];
+  LITTLENUM_TYPE words[MAX_LITTLENUMS];
   char *t;
   int i;
 
@@ -6274,7 +6244,7 @@ s7_atof (int type, char *litP, int *sizeP)
    Called after md_convert_frag().  */
 
 static void
-s7_frag_check (fragS * fragp)
+s7_frag_check (fragS * fragp ATTRIBUTE_UNUSED)
 {
   know (fragp->insn_addr <= s7_RELAX_PAD_BYTE);
 }
@@ -6370,7 +6340,6 @@ s7_relax_frag (asection * sec ATTRIBUTE_UNUSED,
 {
   int grows = 0;
   int insn_size;
-  int insn_relax_size;
   int do_relax_p = 0;           /* Indicate doing relaxation for this frag.  */
   int relaxable_p = 0;
   bfd_boolean word_align_p = FALSE;
@@ -6390,15 +6359,9 @@ s7_relax_frag (asection * sec ATTRIBUTE_UNUSED,
 
   /* Get instruction size and relax size after the last relaxation.  */
   if (fragp->fr_opcode)
-    {
-      insn_size = s7_RELAX_NEW (fragp->fr_subtype);
-      insn_relax_size = s7_RELAX_OLD (fragp->fr_subtype);
-    }
+    insn_size = s7_RELAX_NEW (fragp->fr_subtype);
   else
-    {
-      insn_size = s7_RELAX_OLD (fragp->fr_subtype);
-      insn_relax_size = s7_RELAX_NEW (fragp->fr_subtype);
-    }
+    insn_size = s7_RELAX_OLD (fragp->fr_subtype);
 
   /* Handle specially for s7_GP instruction.  for, s7_judge_size_before_relax() has already determine
      whether the s7_GP instruction should do relax.  */
@@ -6489,7 +6452,7 @@ s7_relax_frag (asection * sec ATTRIBUTE_UNUSED,
                       grows -= 2;
                       do_relax_p = 1;
                     }
-                  /* Make the 32 bit insturction word align.  */
+                  /* Make the 32 bit instruction word align.  */
                   else
                     {
                       fragp->insn_addr += 2;
@@ -6509,7 +6472,7 @@ s7_relax_frag (asection * sec ATTRIBUTE_UNUSED,
       else
         {
          /* Here, try best to do relax regardless fragp->fr_next->fr_type.  */
-          if (word_align_p == FALSE)
+          if (!word_align_p)
             {
               if (insn_size % 4 == 0)
                 {
@@ -6575,28 +6538,28 @@ s7_convert_frag (bfd * abfd ATTRIBUTE_UNUSED,
                 segT sec ATTRIBUTE_UNUSED,
                 fragS * fragp)
 {
-  int old;
-  int new;
+  unsigned int r_old;
+  unsigned int r_new;
   char backup[20];
   fixS *fixp;
 
-  old = s7_RELAX_OLD (fragp->fr_subtype);
-  new = s7_RELAX_NEW (fragp->fr_subtype);
+  r_old = s7_RELAX_OLD (fragp->fr_subtype);
+  r_new = s7_RELAX_NEW (fragp->fr_subtype);
 
   /* fragp->fr_opcode indicates whether this frag should be relaxed.  */
   if (fragp->fr_opcode == NULL)
     {
-      memcpy (backup, fragp->fr_literal, old);
-      fragp->fr_fix = old;
+      memcpy (backup, fragp->fr_literal, r_old);
+      fragp->fr_fix = r_old;
     }
   else
     {
-      memcpy (backup, fragp->fr_literal + old, new);
-      fragp->fr_fix = new;
+      memcpy (backup, fragp->fr_literal + r_old, r_new);
+      fragp->fr_fix = r_new;
     }
 
   fixp = fragp->tc_frag_data.fixp;
-  while (fixp && fixp->fx_frag == fragp && fixp->fx_where < old)
+  while (fixp && fixp->fx_frag == fragp && fixp->fx_where < r_old)
     {
       if (fragp->fr_opcode)
        fixp->fx_done = 1;
@@ -6605,7 +6568,7 @@ s7_convert_frag (bfd * abfd ATTRIBUTE_UNUSED,
   while (fixp && fixp->fx_frag == fragp)
     {
       if (fragp->fr_opcode)
-       fixp->fx_where -= old + fragp->insn_addr;
+       fixp->fx_where -= r_old + fragp->insn_addr;
       else
        fixp->fx_done = 1;
       fixp = fixp->fx_next;
@@ -6642,19 +6605,19 @@ s7_pcrel_from (fixS * fixP)
 static valueT
 s7_section_align (segT segment, valueT size)
 {
-  int align = bfd_get_section_alignment (stdoutput, segment);
+  int align = bfd_section_alignment (segment);
 
-  return ((size + (1 << align) - 1) & (-1 << align));
+  return ((size + (1 << align) - 1) & -(1 << align));
 }
 
 static void
 s7_apply_fix (fixS *fixP, valueT *valP, segT seg)
 {
-  offsetT value = *valP;
-  offsetT abs_value = 0;
-  offsetT newval;
-  offsetT content;
-  unsigned short HI, LO;
+  valueT value = *valP;
+  valueT abs_value = 0;
+  valueT newval;
+  valueT content;
+  valueT HI, LO;
 
   char *buf = fixP->fx_frag->fr_literal + fixP->fx_where;
 
@@ -6685,7 +6648,7 @@ s7_apply_fix (fixS *fixP, valueT *valP, segT seg)
       if (fixP->fx_done)
         {                       /* For la rd, imm32.  */
           newval = s7_md_chars_to_number (buf, s7_INSN_SIZE);
-          HI = (value) >> 16;   /* mul to 2, then take the hi 16 bit.  */
+          HI = value >> 16;   /* mul to 2, then take the hi 16 bit.  */
           newval |= (HI & 0x3fff) << 1;
           newval |= ((HI >> 14) & 0x3) << 16;
           s7_number_to_chars (buf, newval, s7_INSN_SIZE);
@@ -6695,7 +6658,7 @@ s7_apply_fix (fixS *fixP, valueT *valP, segT seg)
       if (fixP->fx_done)        /* For la rd, imm32.  */
         {
           newval = s7_md_chars_to_number (buf, s7_INSN_SIZE);
-          LO = (value) & 0xffff;
+          LO = value & 0xffff;
           newval |= (LO & 0x3fff) << 1; /* 16 bit: imm -> 14 bit in lo, 2 bit in hi.  */
           newval |= ((LO >> 14) & 0x3) << 16;
           s7_number_to_chars (buf, newval, s7_INSN_SIZE);
@@ -6705,7 +6668,7 @@ s7_apply_fix (fixS *fixP, valueT *valP, segT seg)
       {
         content = s7_md_chars_to_number (buf, s7_INSN_SIZE);
         value = fixP->fx_offset;
-        if (!(value >= 0 && value <= 0x1ffffff))
+        if (value > 0x1ffffff)
           {
             as_bad_where (fixP->fx_file, fixP->fx_line,
                           _("j or jl truncate (0x%x)  [0 ~ 2^25-1]"), (unsigned int) value);
@@ -6760,7 +6723,7 @@ s7_apply_fix (fixS *fixP, valueT *valP, segT seg)
       content = s7_md_chars_to_number (buf, s7_INSN16_SIZE);
       content &= 0xf001;
       value = fixP->fx_offset;
-      if (!(value >= 0 && value <= 0xfff))
+      if (value > 0xfff)
         {
           as_bad_where (fixP->fx_file, fixP->fx_line,
                         _("j! or jl! truncate (0x%x)  [0 ~ 2^12-1]"), (unsigned int) value);
@@ -6796,7 +6759,7 @@ s7_apply_fix (fixS *fixP, valueT *valP, segT seg)
         }
       else
         {
-          /* In differnt section.  */
+          /* In different section.  */
           if ((S_GET_SEGMENT (fixP->fx_addsy) != seg) ||
               (fixP->fx_addsy != NULL && S_IS_EXTERNAL (fixP->fx_addsy)))
             value = fixP->fx_offset;
@@ -6884,15 +6847,12 @@ s7_gen_reloc (asection * section ATTRIBUTE_UNUSED, fixS * fixp)
   static arelent *retval[MAX_RELOC_EXPANSION + 1];  /* MAX_RELOC_EXPANSION equals 2.  */
   arelent *reloc;
   bfd_reloc_code_real_type code;
-  char *type;
-  fragS *f;
-  symbolS *s;
-  expressionS e;
+  const char *type;
 
-  reloc = retval[0] = xmalloc (sizeof (arelent));
+  reloc = retval[0] = XNEW (arelent);
   retval[1] = NULL;
 
-  reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
+  reloc->sym_ptr_ptr = XNEW (asymbol *);
   *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
   reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
   reloc->addend = fixp->fx_offset;
@@ -6920,16 +6880,12 @@ s7_gen_reloc (asection * section ATTRIBUTE_UNUSED, fixS * fixp)
       newval |= (((off >> 14) & 0x3) << 16);
       s7_number_to_chars (buf, newval, s7_INSN_SIZE);
 
-      retval[1] = xmalloc (sizeof (arelent));
+      retval[1] = XNEW (arelent);
       retval[2] = NULL;
-      retval[1]->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
+      retval[1]->sym_ptr_ptr = XNEW (asymbol *);
       *retval[1]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
       retval[1]->address = (reloc->address + s7_RELAX_RELOC2 (fixp->fx_frag->fr_subtype));
 
-      f = fixp->fx_frag;
-      s = f->fr_symbol;
-      e = s->sy_value;
-
       retval[1]->addend = 0;
       retval[1]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16);
       gas_assert (retval[1]->howto != NULL);
@@ -6946,6 +6902,7 @@ s7_gen_reloc (asection * section ATTRIBUTE_UNUSED, fixS * fixp)
           code = BFD_RELOC_32_PCREL;
           break;
         }
+      /* Fall through.  */
     case BFD_RELOC_HI16_S:
     case BFD_RELOC_LO16:
     case BFD_RELOC_SCORE_JMP: