]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gas/config/tc-tic6x.c
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / gas / config / tc-tic6x.c
index 81f33f40f134946f809bcec9206275057779f199..e2304c58139f5ac46331ca1d82b342ce6e1d71ec 100644 (file)
@@ -1,5 +1,5 @@
 /* TI C6X assembler.
-   Copyright 2010-2013 Free Software Foundation, Inc.
+   Copyright (C) 2010-2021 Free Software Foundation, Inc.
    Contributed by Joseph Myers <joseph@codesourcery.com>
                  Bernd Schmidt  <bernds@codesourcery.com>
 
@@ -201,7 +201,7 @@ static tic6x_unwind_info *tic6x_get_unwind (void)
   if (unwind)
     return unwind;
 
-  unwind = (tic6x_unwind_info *)xmalloc (sizeof (tic6x_unwind_info));
+  unwind =XNEW (tic6x_unwind_info);
   seg_info (now_seg)->tc_segment_info_data.unwind = unwind;
   memset (unwind, 0, sizeof (*unwind));
   return unwind;
@@ -265,7 +265,7 @@ tic6x_use_pid (const char *arg)
 /* Parse a target-specific option.  */
 
 int
-md_parse_option (int c, char *arg)
+md_parse_option (int c, const char *arg)
 {
   switch (c)
     {
@@ -471,17 +471,15 @@ s_tic6x_personalityindex (int ignored ATTRIBUTE_UNUSED)
 static void
 s_tic6x_personality (int ignored ATTRIBUTE_UNUSED)
 {
-  char *name, *p, c;
+  char *name, c;
   tic6x_unwind_info *unwind = tic6x_get_unwind ();
 
   if (unwind->personality_routine || unwind->personality_index != -1)
     as_bad (_("duplicate .personality directive"));
 
-  name = input_line_pointer;
-  c = get_symbol_end ();
-  p = input_line_pointer;
+  c = get_symbol_name (&name);
   unwind->personality_routine = symbol_find_or_make (name);
-  *p = c;
+  (void) restore_line_pointer (c);
   demand_empty_rest_of_line ();
 }
 
@@ -536,6 +534,7 @@ s_tic6x_ehtype (int ignored ATTRIBUTE_UNUSED)
     }
 
   p = frag_more (4);
+  memset (p, 0, 4);
   fix_new_exp (frag_now, p - frag_now->fr_literal, 4,
               &exp, 0, BFD_RELOC_C6000_EHTYPE);
 
@@ -569,12 +568,11 @@ s_tic6x_scomm (int ignore ATTRIBUTE_UNUSED)
   offsetT align;
   int align2;
 
-  name = input_line_pointer;
-  c = get_symbol_end ();
+  c = get_symbol_name (&name);
 
   /* Just after name is now '\0'.  */
   p = input_line_pointer;
-  *p = c;
+  (void) restore_line_pointer (c);
   SKIP_WHITESPACE ();
   if (*input_line_pointer != ',')
     {
@@ -744,7 +742,7 @@ const pseudo_typeS md_pseudo_table[] =
 /* Hash table of opcodes.  For each opcode name, this stores a pointer
    to a tic6x_opcode_list listing (in an arbitrary order) all opcode
    table entries with that name.  */
-static struct hash_control *opcode_hash;
+static htab_t opcode_hash;
 
 /* Initialize the assembler (called once at assembler startup).  */
 
@@ -759,17 +757,14 @@ md_begin (void)
   bfd_set_arch_mach (stdoutput, TARGET_ARCH, 0);
 
   /* Insert opcodes into the hash table.  */
-  opcode_hash = hash_new ();
+  opcode_hash = str_htab_create ();
   for (id = 0; id < tic6x_opcode_max; id++)
     {
-      const char *errmsg;
-      tic6x_opcode_list *opc = xmalloc (sizeof (tic6x_opcode_list));
+      tic6x_opcode_list *opc = XNEW (tic6x_opcode_list);
 
       opc->id = id;
-      opc->next = hash_find (opcode_hash, tic6x_opcode_table[id].name);
-      if ((errmsg = hash_jam (opcode_hash, tic6x_opcode_table[id].name, opc))
-         != NULL)
-       as_fatal ("%s", _(errmsg));
+      opc->next = str_hash_find (opcode_hash, tic6x_opcode_table[id].name);
+      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
@@ -783,7 +778,7 @@ md_begin (void)
 
   /* This is copied from perform_an_assembly_pass.  */
   applicable = bfd_applicable_section_flags (stdoutput);
-  bfd_set_section_flags (stdoutput, sbss_section, applicable & SEC_ALLOC);
+  bfd_set_section_flags (sbss_section, applicable & SEC_ALLOC);
 
   subseg_set (seg, subseg);
 
@@ -950,7 +945,7 @@ tic6x_frob_label (symbolS *sym)
 
   si = seg_info (now_seg);
   list = si->tc_segment_info_data.label_list;
-  si->tc_segment_info_data.label_list = xmalloc (sizeof (tic6x_label_list));
+  si->tc_segment_info_data.label_list = XNEW (tic6x_label_list);
   si->tc_segment_info_data.label_list->next = list;
   si->tc_segment_info_data.label_list->label = sym;
 
@@ -2012,10 +2007,9 @@ tic6x_fix_new_exp (fragS *frag, int where, int size, expressionS *exp,
    go through the error checking in tic6x_fix_new_exp.  */
 
 void
-tic6x_cons_fix_new (fragS *frag, int where, int size, expressionS *exp)
+tic6x_cons_fix_new (fragS *frag, int where, int size, expressionS *exp,
+                   bfd_reloc_code_real_type r_type)
 {
-  bfd_reloc_code_real_type r_type;
-
   switch (size)
     {
     case 1:
@@ -2068,7 +2062,7 @@ tic6x_fix_adjustable (fixS *fixP)
     case BFD_RELOC_C6000_PCR_H16:
     case BFD_RELOC_C6000_PCR_L16:
       return 0;
-      
+
     default:
       return 1;
     }
@@ -3190,7 +3184,7 @@ md_assemble (char *str)
   this_insn_label_list = seginfo->tc_segment_info_data.label_list;
   seginfo->tc_segment_info_data.label_list = NULL;
 
-  opc_list = hash_find_n (opcode_hash, str, p - str);
+  opc_list = str_hash_find_n (opcode_hash, str, p - str);
   if (opc_list == NULL)
     {
       char c = *p;
@@ -3256,7 +3250,7 @@ md_assemble (char *str)
   for (opc = opc_list; opc; opc = opc->next)
     max_matching_opcodes++;
   num_matching_opcodes = 0;
-  opcm = xmalloc (max_matching_opcodes * sizeof (*opcm));
+  opcm = XNEWVEC (tic6x_opcode_id, max_matching_opcodes);
   max_num_operands = 0;
   ok_this_arch = FALSE;
   ok_this_fu = FALSE;
@@ -3781,7 +3775,7 @@ md_assemble (char *str)
 void
 md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
 {
-  offsetT value = *valP;
+  valueT value = *valP;
   char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
 
   value = SEXT (value);
@@ -3811,7 +3805,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_16:
       if (fixP->fx_done || !seg->use_rela_p)
        {
-         if (value < -0x8000 || value > 0xffff)
+         if (value + 0x8000 > 0xffff + 0x8000)
            as_bad_where (fixP->fx_file, fixP->fx_line,
                          _("value too large for 2-byte field"));
          md_number_to_chars (buf, value, 2);
@@ -3821,10 +3815,10 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_8:
       if (fixP->fx_done || !seg->use_rela_p)
        {
-         if (value < -0x80 || value > 0xff)
+         if (value + 0x80 > 0xff + 0x80)
            as_bad_where (fixP->fx_file, fixP->fx_line,
                          _("value too large for 1-byte field"));
-         md_number_to_chars (buf, value, 1);
+         *buf = value;
        }
       break;
 
@@ -3837,7 +3831,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_C6000_SBR_GOT_L16_W:
       if (fixP->fx_done || !seg->use_rela_p)
        {
-         offsetT newval = md_chars_to_number (buf, 4);
+         valueT newval = md_chars_to_number (buf, 4);
          int shift;
 
          switch (fixP->fx_r_type)
@@ -3857,7 +3851,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
            }
 
          MODIFY_VALUE (newval, value, shift, 7, 16);
-         if ((value < -0x8000 || value > 0x7fff)
+         if ((value + 0x8000 > 0x7fff + 0x8000)
              && (fixP->fx_r_type == BFD_RELOC_C6000_ABS_S16
                  || fixP->fx_r_type == BFD_RELOC_C6000_SBR_S16))
            as_bad_where (fixP->fx_file, fixP->fx_line,
@@ -3878,7 +3872,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_C6000_SBR_GOT_H16_W:
       if (fixP->fx_done || !seg->use_rela_p)
        {
-         offsetT newval = md_chars_to_number (buf, 4);
+         valueT newval = md_chars_to_number (buf, 4);
          int shift;
 
          switch (fixP->fx_r_type)
@@ -3909,7 +3903,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_C6000_PCR_L16:
       if (fixP->fx_done || !seg->use_rela_p)
        {
-         offsetT newval = md_chars_to_number (buf, 4);
+         valueT newval = md_chars_to_number (buf, 4);
          int shift = fixP->fx_r_type == BFD_RELOC_C6000_PCR_H16 ? 16 : 0;
 
          MODIFY_VALUE (newval, value, shift, 7, 16);
@@ -3921,10 +3915,10 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_C6000_SBR_U15_B:
       if (fixP->fx_done || !seg->use_rela_p)
        {
-         offsetT newval = md_chars_to_number (buf, 4);
+         valueT newval = md_chars_to_number (buf, 4);
 
          MODIFY_VALUE (newval, value, 0, 8, 15);
-         if (value < 0 || value > 0x7fff)
+         if (value > 0x7fff)
            as_bad_where (fixP->fx_file, fixP->fx_line,
                          _("immediate offset out of range"));
 
@@ -3935,7 +3929,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_C6000_SBR_U15_H:
       if (fixP->fx_done || !seg->use_rela_p)
        {
-         offsetT newval = md_chars_to_number (buf, 4);
+         valueT newval = md_chars_to_number (buf, 4);
 
          /* Constant ADDA operands, processed as constant when the
             instruction is parsed, are encoded as-is rather than
@@ -3951,7 +3945,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
          if (value & 1)
            as_bad_where (fixP->fx_file, fixP->fx_line,
                          _("immediate offset not 2-byte-aligned"));
-         if (value < 0 || value > 0xfffe)
+         if (value > 0xfffe)
            as_bad_where (fixP->fx_file, fixP->fx_line,
                          _("immediate offset out of range"));
 
@@ -3963,7 +3957,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_C6000_SBR_GOT_U15_W:
       if (fixP->fx_done || !seg->use_rela_p)
        {
-         offsetT newval = md_chars_to_number (buf, 4);
+         valueT newval = md_chars_to_number (buf, 4);
 
          /* Constant ADDA operands, processed as constant when the
             instruction is parsed, are encoded as-is rather than
@@ -3979,7 +3973,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
          if (value & 3)
            as_bad_where (fixP->fx_file, fixP->fx_line,
                          _("immediate offset not 4-byte-aligned"));
-         if (value < 0 || value > 0x1fffc)
+         if (value > 0x1fffc)
            as_bad_where (fixP->fx_file, fixP->fx_line,
                          _("immediate offset out of range"));
 
@@ -4000,14 +3994,14 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_C6000_PCR_S21:
       if (fixP->fx_done || !seg->use_rela_p)
        {
-         offsetT newval = md_chars_to_number (buf, 4);
+         valueT newval = md_chars_to_number (buf, 4);
 
          MODIFY_VALUE (newval, value, 2, 7, 21);
 
          if (value & 3)
            as_bad_where (fixP->fx_file, fixP->fx_line,
                          _("PC-relative offset not 4-byte-aligned"));
-         if (value < -0x400000 || value > 0x3ffffc)
+         if (value + 0x400000 > 0x3ffffc + 0x400000)
            as_bad_where (fixP->fx_file, fixP->fx_line,
                          _("PC-relative offset out of range"));
 
@@ -4018,14 +4012,14 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_C6000_PCR_S12:
       if (fixP->fx_done || !seg->use_rela_p)
        {
-         offsetT newval = md_chars_to_number (buf, 4);
+         valueT newval = md_chars_to_number (buf, 4);
 
          MODIFY_VALUE (newval, value, 2, 16, 12);
 
          if (value & 3)
            as_bad_where (fixP->fx_file, fixP->fx_line,
                          _("PC-relative offset not 4-byte-aligned"));
-         if (value < -0x2000 || value > 0x1ffc)
+         if (value + 0x2000 > 0x1ffc + 0x2000)
            as_bad_where (fixP->fx_file, fixP->fx_line,
                          _("PC-relative offset out of range"));
 
@@ -4036,14 +4030,14 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_C6000_PCR_S10:
       if (fixP->fx_done || !seg->use_rela_p)
        {
-         offsetT newval = md_chars_to_number (buf, 4);
+         valueT newval = md_chars_to_number (buf, 4);
 
          MODIFY_VALUE (newval, value, 2, 13, 10);
 
          if (value & 3)
            as_bad_where (fixP->fx_file, fixP->fx_line,
                          _("PC-relative offset not 4-byte-aligned"));
-         if (value < -0x800 || value > 0x7fc)
+         if (value + 0x800 > 0x7fc + 0x800)
            as_bad_where (fixP->fx_file, fixP->fx_line,
                          _("PC-relative offset out of range"));
 
@@ -4054,14 +4048,14 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_C6000_PCR_S7:
       if (fixP->fx_done || !seg->use_rela_p)
        {
-         offsetT newval = md_chars_to_number (buf, 4);
+         valueT newval = md_chars_to_number (buf, 4);
 
          MODIFY_VALUE (newval, value, 2, 16, 7);
 
          if (value & 3)
            as_bad_where (fixP->fx_file, fixP->fx_line,
                          _("PC-relative offset not 4-byte-aligned"));
-         if (value < -0x100 || value > 0xfc)
+         if (value + 0x100 > 0xfc + 0x100)
            as_bad_where (fixP->fx_file, fixP->fx_line,
                          _("PC-relative offset out of range"));
 
@@ -4081,7 +4075,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
 
 /* Convert a floating-point number to target (IEEE) format.  */
 
-char *
+const char *
 md_atof (int type, char *litP, int *sizeP)
 {
   return ieee_md_atof (type, litP, sizeP, target_big_endian);
@@ -4486,8 +4480,8 @@ md_section_align (segT segment ATTRIBUTE_UNUSED,
 {
   /* Round up section sizes to ensure that text sections consist of
      whole fetch packets.  */
-  int align = bfd_get_section_alignment (stdoutput, segment);
-  return ((size + (1 << align) - 1) & ((valueT) -1 << align));
+  int align = bfd_section_alignment (segment);
+  return ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
 }
 
 /* No special undefined symbol handling needed for now.  */
@@ -4508,8 +4502,8 @@ tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
   asymbol *symbol;
   bfd_reloc_code_real_type r_type;
 
-  reloc = xmalloc (sizeof (arelent));
-  reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
+  reloc = XNEW (arelent);
+  reloc->sym_ptr_ptr = XNEW (asymbol *);
   symbol = symbol_get_bfdsym (fixp->fx_addsy);
   *reloc->sym_ptr_ptr = symbol;
   reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
@@ -4529,7 +4523,7 @@ tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
   if (reloc->howto->pcrel_offset && reloc->howto->partial_inplace)
     {
       reloc->addend += reloc->address;
-      if (!bfd_is_com_section (symbol))
+      if (!bfd_is_com_section (bfd_asymbol_section (symbol)))
        reloc->addend -= symbol->value;
     }
   if (r_type == BFD_RELOC_C6000_PCR_H16
@@ -4609,7 +4603,7 @@ tic6x_start_unwind_section (const segT text_seg, int idx)
   const char * text_name;
   const char * prefix;
   const char * prefix_once;
-  const char * group_name;
+  struct elf_section_match match;
   size_t prefix_len;
   size_t text_len;
   char * sec_name;
@@ -4645,20 +4639,20 @@ tic6x_start_unwind_section (const segT text_seg, int idx)
   prefix_len = strlen (prefix);
   text_len = strlen (text_name);
   sec_name_len = prefix_len + text_len;
-  sec_name = (char *) xmalloc (sec_name_len + 1);
+  sec_name = XNEWVEC (char, sec_name_len + 1);
   memcpy (sec_name, prefix, prefix_len);
   memcpy (sec_name + prefix_len, text_name, text_len);
   sec_name[prefix_len + text_len] = '\0';
 
   flags = SHF_ALLOC;
   linkonce = 0;
-  group_name = 0;
+  memset (&match, 0, sizeof (match));
 
   /* Handle COMDAT group.  */
   if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
     {
-      group_name = elf_group_name (text_seg);
-      if (group_name == NULL)
+      match.group_name = elf_group_name (text_seg);
+      if (match.group_name == NULL)
        {
          as_bad (_("group section `%s' has no group signature"),
                  segment_name (text_seg));
@@ -4669,7 +4663,8 @@ tic6x_start_unwind_section (const segT text_seg, int idx)
       linkonce = 1;
     }
 
-  obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
+  obj_elf_change_section (sec_name, type, flags, 0, &match,
+                         linkonce, 0);
 
   /* Set the section link for index tables.  */
   if (idx)
@@ -4680,18 +4675,18 @@ tic6x_start_unwind_section (const segT text_seg, int idx)
 
 
 static const int
-tic6x_unwind_frame_regs[TIC6X_NUM_UNWIND_REGS] = 
+tic6x_unwind_frame_regs[TIC6X_NUM_UNWIND_REGS] =
 /* A15 B15 B14 B13 B12 B11 B10  B3 A14 A13 A12 A11 A10.  */
   { 15, 31, 30, 29, 28, 27, 26, 19, 14, 13, 12, 11, 10 };
 
 /* Register save offsets for __c6xabi_push_rts.  */
 static const int
-tic6x_pop_rts_offset_little[TIC6X_NUM_UNWIND_REGS] = 
+tic6x_pop_rts_offset_little[TIC6X_NUM_UNWIND_REGS] =
 /* A15 B15 B14 B13 B12 B11 B10  B3 A14 A13 A12 A11 A10.  */
   { -1,  1,  0, -3, -4, -7, -8,-11, -2, -5, -6, -9,-10};
 
 static const int
-tic6x_pop_rts_offset_big[TIC6X_NUM_UNWIND_REGS] = 
+tic6x_pop_rts_offset_big[TIC6X_NUM_UNWIND_REGS] =
 /* A15 B15 B14 B13 B12 B11 B10  B3 A14 A13 A12 A11 A10.  */
   { -2,  1,  0, -4, -3, -8, -7,-12, -1, -6, -5,-10, -9};
 
@@ -4836,6 +4831,7 @@ tic6x_output_exidx_entry (void)
   record_alignment (now_seg, 2);
 
   ptr = frag_more (8);
+  memset (ptr, 0, 8);
   where = frag_now_fix () - 8;
 
   /* Self relative offset of the function start.  */
@@ -5061,7 +5057,7 @@ tic6x_output_unwinding (bfd_boolean need_extab)
       if (unwind->personality_index == -1)
        {
          tmp = md_chars_to_number (unwind->frag_start + 4, 4);
-         tmp |= ((unwind->data_bytes - 8) >> 2) << 24;
+         tmp |= (valueT) ((unwind->data_bytes - 8) >> 2) << 24;
          md_number_to_chars (unwind->frag_start + 4, tmp, 4);
        }
       else if (unwind->personality_index == 1 || unwind->personality_index == 2)
@@ -5339,7 +5335,7 @@ tic6x_cfi_endproc (struct fde_entry *fde)
            continue;
 
          unwind->saved_reg_count++;
-         /* Encoding uses 4 bits per word, so size of unwinding opcode data 
+         /* Encoding uses 4 bits per word, so size of unwinding opcode data
             limits the save area size.  The exact cap will be figured out
             later due to overflow, the 0x800 here is just a quick sanity
             check to weed out obviously excessive offsets.  */