]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gas/config/tc-tilegx.c
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / gas / config / tc-tilegx.c
index 49bf093e9032a2bd4aeb2ae74f0168111c005504..b6413a2c4ba16ec104d0dbddefcaa82bdd3bd83c 100644 (file)
@@ -1,5 +1,5 @@
 /* tc-tilegx.c -- Assemble for a Tile-Gx chip.
-   Copyright 2011 Free Software Foundation, Inc.
+   Copyright (C) 2011-2021 Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
 
@@ -19,7 +19,6 @@
    MA 02110-1301, USA.  */
 
 #include "as.h"
-#include "struc-symbol.h"
 #include "subsegs.h"
 
 #include "elf/tilegx.h"
@@ -99,7 +98,7 @@ struct option md_longopts[] =
 size_t md_longopts_size = sizeof (md_longopts);
 
 int
-md_parse_option (int c, char *arg ATTRIBUTE_UNUSED)
+md_parse_option (int c, const char *arg ATTRIBUTE_UNUSED)
 {
   switch (c)
     {
@@ -157,35 +156,34 @@ md_show_usage (FILE *stream)
 #define O_hw1_last             O_md6
 #define O_hw2_last             O_md7
 #define O_hw0_got              O_md8
-#define O_hw1_got              O_md9
-#define O_hw2_got              O_md10
-#define O_hw3_got              O_md11
-#define O_hw0_last_got         O_md12
-#define O_hw1_last_got         O_md13
-#define O_hw2_last_got         O_md14
-#define O_plt                  O_md15
-#define O_hw0_tls_gd           O_md16
-#define O_hw1_tls_gd           O_md17
-#define O_hw2_tls_gd           O_md18
-#define O_hw3_tls_gd           O_md19
-#define O_hw0_last_tls_gd      O_md20
-#define O_hw1_last_tls_gd      O_md21
-#define O_hw2_last_tls_gd      O_md22
-#define O_hw0_tls_ie           O_md23
-#define O_hw1_tls_ie           O_md24
-#define O_hw2_tls_ie           O_md25
-#define O_hw3_tls_ie           O_md26
-#define O_hw0_last_tls_ie      O_md27
-#define O_hw1_last_tls_ie      O_md28
-#define O_hw2_last_tls_ie      O_md29
-
-static struct hash_control *special_operator_hash;
+#define O_hw0_last_got         O_md9
+#define O_hw1_last_got         O_md10
+#define O_plt                  O_md11
+#define O_hw0_tls_gd           O_md12
+#define O_hw0_last_tls_gd      O_md13
+#define O_hw1_last_tls_gd      O_md14
+#define O_hw0_tls_ie           O_md15
+#define O_hw0_last_tls_ie      O_md16
+#define O_hw1_last_tls_ie      O_md17
+#define O_hw0_tls_le           O_md18
+#define O_hw0_last_tls_le      O_md19
+#define O_hw1_last_tls_le      O_md20
+#define O_tls_gd_call          O_md21
+#define O_tls_gd_add           O_md22
+#define O_tls_ie_load          O_md23
+#define O_tls_add              O_md24
+#define O_hw0_plt              O_md25
+#define O_hw1_plt              O_md26
+#define O_hw1_last_plt         O_md27
+#define O_hw2_last_plt         O_md28
+
+static htab_t special_operator_hash;
 
 /* Hash tables for instruction mnemonic lookup.  */
-static struct hash_control *op_hash;
+static htab_t op_hash;
 
 /* Hash table for spr lookup.  */
-static struct hash_control *spr_hash;
+static htab_t spr_hash;
 
 /* True temporarily while parsing an SPR expression. This changes the
  * namespace to include SPR names.  */
@@ -233,7 +231,7 @@ static int allow_suspicious_bundles;
    for that register (e.g. r63 instead of zero), so we should generate
    a warning. The attempted register number can be found by clearing
    NONCANONICAL_REG_NAME_FLAG.  */
-static struct hash_control *main_reg_hash;
+static htab_t main_reg_hash;
 
 
 /* We cannot unambiguously store a 0 in a hash table and look it up,
@@ -264,7 +262,7 @@ md_begin (void)
     as_warn (_("Could not set architecture and machine"));
 
   /* Guarantee text section is aligned.  */
-  bfd_set_section_alignment (stdoutput, text_section,
+  bfd_set_section_alignment (text_section,
                              TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES);
 
   require_canonical_reg_names = 1;
@@ -275,9 +273,9 @@ md_begin (void)
   tilegx_cie_data_alignment = (tilegx_arch_size == 64 ? -8 : -4);
 
   /* Initialize special operator hash table.  */
-  special_operator_hash = hash_new ();
+  special_operator_hash = str_htab_create ();
 #define INSERT_SPECIAL_OP(name)                                        \
-  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);
@@ -287,63 +285,58 @@ md_begin (void)
   INSERT_SPECIAL_OP (hw1_last);
   INSERT_SPECIAL_OP (hw2_last);
   /* hw3_last is a convenience alias for the equivalent hw3.  */
-  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 (hw1_got);
-  INSERT_SPECIAL_OP (hw2_got);
-  INSERT_SPECIAL_OP (hw3_got);
   INSERT_SPECIAL_OP (hw0_last_got);
   INSERT_SPECIAL_OP (hw1_last_got);
-  INSERT_SPECIAL_OP (hw2_last_got);
   INSERT_SPECIAL_OP(plt);
   INSERT_SPECIAL_OP (hw0_tls_gd);
-  INSERT_SPECIAL_OP (hw1_tls_gd);
-  INSERT_SPECIAL_OP (hw2_tls_gd);
-  INSERT_SPECIAL_OP (hw3_tls_gd);
   INSERT_SPECIAL_OP (hw0_last_tls_gd);
   INSERT_SPECIAL_OP (hw1_last_tls_gd);
-  INSERT_SPECIAL_OP (hw2_last_tls_gd);
   INSERT_SPECIAL_OP (hw0_tls_ie);
-  INSERT_SPECIAL_OP (hw1_tls_ie);
-  INSERT_SPECIAL_OP (hw2_tls_ie);
-  INSERT_SPECIAL_OP (hw3_tls_ie);
   INSERT_SPECIAL_OP (hw0_last_tls_ie);
   INSERT_SPECIAL_OP (hw1_last_tls_ie);
-  INSERT_SPECIAL_OP (hw2_last_tls_ie);
+  INSERT_SPECIAL_OP (hw0_tls_le);
+  INSERT_SPECIAL_OP (hw0_last_tls_le);
+  INSERT_SPECIAL_OP (hw1_last_tls_le);
+  INSERT_SPECIAL_OP (tls_gd_call);
+  INSERT_SPECIAL_OP (tls_gd_add);
+  INSERT_SPECIAL_OP (tls_ie_load);
+  INSERT_SPECIAL_OP (tls_add);
+  INSERT_SPECIAL_OP (hw0_plt);
+  INSERT_SPECIAL_OP (hw1_plt);
+  INSERT_SPECIAL_OP (hw1_last_plt);
+  INSERT_SPECIAL_OP (hw2_last_plt);
 #undef INSERT_SPECIAL_OP
 
   /* Initialize op_hash hash table.  */
-  op_hash = hash_new ();
+  op_hash = str_htab_create ();
   for (op = &tilegx_opcodes[0]; op->name != NULL; op++)
-    {
-      const char *hash_err = hash_insert (op_hash, op->name, (void *)op);
-      if (hash_err != NULL)
-       as_fatal (_("Internal Error:  Can't hash %s: %s"), op->name, hash_err);
-    }
+    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 = hash_new ();
+  spr_hash = str_htab_create ();
   for (i = 0; i < tilegx_num_sprs; i++)
-    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
      with labels that have the same names as registers.  */
-  main_reg_hash = hash_new ();
+  main_reg_hash = str_htab_create ();
   for (i = 0; i < TILEGX_NUM_REGISTERS; i++)
     {
       char buf[64];
 
-      hash_insert (main_reg_hash, tilegx_register_names[i],
-                  (void *) (long) (i | CANONICAL_REG_NAME_FLAG));
+      str_hash_insert (main_reg_hash, tilegx_register_names[i],
+                      (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)
-       hash_insert (main_reg_hash, xstrdup (buf),
-                    (void *) (long) (i | NONCANONICAL_REG_NAME_FLAG));
+       str_hash_insert (main_reg_hash, xstrdup (buf),
+                        (void *) (long) (i | NONCANONICAL_REG_NAME_FLAG), 0);
     }
 }
 
@@ -398,7 +391,7 @@ static tilegx_bundle_bits
 insert_operand (tilegx_bundle_bits bits,
                 const struct tilegx_operand *operand,
                 int operand_value,
-                char *file,
+                const char *file,
                 unsigned lineno)
 {
   /* Range-check the immediate.  */
@@ -436,7 +429,8 @@ insert_operand (tilegx_bundle_bits bits,
 
 
 static int
-apply_special_operator (operatorT op, offsetT num, char *file, unsigned lineno)
+apply_special_operator (operatorT op, offsetT num, const char *file,
+                       unsigned lineno)
 {
   int ret;
   int check_shift = -1;
@@ -566,113 +560,158 @@ emit_tilegx_instruction (tilegx_bundle_bits bits,
              require_symbol = 1;
              break;
 
-           case O_hw1_got:
-             HANDLE_OP16 (HW1_GOT);
+           case O_hw0_last_got:
+             HANDLE_OP16 (HW0_LAST_GOT);
              require_symbol = 1;
              break;
 
-           case O_hw2_got:
-             HANDLE_OP16 (HW2_GOT);
+           case O_hw1_last_got:
+             HANDLE_OP16 (HW1_LAST_GOT);
              require_symbol = 1;
              break;
 
-           case O_hw3_got:
-             HANDLE_OP16 (HW3_GOT);
+           case O_hw0_tls_gd:
+             HANDLE_OP16 (HW0_TLS_GD);
              require_symbol = 1;
              break;
 
-           case O_hw0_last_got:
-             HANDLE_OP16 (HW0_LAST_GOT);
+           case O_hw0_last_tls_gd:
+             HANDLE_OP16 (HW0_LAST_TLS_GD);
              require_symbol = 1;
              break;
 
-           case O_hw1_last_got:
-             HANDLE_OP16 (HW1_LAST_GOT);
+           case O_hw1_last_tls_gd:
+             HANDLE_OP16 (HW1_LAST_TLS_GD);
              require_symbol = 1;
              break;
 
-           case O_hw2_last_got:
-             HANDLE_OP16 (HW2_LAST_GOT);
+           case O_hw0_tls_ie:
+             HANDLE_OP16 (HW0_TLS_IE);
              require_symbol = 1;
              break;
 
-           case O_hw0_tls_gd:
-             HANDLE_OP16 (HW0_TLS_GD);
+           case O_hw0_last_tls_ie:
+             HANDLE_OP16 (HW0_LAST_TLS_IE);
              require_symbol = 1;
              break;
 
-           case O_hw1_tls_gd:
-             HANDLE_OP16 (HW1_TLS_GD);
+           case O_hw1_last_tls_ie:
+             HANDLE_OP16 (HW1_LAST_TLS_IE);
              require_symbol = 1;
              break;
 
-           case O_hw2_tls_gd:
-             HANDLE_OP16 (HW2_TLS_GD);
+           case O_hw0_tls_le:
+             HANDLE_OP16 (HW0_TLS_LE);
              require_symbol = 1;
              break;
 
-           case O_hw3_tls_gd:
-             HANDLE_OP16 (HW3_TLS_GD);
+           case O_hw0_last_tls_le:
+             HANDLE_OP16 (HW0_LAST_TLS_LE);
              require_symbol = 1;
              break;
 
-           case O_hw0_last_tls_gd:
-             HANDLE_OP16 (HW0_LAST_TLS_GD);
+           case O_hw1_last_tls_le:
+             HANDLE_OP16 (HW1_LAST_TLS_LE);
              require_symbol = 1;
              break;
 
-           case O_hw1_last_tls_gd:
-             HANDLE_OP16 (HW1_LAST_TLS_GD);
-             require_symbol = 1;
+           case O_hw0_plt:
+             HANDLE_OP16 (HW0_PLT_PCREL);
              break;
 
-           case O_hw2_last_tls_gd:
-             HANDLE_OP16 (HW2_LAST_TLS_GD);
-             require_symbol = 1;
+           case O_hw1_plt:
+             HANDLE_OP16 (HW1_PLT_PCREL);
              break;
 
-           case O_hw0_tls_ie:
-             HANDLE_OP16 (HW0_TLS_IE);
-             require_symbol = 1;
+           case O_hw1_last_plt:
+             HANDLE_OP16 (HW1_LAST_PLT_PCREL);
              break;
 
-           case O_hw1_tls_ie:
-             HANDLE_OP16 (HW1_TLS_IE);
-             require_symbol = 1;
+           case O_hw2_last_plt:
+             HANDLE_OP16 (HW2_LAST_PLT_PCREL);
              break;
 
-           case O_hw2_tls_ie:
-             HANDLE_OP16 (HW2_TLS_IE);
-             require_symbol = 1;
-             break;
+#undef HANDLE_OP16
 
-           case O_hw3_tls_ie:
-             HANDLE_OP16 (HW3_TLS_IE);
+           case O_plt:
+             switch (reloc)
+               {
+               case BFD_RELOC_TILEGX_JUMPOFF_X1:
+                 reloc = BFD_RELOC_TILEGX_JUMPOFF_X1_PLT;
+                 break;
+               default:
+                 die = 1;
+                 break;
+               }
+             use_subexp = 1;
              require_symbol = 1;
              break;
 
-           case O_hw0_last_tls_ie:
-             HANDLE_OP16 (HW0_LAST_TLS_IE);
+           case O_tls_gd_call:
+             switch (reloc)
+               {
+               case BFD_RELOC_TILEGX_JUMPOFF_X1:
+                 reloc = BFD_RELOC_TILEGX_TLS_GD_CALL;
+                 break;
+               default:
+                 die = 1;
+                 break;
+               }
+             use_subexp = 1;
              require_symbol = 1;
              break;
 
-           case O_hw1_last_tls_ie:
-             HANDLE_OP16 (HW1_LAST_TLS_IE);
+           case O_tls_gd_add:
+             switch (reloc)
+               {
+               case BFD_RELOC_TILEGX_IMM8_X0:
+                 reloc = BFD_RELOC_TILEGX_IMM8_X0_TLS_GD_ADD;
+                 break;
+               case BFD_RELOC_TILEGX_IMM8_X1:
+                 reloc = BFD_RELOC_TILEGX_IMM8_X1_TLS_GD_ADD;
+                 break;
+               case BFD_RELOC_TILEGX_IMM8_Y0:
+                 reloc = BFD_RELOC_TILEGX_IMM8_Y0_TLS_GD_ADD;
+                 break;
+               case BFD_RELOC_TILEGX_IMM8_Y1:
+                 reloc = BFD_RELOC_TILEGX_IMM8_Y1_TLS_GD_ADD;
+                 break;
+               default:
+                 die = 1;
+                 break;
+               }
+             use_subexp = 1;
              require_symbol = 1;
              break;
 
-           case O_hw2_last_tls_ie:
-             HANDLE_OP16 (HW2_LAST_TLS_IE);
+           case O_tls_ie_load:
+             switch (reloc)
+               {
+               case BFD_RELOC_TILEGX_IMM8_X1:
+                 reloc = BFD_RELOC_TILEGX_TLS_IE_LOAD;
+                 break;
+               default:
+                 die = 1;
+                 break;
+               }
+             use_subexp = 1;
              require_symbol = 1;
              break;
 
-#undef HANDLE_OP16
-
-           case O_plt:
+           case O_tls_add:
              switch (reloc)
                {
-               case BFD_RELOC_TILEGX_JUMPOFF_X1:
-                 reloc = BFD_RELOC_TILEGX_JUMPOFF_X1_PLT;
+               case BFD_RELOC_TILEGX_IMM8_X0:
+                 reloc = BFD_RELOC_TILEGX_IMM8_X0_TLS_ADD;
+                 break;
+               case BFD_RELOC_TILEGX_IMM8_X1:
+                 reloc = BFD_RELOC_TILEGX_IMM8_X1_TLS_ADD;
+                 break;
+               case BFD_RELOC_TILEGX_IMM8_Y0:
+                 reloc = BFD_RELOC_TILEGX_IMM8_Y0_TLS_ADD;
+                 break;
+               case BFD_RELOC_TILEGX_IMM8_Y1:
+                 reloc = BFD_RELOC_TILEGX_IMM8_Y1_TLS_ADD;
                  break;
                default:
                  die = 1;
@@ -693,15 +732,18 @@ emit_tilegx_instruction (tilegx_bundle_bits bits,
            }
          else if (use_subexp)
            {
+             expressionS *sval = NULL;
              /* Now that we've changed the reloc, change ha16(x) into x,
                 etc.  */
 
-             if (operand_exp->X_add_symbol->sy_value.X_md)
+             if (symbol_symbolS (operand_exp->X_add_symbol))
+               sval = symbol_get_value_expression (operand_exp->X_add_symbol);
+             if (sval && sval->X_md)
                {
                  /* HACK: We used X_md to mark this symbol as a fake wrapper
                     around a real expression. To unwrap it, we just grab its
                     value here.  */
-                 operand_exp = &operand_exp->X_add_symbol->sy_value;
+                 operand_exp = sval;
 
                  if (require_symbol)
                    {
@@ -902,8 +944,8 @@ tilegx_flush_bundle (void)
 
   /* If the section seems to have no alignment set yet, go ahead and
      make it large enough to hold code.  */
-  if (bfd_get_section_alignment (stdoutput, now_seg) == 0)
-    bfd_set_section_alignment (stdoutput, now_seg,
+  if (bfd_section_alignment (now_seg) == 0)
+    bfd_set_section_alignment (now_seg,
                                TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES);
 
   for (j = 0; j < current_bundle_index; j++)
@@ -967,7 +1009,7 @@ tilegx_parse_name (char *name, expressionS *e, char *nextcharP)
 
   if (parsing_spr)
     {
-      void* val = hash_find (spr_hash, name);
+      void* val = str_hash_find (spr_hash, name);
       if (val == NULL)
        return 0;
 
@@ -985,7 +1027,7 @@ tilegx_parse_name (char *name, expressionS *e, char *nextcharP)
   else
     {
       /* Look up the operator in our table.  */
-      void* val = hash_find (special_operator_hash, name);
+      void* val = str_hash_find (special_operator_hash, name);
       if (val == 0)
        return 0;
       op = (operatorT)(long)val;
@@ -1022,7 +1064,7 @@ tilegx_parse_name (char *name, expressionS *e, char *nextcharP)
          /* HACK: mark this symbol as a temporary wrapper around a proper
             expression, so we can unwrap it later once we have communicated
             the relocation type.  */
-         sym->sy_value.X_md = 1;
+         symbol_get_value_expression (sym)->X_md = 1;
        }
 
       memset (e, 0, sizeof *e);
@@ -1041,33 +1083,32 @@ tilegx_parse_name (char *name, expressionS *e, char *nextcharP)
 static void
 parse_reg_expression (expressionS* expression)
 {
+  char *regname;
+  char terminating_char;
+  void *pval;
+  int regno_and_flags;
+  int regno;
+
   /* Zero everything to make sure we don't miss any flags.  */
   memset (expression, 0, sizeof *expression);
 
-  char* regname = input_line_pointer;
-  char terminating_char = get_symbol_end ();
-
-  void* pval = hash_find (main_reg_hash, regname);
+  terminating_char = get_symbol_name (&regname);
 
+  pval = str_hash_find (main_reg_hash, regname);
   if (pval == NULL)
-    {
-      as_bad (_("Expected register, got '%s'."), regname);
-    }
+    as_bad (_("Expected register, got '%s'."), regname);
 
-  int regno_and_flags = (int)(size_t)pval;
-  int regno = EXTRACT_REGNO(regno_and_flags);
+  regno_and_flags = (int)(size_t)pval;
+  regno = EXTRACT_REGNO(regno_and_flags);
 
   if ((regno_and_flags & NONCANONICAL_REG_NAME_FLAG)
       && require_canonical_reg_names)
-    {
-      as_warn (_("Found use of non-canonical register name %s; "
-                "use %s instead."),
-              regname,
-              tilegx_register_names[regno]);
-    }
+    as_warn (_("Found use of non-canonical register name %s; "
+              "use %s instead."),
+            regname, tilegx_register_names[regno]);
 
   /* Restore the old character following the register name.  */
-  *input_line_pointer = terminating_char;
+  (void) restore_line_pointer (terminating_char);
 
   /* Fill in the expression fields to indicate it's a register.  */
   expression->X_op = O_register;
@@ -1198,7 +1239,7 @@ md_assemble (char *str)
   old_char = str[opname_len];
   str[opname_len] = '\0';
 
-  op = hash_find(op_hash, str);
+  op = str_hash_find (op_hash, str);
   str[opname_len] = old_char;
   if (op == NULL)
     {
@@ -1269,9 +1310,6 @@ const pseudo_typeS md_pseudo_table[] =
   { NULL, 0, 0 }
 };
 
-/* Equal to MAX_PRECISION in atof-ieee.c  */
-#define MAX_LITTLENUMS 6
-
 void
 md_number_to_chars (char * buf, valueT val, int n)
 {
@@ -1286,7 +1324,7 @@ md_number_to_chars (char * buf, valueT val, int n)
    LITTLENUMS emitted is stored in *SIZEP.  An error message is
    returned, or NULL on OK.  */
 
-char *
+const char *
 md_atof (int type, char *litP, int *sizeP)
 {
   int prec;
@@ -1455,6 +1493,13 @@ md_apply_fix (fixS *fixP, valueT * valP, segT seg ATTRIBUTE_UNUSED)
        fixP->fx_r_type = rtype;                \
       break
 
+#define FIX_PLT_PCREL(rtype)                   \
+      case rtype##_PLT_PCREL:                  \
+       if (!fixP->fx_pcrel)                    \
+         fixP->fx_r_type = rtype;              \
+                                               \
+      break;
+
       FIX_PCREL (BFD_RELOC_8);
       FIX_PCREL (BFD_RELOC_16);
       FIX_PCREL (BFD_RELOC_32);
@@ -1473,6 +1518,14 @@ md_apply_fix (fixS *fixP, valueT * valP, segT seg ATTRIBUTE_UNUSED)
       FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST);
       FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST);
       FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST);
+      FIX_PLT_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW0);
+      FIX_PLT_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW0);
+      FIX_PLT_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW1);
+      FIX_PLT_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW1);
+      FIX_PLT_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST);
+      FIX_PLT_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST);
+      FIX_PLT_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST);
+      FIX_PLT_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST);
 
 #undef FIX_PCREL
 
@@ -1486,34 +1539,34 @@ md_apply_fix (fixS *fixP, valueT * valP, segT seg ATTRIBUTE_UNUSED)
 #ifdef OBJ_ELF
       switch (fixP->fx_r_type)
        {
+       case BFD_RELOC_TILEGX_IMM8_X0_TLS_ADD:
+       case BFD_RELOC_TILEGX_IMM8_X1_TLS_ADD:
+       case BFD_RELOC_TILEGX_IMM8_Y0_TLS_ADD:
+       case BFD_RELOC_TILEGX_IMM8_Y1_TLS_ADD:
+       case BFD_RELOC_TILEGX_IMM8_X0_TLS_GD_ADD:
+       case BFD_RELOC_TILEGX_IMM8_X1_TLS_GD_ADD:
+       case BFD_RELOC_TILEGX_IMM8_Y0_TLS_GD_ADD:
+       case BFD_RELOC_TILEGX_IMM8_Y1_TLS_GD_ADD:
        case BFD_RELOC_TILEGX_IMM16_X0_HW0_TLS_GD:
        case BFD_RELOC_TILEGX_IMM16_X1_HW0_TLS_GD:
-       case BFD_RELOC_TILEGX_IMM16_X0_HW0_TLS_IE:
-       case BFD_RELOC_TILEGX_IMM16_X1_HW0_TLS_IE:
        case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
        case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
-       case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
-       case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
-       case BFD_RELOC_TILEGX_IMM16_X0_HW1_TLS_GD:
-       case BFD_RELOC_TILEGX_IMM16_X1_HW1_TLS_GD:
-       case BFD_RELOC_TILEGX_IMM16_X0_HW1_TLS_IE:
-       case BFD_RELOC_TILEGX_IMM16_X1_HW1_TLS_IE:
        case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
        case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
+       case BFD_RELOC_TILEGX_IMM16_X0_HW0_TLS_IE:
+       case BFD_RELOC_TILEGX_IMM16_X1_HW0_TLS_IE:
+       case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
+       case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
        case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
        case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
-       case BFD_RELOC_TILEGX_IMM16_X0_HW2_TLS_GD:
-       case BFD_RELOC_TILEGX_IMM16_X1_HW2_TLS_GD:
-       case BFD_RELOC_TILEGX_IMM16_X0_HW2_TLS_IE:
-       case BFD_RELOC_TILEGX_IMM16_X1_HW2_TLS_IE:
-       case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_TLS_GD:
-       case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_TLS_GD:
-       case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_TLS_IE:
-       case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_TLS_IE:
-       case BFD_RELOC_TILEGX_IMM16_X0_HW3_TLS_GD:
-       case BFD_RELOC_TILEGX_IMM16_X1_HW3_TLS_GD:
-       case BFD_RELOC_TILEGX_IMM16_X0_HW3_TLS_IE:
-       case BFD_RELOC_TILEGX_IMM16_X1_HW3_TLS_IE:
+       case BFD_RELOC_TILEGX_IMM16_X0_HW0_TLS_LE:
+       case BFD_RELOC_TILEGX_IMM16_X1_HW0_TLS_LE:
+       case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_TLS_LE:
+       case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_TLS_LE:
+       case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_TLS_LE:
+       case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_TLS_LE:
+       case BFD_RELOC_TILEGX_TLS_GD_CALL:
+       case BFD_RELOC_TILEGX_TLS_IE_LOAD:
        case BFD_RELOC_TILEGX_TLS_DTPMOD64:
        case BFD_RELOC_TILEGX_TLS_DTPOFF64:
        case BFD_RELOC_TILEGX_TLS_TPOFF64:
@@ -1540,6 +1593,8 @@ md_apply_fix (fixS *fixP, valueT * valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_TILEGX_IMM16_X1_HW0:
     case BFD_RELOC_TILEGX_IMM16_X0_HW0_PCREL:
     case BFD_RELOC_TILEGX_IMM16_X1_HW0_PCREL:
+    case BFD_RELOC_TILEGX_IMM16_X0_HW0_PLT_PCREL:
+    case BFD_RELOC_TILEGX_IMM16_X1_HW0_PLT_PCREL:
       special = O_hw0;
       break;
 
@@ -1548,6 +1603,8 @@ md_apply_fix (fixS *fixP, valueT * valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST:
     case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_PCREL:
     case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_PCREL:
+    case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL:
+    case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL:
       special = O_hw0_last;
       break;
 
@@ -1556,6 +1613,8 @@ md_apply_fix (fixS *fixP, valueT * valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_TILEGX_IMM16_X1_HW1:
     case BFD_RELOC_TILEGX_IMM16_X0_HW1_PCREL:
     case BFD_RELOC_TILEGX_IMM16_X1_HW1_PCREL:
+    case BFD_RELOC_TILEGX_IMM16_X0_HW1_PLT_PCREL:
+    case BFD_RELOC_TILEGX_IMM16_X1_HW1_PLT_PCREL:
       special = O_hw1;
       break;
 
@@ -1564,6 +1623,8 @@ md_apply_fix (fixS *fixP, valueT * valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST:
     case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_PCREL:
     case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_PCREL:
+    case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL:
+    case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL:
       special = O_hw1_last;
       break;
 
@@ -1572,6 +1633,8 @@ md_apply_fix (fixS *fixP, valueT * valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_TILEGX_IMM16_X1_HW2:
     case BFD_RELOC_TILEGX_IMM16_X0_HW2_PCREL:
     case BFD_RELOC_TILEGX_IMM16_X1_HW2_PCREL:
+    case BFD_RELOC_TILEGX_IMM16_X0_HW2_PLT_PCREL:
+    case BFD_RELOC_TILEGX_IMM16_X1_HW2_PLT_PCREL:
       special = O_hw2;
       break;
 
@@ -1580,6 +1643,8 @@ md_apply_fix (fixS *fixP, valueT * valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST:
     case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_PCREL:
     case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_PCREL:
+    case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL:
+    case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL:
       special = O_hw2_last;
       break;
 
@@ -1588,6 +1653,8 @@ md_apply_fix (fixS *fixP, valueT * valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_TILEGX_IMM16_X1_HW3:
     case BFD_RELOC_TILEGX_IMM16_X0_HW3_PCREL:
     case BFD_RELOC_TILEGX_IMM16_X1_HW3_PCREL:
+    case BFD_RELOC_TILEGX_IMM16_X0_HW3_PLT_PCREL:
+    case BFD_RELOC_TILEGX_IMM16_X1_HW3_PLT_PCREL:
       special = O_hw3;
       break;
 
@@ -1662,8 +1729,8 @@ tc_gen_reloc (asection *sec ATTRIBUTE_UNUSED, fixS *fixp)
 {
   arelent *reloc;
 
-  reloc = (arelent *) xmalloc (sizeof (arelent));
-  reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
+  reloc = XNEW (arelent);
+  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;