xtensa: typedef enums when defining them
[deliverable/binutils-gdb.git] / gas / config / tc-cris.c
index 75c675c35d850d58649bb8fd228cb205a3b491df..74af4ce93fbc1555178cf56ce1887c4aa83d5fdd 100644 (file)
@@ -1,5 +1,5 @@
 /* tc-cris.c -- Assembler code for the CRIS CPU core.
 /* tc-cris.c -- Assembler code for the CRIS CPU core.
-   Copyright 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+   Copyright (C) 2000-2016 Free Software Foundation, Inc.
 
    Contributed by Axis Communications AB, Lund, Sweden.
    Originally written for GAS 1.38.1 by Mikael Asker.
 
    Contributed by Axis Communications AB, Lund, Sweden.
    Originally written for GAS 1.38.1 by Mikael Asker.
@@ -9,7 +9,7 @@
 
    GAS is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 
    GAS is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
+   the Free Software Foundation; either version 3, or (at your option)
    any later version.
 
    GAS is distributed in the hope that it will be useful,
    any later version.
 
    GAS is distributed in the hope that it will be useful,
@@ -22,7 +22,6 @@
    Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
    MA 02110-1301, USA.  */
 
    Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
    MA 02110-1301, USA.  */
 
-#include <stdio.h>
 #include "as.h"
 #include "safe-ctype.h"
 #include "subsegs.h"
 #include "as.h"
 #include "safe-ctype.h"
 #include "subsegs.h"
@@ -52,7 +51,7 @@
 
 /* Like in ":GOT", ":GOTOFF" etc.  Other ports use '@', but that's in
    line_separator_chars for CRIS, so we avoid it.  */
 
 /* Like in ":GOT", ":GOTOFF" etc.  Other ports use '@', but that's in
    line_separator_chars for CRIS, so we avoid it.  */
-#define PIC_SUFFIX_CHAR ':'
+#define RELOC_SUFFIX_CHAR ':'
 
 /* This might be CRIS_INSN_NONE if we're assembling a prefix-insn only.
    Note that some prefix-insns might be assembled as CRIS_INSN_NORMAL.  */
 
 /* This might be CRIS_INSN_NONE if we're assembling a prefix-insn only.
    Note that some prefix-insns might be assembled as CRIS_INSN_NORMAL.  */
@@ -120,7 +119,7 @@ enum cris_archs
   arch_cris_any_v0_v10, arch_crisv32, arch_cris_common_v10_v32
 };
 
   arch_cris_any_v0_v10, arch_crisv32, arch_cris_common_v10_v32
 };
 
-static enum cris_archs cris_arch_from_string (char **);
+static enum cris_archs cris_arch_from_string (const char **);
 static int cris_insn_ver_valid_for_arch (enum cris_insn_version_usage,
                                         enum cris_archs);
 
 static int cris_insn_ver_valid_for_arch (enum cris_insn_version_usage,
                                         enum cris_archs);
 
@@ -142,17 +141,16 @@ static int branch_disp (int);
 static void gen_cond_branch_32 (char *, char *, fragS *, symbolS *, symbolS *,
                                long int);
 static void cris_number_to_imm (char *, long, int, fixS *, segT);
 static void gen_cond_branch_32 (char *, char *, fragS *, symbolS *, symbolS *,
                                long int);
 static void cris_number_to_imm (char *, long, int, fixS *, segT);
-static void cris_create_short_jump (char *, addressT, addressT, fragS *,
-                                   symbolS *);
 static void s_syntax (int);
 static void s_cris_file (int);
 static void s_cris_loc (int);
 static void s_cris_arch (int);
 static void s_syntax (int);
 static void s_cris_file (int);
 static void s_cris_loc (int);
 static void s_cris_arch (int);
+static void s_cris_dtpoff (int);
 
 /* Get ":GOT", ":GOTOFF", ":PLT" etc. suffixes.  */
 
 /* Get ":GOT", ":GOTOFF", ":PLT" etc. suffixes.  */
-static void cris_get_pic_suffix (char **, bfd_reloc_code_real_type *,
-                                expressionS *);
-static unsigned int cris_get_pic_reloc_size (bfd_reloc_code_real_type);
+static void cris_get_reloc_suffix (char **, bfd_reloc_code_real_type *,
+                                  expressionS *);
+static unsigned int cris_get_specified_reloc_size (bfd_reloc_code_real_type);
 
 /* All the .syntax functions.  */
 static void cris_force_reg_prefix (void);
 
 /* All the .syntax functions.  */
 static void cris_force_reg_prefix (void);
@@ -183,6 +181,9 @@ static bfd_boolean symbols_have_leading_underscore
 /* Whether or not we allow PIC, and expand to PIC-friendly constructs.  */
 static bfd_boolean pic = FALSE;
 
 /* Whether or not we allow PIC, and expand to PIC-friendly constructs.  */
 static bfd_boolean pic = FALSE;
 
+/* Whether or not we allow TLS suffixes.  For the moment, we always do.  */
+static const bfd_boolean tls = TRUE;
+
 /* If we're configured for "cris", default to allow all v0..v10
    instructions and register names.  */
 #ifndef DEFAULT_CRIS_ARCH
 /* If we're configured for "cris", default to allow all v0..v10
    instructions and register names.  */
 #ifndef DEFAULT_CRIS_ARCH
@@ -195,6 +196,7 @@ static enum cris_archs cris_arch = XCONCAT2 (arch_,DEFAULT_CRIS_ARCH);
 const pseudo_typeS md_pseudo_table[] =
 {
   {"dword", cons, 4},
 const pseudo_typeS md_pseudo_table[] =
 {
   {"dword", cons, 4},
+  {"dtpoffd", s_cris_dtpoff, 4},
   {"syntax", s_syntax, 0},
   {"file", s_cris_file, 0},
   {"loc", s_cris_loc, 0},
   {"syntax", s_syntax, 0},
   {"file", s_cris_file, 0},
   {"loc", s_cris_loc, 0},
@@ -531,6 +533,7 @@ cris_relax_frag (segT seg ATTRIBUTE_UNUSED, fragS *fragP,
      because of the different reasons that they aren't relaxable.  */
   switch (fragP->fr_subtype)
     {
      because of the different reasons that they aren't relaxable.  */
   switch (fragP->fr_subtype)
     {
+    case ENCODE_RELAX (STATE_COND_BRANCH_PIC, STATE_DWORD):
     case ENCODE_RELAX (STATE_COND_BRANCH, STATE_DWORD):
     case ENCODE_RELAX (STATE_COND_BRANCH_V32, STATE_DWORD):
     case ENCODE_RELAX (STATE_COND_BRANCH_COMMON, STATE_DWORD):
     case ENCODE_RELAX (STATE_COND_BRANCH, STATE_DWORD):
     case ENCODE_RELAX (STATE_COND_BRANCH_V32, STATE_DWORD):
     case ENCODE_RELAX (STATE_COND_BRANCH_COMMON, STATE_DWORD):
@@ -811,7 +814,7 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT sec ATTRIBUTE_UNUSED,
 
   /* Used to check integrity of the relaxation.
      One of 2 = long, 1 = word, or 0 = byte.  */
 
   /* Used to check integrity of the relaxation.
      One of 2 = long, 1 = word, or 0 = byte.  */
-  int length_code;
+  int length_code ATTRIBUTE_UNUSED;
 
   /* Size in bytes of variable-sized part of frag.  */
   int var_part_size = 0;
 
   /* Size in bytes of variable-sized part of frag.  */
   int var_part_size = 0;
@@ -1017,14 +1020,10 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT sec ATTRIBUTE_UNUSED,
 }
 
 /* Generate a short jump around a secondary jump table.
 }
 
 /* Generate a short jump around a secondary jump table.
-   Used by md_create_long_jump.
-
-   This used to be md_create_short_jump, but is now called from
-   md_create_long_jump instead, when sufficient, since the sizes of the
-   jumps are the same for pre-v32.  */
+   Also called from md_create_long_jump, when sufficient.  */
 
 
-static void
-cris_create_short_jump (char *storep, addressT from_addr, addressT to_addr,
+void
+md_create_short_jump (char *storep, addressT from_addr, addressT to_addr,
                        fragS *fragP ATTRIBUTE_UNUSED,
                        symbolS *to_symbol ATTRIBUTE_UNUSED)
 {
                        fragS *fragP ATTRIBUTE_UNUSED,
                        symbolS *to_symbol ATTRIBUTE_UNUSED)
 {
@@ -1033,18 +1032,30 @@ cris_create_short_jump (char *storep, addressT from_addr, addressT to_addr,
   /* See md_create_long_jump about the comment on the "+ 2".  */
   long int max_minimal_minus_distance;
   long int max_minimal_plus_distance;
   /* See md_create_long_jump about the comment on the "+ 2".  */
   long int max_minimal_minus_distance;
   long int max_minimal_plus_distance;
+  long int max_minus_distance;
+  long int max_plus_distance;
   int nop_opcode;
 
   if (cris_arch == arch_crisv32)
     {
       max_minimal_minus_distance = BRANCH_BB_V32 + 2;
       max_minimal_plus_distance = BRANCH_BF_V32 + 2;
   int nop_opcode;
 
   if (cris_arch == arch_crisv32)
     {
       max_minimal_minus_distance = BRANCH_BB_V32 + 2;
       max_minimal_plus_distance = BRANCH_BF_V32 + 2;
+      max_minus_distance = BRANCH_WB_V32 + 2;
+      max_plus_distance = BRANCH_WF_V32 + 2;
       nop_opcode = NOP_OPCODE_V32;
     }
       nop_opcode = NOP_OPCODE_V32;
     }
+  else if (cris_arch == arch_cris_common_v10_v32)
+    /* Bail out for compatibility mode.  (It seems it can be implemented,
+       perhaps with a 10-byte sequence: "move.d NNNN,$pc/$acr", "jump
+       $acr", "nop"; but doesn't seem worth it at the moment.)  */
+    as_fatal (_("Out-of-range .word offset handling\
+ is not implemented for .arch common_v10_v32"));
   else
     {
       max_minimal_minus_distance = BRANCH_BB + 2;
       max_minimal_plus_distance = BRANCH_BF + 2;
   else
     {
       max_minimal_minus_distance = BRANCH_BB + 2;
       max_minimal_plus_distance = BRANCH_BF + 2;
+      max_minus_distance = BRANCH_WB + 2;
+      max_plus_distance = BRANCH_WF + 2;
       nop_opcode = NOP_OPCODE;
     }
 
       nop_opcode = NOP_OPCODE;
     }
 
@@ -1064,7 +1075,8 @@ cris_create_short_jump (char *storep, addressT from_addr, addressT to_addr,
         a nop to keep disassembly sane.  */
       md_number_to_chars (storep + 4, nop_opcode, 2);
     }
         a nop to keep disassembly sane.  */
       md_number_to_chars (storep + 4, nop_opcode, 2);
     }
-  else
+  else if (max_minus_distance <= distance
+          && distance <= max_plus_distance)
     {
       /* Make it a "long" short jump: "BA (PC+)".  */
       md_number_to_chars (storep, BA_PC_INCR_OPCODE, 2);
     {
       /* Make it a "long" short jump: "BA (PC+)".  */
       md_number_to_chars (storep, BA_PC_INCR_OPCODE, 2);
@@ -1079,6 +1091,9 @@ cris_create_short_jump (char *storep, addressT from_addr, addressT to_addr,
       /* A nop for the delay slot.  */
       md_number_to_chars (storep + 4, nop_opcode, 2);
     }
       /* A nop for the delay slot.  */
       md_number_to_chars (storep + 4, nop_opcode, 2);
     }
+  else
+    as_bad_where (fragP->fr_file, fragP->fr_line,
+                 _(".word case-table handling failed: table too large"));
 }
 
 /* Generate a long jump in a secondary jump table.
 }
 
 /* Generate a long jump in a secondary jump table.
@@ -1105,20 +1120,19 @@ md_create_long_jump (char *storep, addressT from_addr, addressT to_addr,
   long int max_short_plus_distance
     = cris_arch != arch_crisv32 ? BRANCH_WF + 3 : BRANCH_WF_V32 + 3;
 
   long int max_short_plus_distance
     = cris_arch != arch_crisv32 ? BRANCH_WF + 3 : BRANCH_WF_V32 + 3;
 
-  /* Bail out for compatibility mode.  (It seems it can be implemented,
-     perhaps with a 10-byte sequence: "move.d NNNN,$pc/$acr", "jump
-     $acr", "nop"; but doesn't seem worth it at the moment.)  */
-  if (cris_arch == arch_cris_common_v10_v32)
-    as_fatal (_("Out-of-range .word offset handling\
- is not implemented for .arch common_v10_v32"));
-
   distance = to_addr - from_addr;
 
   if (max_short_minus_distance <= distance
       && distance <= max_short_plus_distance)
   distance = to_addr - from_addr;
 
   if (max_short_minus_distance <= distance
       && distance <= max_short_plus_distance)
-    /* Then make it a "short" long jump.  */
-    cris_create_short_jump (storep, from_addr, to_addr, fragP,
+    {
+      /* Then make it a "short" long jump.  */
+      md_create_short_jump (storep, from_addr, to_addr, fragP,
                            to_symbol);
                            to_symbol);
+      if (cris_arch == arch_crisv32)
+       md_number_to_chars (storep + 6, NOP_OPCODE_V32, 2);
+      else
+       md_number_to_chars (storep + 6, NOP_OPCODE, 2);
+    }
   else
     {
       /* We have a "long" long jump: "JUMP [PC+]".  If CRISv32, always
   else
     {
       /* We have a "long" long jump: "JUMP [PC+]".  If CRISv32, always
@@ -1252,7 +1266,7 @@ md_assemble (char *str)
       /* When the expression is unknown for a BDAP, it can need 0, 2 or 4
         extra bytes, so we handle it separately.  */
     case PREFIX_BDAP_IMM:
       /* When the expression is unknown for a BDAP, it can need 0, 2 or 4
         extra bytes, so we handle it separately.  */
     case PREFIX_BDAP_IMM:
-      /* We only do it if the relocation is unspecified, i.e. not a PIC
+      /* We only do it if the relocation is unspecified, i.e. not a PIC or TLS
         relocation.  */
       if (prefix.reloc == BFD_RELOC_NONE)
        {
         relocation.  */
       if (prefix.reloc == BFD_RELOC_NONE)
        {
@@ -1269,13 +1283,13 @@ md_assemble (char *str)
       md_number_to_chars (opcodep, (long) prefix.opcode, 2);
 
       /* Having a specified reloc only happens for DIP and for BDAP with
       md_number_to_chars (opcodep, (long) prefix.opcode, 2);
 
       /* Having a specified reloc only happens for DIP and for BDAP with
-        PIC operands, but it is ok to drop through here for the other
+        PIC or TLS operands, but it is ok to drop through here for the other
         prefixes as they can have no relocs specified.  */
       if (prefix.reloc != BFD_RELOC_NONE)
        {
          unsigned int relocsize
            = (prefix.kind == PREFIX_DIP
         prefixes as they can have no relocs specified.  */
       if (prefix.reloc != BFD_RELOC_NONE)
        {
          unsigned int relocsize
            = (prefix.kind == PREFIX_DIP
-              ? 4 : cris_get_pic_reloc_size (prefix.reloc));
+              ? 4 : cris_get_specified_reloc_size (prefix.reloc));
 
          p = frag_more (relocsize);
          fix_new_exp (frag_now, (p - frag_now->fr_literal), relocsize,
 
          p = frag_more (relocsize);
          fix_new_exp (frag_now, (p - frag_now->fr_literal), relocsize,
@@ -1478,6 +1492,19 @@ md_assemble (char *str)
     }
 }
 
     }
 }
 
+/* Helper error-reporting function: calls as_bad for a format string
+   for a single value and zeroes the offending value (zero assumed
+   being a valid value) to avoid repeated error reports in later value
+   checking.  */
+
+static void
+cris_bad (const char *format, offsetT *valp)
+{
+  /* We cast to long so the format string can assume that format.  */
+  as_bad (format, (long) *valp);
+  *valp = 0;
+}
+
 /* Low level text-to-bits assembly.  */
 
 static void
 /* Low level text-to-bits assembly.  */
 
 static void
@@ -1632,8 +1659,8 @@ cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
                  if (out_insnp->expr.X_op == O_constant
                      && (out_insnp->expr.X_add_number < 0
                          || out_insnp->expr.X_add_number > 31))
                  if (out_insnp->expr.X_op == O_constant
                      && (out_insnp->expr.X_add_number < 0
                          || out_insnp->expr.X_add_number > 31))
-                   as_bad (_("Immediate value not in 5 bit unsigned range: %ld"),
-                           out_insnp->expr.X_add_number);
+                   cris_bad (_("Immediate value not in 5 bit unsigned range: %ld"),
+                             &out_insnp->expr.X_add_number);
 
                  out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_5;
                  continue;
 
                  out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_5;
                  continue;
@@ -1648,8 +1675,8 @@ cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
                  if (out_insnp->expr.X_op == O_constant
                      && (out_insnp->expr.X_add_number < 0
                          || out_insnp->expr.X_add_number > 15))
                  if (out_insnp->expr.X_op == O_constant
                      && (out_insnp->expr.X_add_number < 0
                          || out_insnp->expr.X_add_number > 15))
-                   as_bad (_("Immediate value not in 4 bit unsigned range: %ld"),
-                           out_insnp->expr.X_add_number);
+                   cris_bad (_("Immediate value not in 4 bit unsigned range: %ld"),
+                             &out_insnp->expr.X_add_number);
 
                  out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_4;
                  continue;
 
                  out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_4;
                  continue;
@@ -1700,8 +1727,9 @@ cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
                  if (out_insnp->expr.X_op == O_constant
                      && (out_insnp->expr.X_add_number < -32
                          || out_insnp->expr.X_add_number > 31))
                  if (out_insnp->expr.X_op == O_constant
                      && (out_insnp->expr.X_add_number < -32
                          || out_insnp->expr.X_add_number > 31))
-                   as_bad (_("Immediate value not in 6 bit range: %ld"),
-                           out_insnp->expr.X_add_number);
+                   cris_bad (_("Immediate value not in 6 bit range: %ld"),
+                             &out_insnp->expr.X_add_number);
+
                  out_insnp->reloc = BFD_RELOC_CRIS_SIGNED_6;
                  continue;
                }
                  out_insnp->reloc = BFD_RELOC_CRIS_SIGNED_6;
                  continue;
                }
@@ -1715,8 +1743,9 @@ cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
                  if (out_insnp->expr.X_op == O_constant
                      && (out_insnp->expr.X_add_number < 0
                          || out_insnp->expr.X_add_number > 63))
                  if (out_insnp->expr.X_op == O_constant
                      && (out_insnp->expr.X_add_number < 0
                          || out_insnp->expr.X_add_number > 63))
-                   as_bad (_("Immediate value not in 6 bit unsigned range: %ld"),
-                           out_insnp->expr.X_add_number);
+                   cris_bad (_("Immediate value not in 6 bit unsigned range: %ld"),
+                             &out_insnp->expr.X_add_number);
+
                  out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_6;
                  continue;
                }
                  out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_6;
                  continue;
                }
@@ -1783,7 +1812,7 @@ cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
              out_insnp->opcode |= regno << 12;
              out_insnp->reloc = BFD_RELOC_CRIS_SIGNED_8;
              continue;
              out_insnp->opcode |= regno << 12;
              out_insnp->reloc = BFD_RELOC_CRIS_SIGNED_8;
              continue;
-             
+
            case 'O':
              /* A BDAP expression for any size, "expr,R".  */
              if (! cris_get_expression (&s, &prefixp->expr))
            case 'O':
              /* A BDAP expression for any size, "expr,R".  */
              if (! cris_get_expression (&s, &prefixp->expr))
@@ -1819,7 +1848,7 @@ cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
                     pseudo yet, so some of this is just unused
                     framework.  */
                  if (out_insnp->spec_reg->warning)
                     pseudo yet, so some of this is just unused
                     framework.  */
                  if (out_insnp->spec_reg->warning)
-                   as_warn (out_insnp->spec_reg->warning);
+                   as_warn ("%s", out_insnp->spec_reg->warning);
                  else if (out_insnp->spec_reg->applicable_version
                           == cris_ver_warning)
                    /* Others have a generic warning.  */
                  else if (out_insnp->spec_reg->applicable_version
                           == cris_ver_warning)
                    /* Others have a generic warning.  */
@@ -1889,7 +1918,7 @@ cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
                         whether or not this is autoincrement mode.  */
                      out_insnp->opcode |= (mode << 10);
 
                         whether or not this is autoincrement mode.  */
                      out_insnp->opcode |= (mode << 10);
 
-                     /* If there was a PIC reloc specifier, then it was
+                     /* If there was a reloc specifier, then it was
                         attached to the prefix.  Note that we can't check
                         that the reloc size matches, since we don't have
                         all the operands yet in all cases.  */
                         attached to the prefix.  Note that we can't check
                         that the reloc size matches, since we don't have
                         all the operands yet in all cases.  */
@@ -1903,8 +1932,8 @@ cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
 
            case 'N':
            case 'Y':
 
            case 'N':
            case 'Y':
-             /* Like 's', but immediate operand only.  Also does not
-                modify insn.  There are no insns where a PIC reloc
+             /* Like 's', but immediate operand only.  Also do not
+                modify insn.  There are no insns where an explicit reloc
                 specifier makes sense.  */
              if (cris_get_expression (&s, &out_insnp->expr))
                {
                 specifier makes sense.  */
              if (cris_get_expression (&s, &out_insnp->expr))
                {
@@ -1927,9 +1956,10 @@ cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
                     relocation.  */
                  out_insnp->expr.X_add_number += 6;
 
                     relocation.  */
                  out_insnp->expr.X_add_number += 6;
 
-                 if (pic && *s == PIC_SUFFIX_CHAR)
-                   cris_get_pic_suffix (&s, &out_insnp->reloc,
-                                        &out_insnp->expr);
+                 /* TLS specifiers do not make sense here.  */
+                 if (pic && *s == RELOC_SUFFIX_CHAR)
+                   cris_get_reloc_suffix (&s, &out_insnp->reloc,
+                                          &out_insnp->expr);
 
                  continue;
                }
 
                  continue;
                }
@@ -2107,8 +2137,8 @@ cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
                        if (out_insnp->expr.X_op == O_constant
                            && (out_insnp->expr.X_add_number < -128
                                || out_insnp->expr.X_add_number > 255))
                        if (out_insnp->expr.X_op == O_constant
                            && (out_insnp->expr.X_add_number < -128
                                || out_insnp->expr.X_add_number > 255))
-                         as_bad (_("Immediate value not in 8 bit range: %ld"),
-                                 out_insnp->expr.X_add_number);
+                         cris_bad (_("Immediate value not in 8 bit range: %ld"),
+                                   &out_insnp->expr.X_add_number);
                        /* Fall through.  */
                      case 2:
                        /* FIXME:  We need an indicator in the instruction
                        /* Fall through.  */
                      case 2:
                        /* FIXME:  We need an indicator in the instruction
@@ -2117,8 +2147,8 @@ cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
                        if (out_insnp->expr.X_op == O_constant
                            && (out_insnp->expr.X_add_number < -32768
                                || out_insnp->expr.X_add_number > 65535))
                        if (out_insnp->expr.X_op == O_constant
                            && (out_insnp->expr.X_add_number < -32768
                                || out_insnp->expr.X_add_number > 65535))
-                         as_bad (_("Immediate value not in 16 bit range: %ld"),
-                                 out_insnp->expr.X_add_number);
+                         cris_bad (_("Immediate value not in 16 bit range: %ld"),
+                                   &out_insnp->expr.X_add_number);
                        out_insnp->imm_oprnd_size = 2;
                        break;
 
                        out_insnp->imm_oprnd_size = 2;
                        break;
 
@@ -2147,18 +2177,18 @@ cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
                          if (instruction->imm_oprnd_size == SIZE_FIELD
                              && (out_insnp->expr.X_add_number < -128
                                  || out_insnp->expr.X_add_number > 255))
                          if (instruction->imm_oprnd_size == SIZE_FIELD
                              && (out_insnp->expr.X_add_number < -128
                                  || out_insnp->expr.X_add_number > 255))
-                           as_bad (_("Immediate value not in 8 bit range: %ld"),
-                                   out_insnp->expr.X_add_number);
+                           cris_bad (_("Immediate value not in 8 bit range: %ld"),
+                                     &out_insnp->expr.X_add_number);
                          else if (instruction->imm_oprnd_size == SIZE_FIELD_SIGNED
                              && (out_insnp->expr.X_add_number < -128
                                  || out_insnp->expr.X_add_number > 127))
                          else if (instruction->imm_oprnd_size == SIZE_FIELD_SIGNED
                              && (out_insnp->expr.X_add_number < -128
                                  || out_insnp->expr.X_add_number > 127))
-                           as_bad (_("Immediate value not in 8 bit signed range: %ld"),
-                                   out_insnp->expr.X_add_number);
+                           cris_bad (_("Immediate value not in 8 bit signed range: %ld"),
+                                     &out_insnp->expr.X_add_number);
                          else if (instruction->imm_oprnd_size == SIZE_FIELD_UNSIGNED
                                   && (out_insnp->expr.X_add_number < 0
                                       || out_insnp->expr.X_add_number > 255))
                          else if (instruction->imm_oprnd_size == SIZE_FIELD_UNSIGNED
                                   && (out_insnp->expr.X_add_number < 0
                                       || out_insnp->expr.X_add_number > 255))
-                           as_bad (_("Immediate value not in 8 bit unsigned range: %ld"),
-                                   out_insnp->expr.X_add_number);
+                           cris_bad (_("Immediate value not in 8 bit unsigned range: %ld"),
+                                     &out_insnp->expr.X_add_number);
                        }
 
                      /* Fall through.  */
                        }
 
                      /* Fall through.  */
@@ -2168,18 +2198,18 @@ cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
                          if (instruction->imm_oprnd_size == SIZE_FIELD
                              && (out_insnp->expr.X_add_number < -32768
                                  || out_insnp->expr.X_add_number > 65535))
                          if (instruction->imm_oprnd_size == SIZE_FIELD
                              && (out_insnp->expr.X_add_number < -32768
                                  || out_insnp->expr.X_add_number > 65535))
-                           as_bad (_("Immediate value not in 16 bit range: %ld"),
-                                   out_insnp->expr.X_add_number);
+                           cris_bad (_("Immediate value not in 16 bit range: %ld"),
+                                     &out_insnp->expr.X_add_number);
                          else if (instruction->imm_oprnd_size == SIZE_FIELD_SIGNED
                              && (out_insnp->expr.X_add_number < -32768
                                  || out_insnp->expr.X_add_number > 32767))
                          else if (instruction->imm_oprnd_size == SIZE_FIELD_SIGNED
                              && (out_insnp->expr.X_add_number < -32768
                                  || out_insnp->expr.X_add_number > 32767))
-                           as_bad (_("Immediate value not in 16 bit signed range: %ld"),
-                                   out_insnp->expr.X_add_number);
+                           cris_bad (_("Immediate value not in 16 bit signed range: %ld"),
+                                     &out_insnp->expr.X_add_number);
                          else if (instruction->imm_oprnd_size == SIZE_FIELD_UNSIGNED
                              && (out_insnp->expr.X_add_number < 0
                                  || out_insnp->expr.X_add_number > 65535))
                          else if (instruction->imm_oprnd_size == SIZE_FIELD_UNSIGNED
                              && (out_insnp->expr.X_add_number < 0
                                  || out_insnp->expr.X_add_number > 65535))
-                           as_bad (_("Immediate value not in 16 bit unsigned range: %ld"),
-                                   out_insnp->expr.X_add_number);
+                           cris_bad (_("Immediate value not in 16 bit unsigned range: %ld"),
+                                     &out_insnp->expr.X_add_number);
                        }
                      out_insnp->imm_oprnd_size = 2;
                      break;
                        }
                      out_insnp->imm_oprnd_size = 2;
                      break;
@@ -2194,13 +2224,18 @@ cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
                }
 
              /* If there was a relocation specified for the immediate
                }
 
              /* If there was a relocation specified for the immediate
-                expression (i.e. it had a PIC modifier) check that the
-                size of the PIC relocation matches the size specified by
+                expression (i.e. it had a PIC or TLS modifier) check that the
+                size of the relocation matches the size specified by
                 the opcode.  */
              if (out_insnp->reloc != BFD_RELOC_NONE
                 the opcode.  */
              if (out_insnp->reloc != BFD_RELOC_NONE
-                 && (cris_get_pic_reloc_size (out_insnp->reloc)
+                 && (cris_get_specified_reloc_size (out_insnp->reloc)
                      != (unsigned int) out_insnp->imm_oprnd_size))
                      != (unsigned int) out_insnp->imm_oprnd_size))
-               as_bad (_("PIC relocation size does not match operand size"));
+               as_bad (out_insnp->reloc == BFD_RELOC_CRIS_32_GD
+                       || out_insnp->reloc == BFD_RELOC_CRIS_32_TPREL
+                       || out_insnp->reloc == BFD_RELOC_CRIS_16_TPREL
+                       || out_insnp->reloc == BFD_RELOC_CRIS_32_IE
+                       ? _("TLS relocation size does not match operand size")
+                       : _("PIC relocation size does not match operand size"));
            }
          else if (instruction->op == cris_muls_op
                   || instruction->op == cris_mulu_op)
            }
          else if (instruction->op == cris_muls_op
                   || instruction->op == cris_mulu_op)
@@ -2715,8 +2750,8 @@ get_autoinc_prefix_or_indir_op (char **cPP, struct cris_prefix *prefixp,
 
                          /* We tentatively put an opcode corresponding to
                             a 32-bit operand here, although it may be
 
                          /* We tentatively put an opcode corresponding to
                             a 32-bit operand here, although it may be
-                            relaxed when there's no PIC specifier for the
-                            operand.  */
+                            relaxed when there's no relocation
+                            specifier for the operand.  */
                          prefixp->opcode
                            = (BDAP_INDIR_OPCODE
                               | (prefixp->base_reg_number << 12)
                          prefixp->opcode
                            = (BDAP_INDIR_OPCODE
                               | (prefixp->base_reg_number << 12)
@@ -2726,18 +2761,18 @@ get_autoinc_prefix_or_indir_op (char **cPP, struct cris_prefix *prefixp,
 
                          /* This can have a PIC suffix, specifying reloc
                             type to use.  */
 
                          /* This can have a PIC suffix, specifying reloc
                             type to use.  */
-                         if (pic && **cPP == PIC_SUFFIX_CHAR)
+                         if ((pic || tls) && **cPP == RELOC_SUFFIX_CHAR)
                            {
                              unsigned int relocsize;
 
                            {
                              unsigned int relocsize;
 
-                             cris_get_pic_suffix (cPP, &prefixp->reloc,
-                                                  &prefixp->expr);
+                             cris_get_reloc_suffix (cPP, &prefixp->reloc,
+                                                    &prefixp->expr);
 
                              /* Tweak the size of the immediate operand
                                 in the prefix opcode if it isn't what we
                                 set.  */
                              relocsize
 
                              /* Tweak the size of the immediate operand
                                 in the prefix opcode if it isn't what we
                                 set.  */
                              relocsize
-                               = cris_get_pic_reloc_size (prefixp->reloc);
+                               = cris_get_specified_reloc_size (prefixp->reloc);
                              if (relocsize != 4)
                                prefixp->opcode
                                  = ((prefixp->opcode & ~(3 << 4))
                              if (relocsize != 4)
                                prefixp->opcode
                                  = ((prefixp->opcode & ~(3 << 4))
@@ -2763,8 +2798,9 @@ get_autoinc_prefix_or_indir_op (char **cPP, struct cris_prefix *prefixp,
                             in the blanks and break out to match the
                             final ']'.
 
                             in the blanks and break out to match the
                             final ']'.
 
-                            Note that we don't allow a PIC suffix for an
-                            operand with a minus sign.  */
+                            Note that we don't allow a relocation
+                            suffix for an operand with a minus
+                            sign.  */
                          prefixp->kind = PREFIX_BDAP_IMM;
                          break;
                        }
                          prefixp->kind = PREFIX_BDAP_IMM;
                          break;
                        }
@@ -2802,8 +2838,8 @@ get_autoinc_prefix_or_indir_op (char **cPP, struct cris_prefix *prefixp,
 
       /* This can have a PIC suffix, specifying reloc type to use.  The
         caller must check that the reloc size matches the operand size.  */
 
       /* This can have a PIC suffix, specifying reloc type to use.  The
         caller must check that the reloc size matches the operand size.  */
-      if (pic && **cPP == PIC_SUFFIX_CHAR)
-       cris_get_pic_suffix (cPP, &prefixp->reloc, imm_exprP);
+      if ((pic || tls) && **cPP == RELOC_SUFFIX_CHAR)
+       cris_get_reloc_suffix (cPP, &prefixp->reloc, imm_exprP);
 
       return 1;
     }
 
       return 1;
     }
@@ -2971,15 +3007,15 @@ get_3op_or_dip_prefix_op (char **cPP, struct cris_prefix *prefixp)
                   | REG_PC /* << 0 */);
 
              /* This can have a PIC suffix, specifying reloc type to use.  */
                   | REG_PC /* << 0 */);
 
              /* This can have a PIC suffix, specifying reloc type to use.  */
-             if (pic && **cPP == PIC_SUFFIX_CHAR)
+             if ((pic || tls) && **cPP == RELOC_SUFFIX_CHAR)
                {
                  unsigned int relocsize;
 
                {
                  unsigned int relocsize;
 
-                 cris_get_pic_suffix (cPP, &prefixp->reloc, &prefixp->expr);
+                 cris_get_reloc_suffix (cPP, &prefixp->reloc, &prefixp->expr);
 
                  /* Tweak the size of the immediate operand in the prefix
                     opcode if it isn't what we set.  */
 
                  /* Tweak the size of the immediate operand in the prefix
                     opcode if it isn't what we set.  */
-                 relocsize = cris_get_pic_reloc_size (prefixp->reloc);
+                 relocsize = cris_get_specified_reloc_size (prefixp->reloc);
                  if (relocsize != 4)
                    prefixp->opcode
                      = ((prefixp->opcode & ~(3 << 4))
                  if (relocsize != 4)
                    prefixp->opcode
                      = ((prefixp->opcode & ~(3 << 4))
@@ -3035,6 +3071,10 @@ get_3op_or_dip_prefix_op (char **cPP, struct cris_prefix *prefixp)
       prefixp->kind = PREFIX_DIP;
       prefixp->opcode = DIP_OPCODE | (AUTOINCR_BIT << 8) | REG_PC;
       prefixp->reloc = BFD_RELOC_32;
       prefixp->kind = PREFIX_DIP;
       prefixp->opcode = DIP_OPCODE | (AUTOINCR_BIT << 8) | REG_PC;
       prefixp->reloc = BFD_RELOC_32;
+
+      /* For :GD and :IE, it makes sense to have TLS specifiers here.  */
+      if ((pic || tls) && **cPP == RELOC_SUFFIX_CHAR)
+       cris_get_reloc_suffix (cPP, &prefixp->reloc, &prefixp->expr);
     }
   else
     /* Neither '[' nor register nor expression.  We lose.  */
     }
   else
     /* Neither '[' nor register nor expression.  We lose.  */
@@ -3065,7 +3105,6 @@ static int
 cris_get_expression (char **cPP, expressionS *exprP)
 {
   char *saved_input_line_pointer;
 cris_get_expression (char **cPP, expressionS *exprP)
 {
   char *saved_input_line_pointer;
-  segT exp;
 
   /* The "expression" function expects to find an expression at the
      global variable input_line_pointer, so we have to save it to give
 
   /* The "expression" function expects to find an expression at the
      global variable input_line_pointer, so we have to save it to give
@@ -3084,7 +3123,7 @@ cris_get_expression (char **cPP, expressionS *exprP)
       return 0;
     }
 
       return 0;
     }
 
-  exp = expression (exprP);
+  expression (exprP);
   if (exprP->X_op == O_illegal || exprP->X_op == O_absent)
     {
       input_line_pointer = saved_input_line_pointer;
   if (exprP->X_op == O_illegal || exprP->X_op == O_absent)
     {
       input_line_pointer = saved_input_line_pointer;
@@ -3426,13 +3465,19 @@ gen_cond_branch_32 (char *opcodep, char *writep, fragS *fragP,
     md_number_to_chars (writep + 8, MOVE_PC_INCR_OPCODE_SUFFIX, 2);
 }
 
     md_number_to_chars (writep + 8, MOVE_PC_INCR_OPCODE_SUFFIX, 2);
 }
 
-/* Get the size of an immediate-reloc in bytes.  Only valid for PIC
-   relocs.  */
+/* Get the size of an immediate-reloc in bytes.  Only valid for
+   specified relocs (TLS, PIC).  */
 
 static unsigned int
 
 static unsigned int
-cris_get_pic_reloc_size (bfd_reloc_code_real_type reloc)
+cris_get_specified_reloc_size (bfd_reloc_code_real_type reloc)
 {
 {
-  return reloc == BFD_RELOC_CRIS_16_GOTPLT || reloc == BFD_RELOC_CRIS_16_GOT
+  return
+    reloc == BFD_RELOC_CRIS_16_GOTPLT
+    || reloc == BFD_RELOC_CRIS_16_GOT
+    || reloc == BFD_RELOC_CRIS_16_GOT_GD
+    || reloc == BFD_RELOC_CRIS_16_DTPREL
+    || reloc == BFD_RELOC_CRIS_16_GOT_TPREL
+    || reloc == BFD_RELOC_CRIS_16_TPREL
     ? 2 : 4;
 }
 
     ? 2 : 4;
 }
 
@@ -3440,8 +3485,8 @@ cris_get_pic_reloc_size (bfd_reloc_code_real_type reloc)
    Adjust *EXPRP with any addend found after the PIC suffix.  */
 
 static void
    Adjust *EXPRP with any addend found after the PIC suffix.  */
 
 static void
-cris_get_pic_suffix (char **cPP, bfd_reloc_code_real_type *relocp,
-                    expressionS *exprP)
+cris_get_reloc_suffix (char **cPP, bfd_reloc_code_real_type *relocp,
+                      expressionS *exprP)
 {
   char *s = *cPP;
   unsigned int i;
 {
   char *s = *cPP;
   unsigned int i;
@@ -3452,10 +3497,14 @@ cris_get_pic_suffix (char **cPP, bfd_reloc_code_real_type *relocp,
     const char *const suffix;
     unsigned int len;
     bfd_reloc_code_real_type reloc;
     const char *const suffix;
     unsigned int len;
     bfd_reloc_code_real_type reloc;
+    bfd_boolean pic_p;
+    bfd_boolean tls_p;
   } pic_suffixes[] =
     {
 #undef PICMAP
   } pic_suffixes[] =
     {
 #undef PICMAP
-#define PICMAP(s, r) {s, sizeof (s) - 1, r}
+#define PICMAP(s, r) {s, sizeof (s) - 1, r, TRUE, FALSE}
+#define PICTLSMAP(s, r) {s, sizeof (s) - 1, r, TRUE, TRUE}
+#define TLSMAP(s, r) {s, sizeof (s) - 1, r, FALSE, TRUE}
       /* Keep this in order with longest unambiguous prefix first.  */
       PICMAP ("GOTPLT16", BFD_RELOC_CRIS_16_GOTPLT),
       PICMAP ("GOTPLT", BFD_RELOC_CRIS_32_GOTPLT),
       /* Keep this in order with longest unambiguous prefix first.  */
       PICMAP ("GOTPLT16", BFD_RELOC_CRIS_16_GOTPLT),
       PICMAP ("GOTPLT", BFD_RELOC_CRIS_32_GOTPLT),
@@ -3463,7 +3512,17 @@ cris_get_pic_suffix (char **cPP, bfd_reloc_code_real_type *relocp,
       PICMAP ("PLT", BFD_RELOC_CRIS_32_PLT_PCREL),
       PICMAP ("GOTOFF", BFD_RELOC_CRIS_32_GOTREL),
       PICMAP ("GOT16", BFD_RELOC_CRIS_16_GOT),
       PICMAP ("PLT", BFD_RELOC_CRIS_32_PLT_PCREL),
       PICMAP ("GOTOFF", BFD_RELOC_CRIS_32_GOTREL),
       PICMAP ("GOT16", BFD_RELOC_CRIS_16_GOT),
-      PICMAP ("GOT", BFD_RELOC_CRIS_32_GOT)
+      PICMAP ("GOT", BFD_RELOC_CRIS_32_GOT),
+      PICTLSMAP ("GDGOTREL16", BFD_RELOC_CRIS_16_GOT_GD),
+      PICTLSMAP ("GDGOTREL", BFD_RELOC_CRIS_32_GOT_GD),
+      TLSMAP ("GD", BFD_RELOC_CRIS_32_GD),
+      PICTLSMAP ("DTPREL16", BFD_RELOC_CRIS_16_DTPREL),
+      PICTLSMAP ("DTPREL", BFD_RELOC_CRIS_32_DTPREL),
+      TLSMAP ("IE", BFD_RELOC_CRIS_32_IE),
+      PICTLSMAP ("TPOFFGOT16", BFD_RELOC_CRIS_16_GOT_TPREL),
+      PICTLSMAP ("TPOFFGOT", BFD_RELOC_CRIS_32_GOT_TPREL),
+      TLSMAP ("TPOFF16", BFD_RELOC_CRIS_16_TPREL),
+      TLSMAP ("TPOFF", BFD_RELOC_CRIS_32_TPREL)
     };
 
   /* We've already seen the ':', so consume it.  */
     };
 
   /* We've already seen the ':', so consume it.  */
@@ -3472,7 +3531,11 @@ cris_get_pic_suffix (char **cPP, bfd_reloc_code_real_type *relocp,
   for (i = 0; i < sizeof (pic_suffixes)/sizeof (pic_suffixes[0]); i++)
     {
       if (strncmp (s, pic_suffixes[i].suffix, pic_suffixes[i].len) == 0
   for (i = 0; i < sizeof (pic_suffixes)/sizeof (pic_suffixes[0]); i++)
     {
       if (strncmp (s, pic_suffixes[i].suffix, pic_suffixes[i].len) == 0
-         && ! is_part_of_name (s[pic_suffixes[i].len]))
+         && ! is_part_of_name (s[pic_suffixes[i].len])
+         /* PIC and non-PIC relocations are exclusive.  */
+         && (pic != 0) == (pic_suffixes[i].pic_p != 0)
+         /* But TLS can be active for non-TLS relocations too.  */
+         && (pic_suffixes[i].tls_p == 0 || tls))
        {
          /* We have a match.  Consume the suffix and set the relocation
             type.   */
        {
          /* We have a match.  Consume the suffix and set the relocation
             type.   */
@@ -3528,7 +3591,7 @@ cris_get_pic_suffix (char **cPP, bfd_reloc_code_real_type *relocp,
    code as assembly code, but if they do, they should be able enough to
    find out the correct bit patterns and use them.  */
 
    code as assembly code, but if they do, they should be able enough to
    find out the correct bit patterns and use them.  */
 
-char *
+const char *
 md_atof (int type ATTRIBUTE_UNUSED, char *litp ATTRIBUTE_UNUSED,
         int *sizep ATTRIBUTE_UNUSED)
 {
 md_atof (int type ATTRIBUTE_UNUSED, char *litp ATTRIBUTE_UNUSED,
         int *sizep ATTRIBUTE_UNUSED)
 {
@@ -3580,10 +3643,12 @@ cris_number_to_imm (char *bufp, long val, int n, fixS *fixP, segT seg)
        ;
       }
 
        ;
       }
 
-  /* Only do this for old-arch binaries.  */
+  /* Only use the computed value for old-arch binaries.  For all
+     others, where we're going to output a relocation, put 0 in the
+     code.  */
   if (cris_arch != arch_cris_any_v0_v10
       && (fixP->fx_addsy != NULL || fixP->fx_pcrel))
   if (cris_arch != arch_cris_any_v0_v10
       && (fixP->fx_addsy != NULL || fixP->fx_pcrel))
-    return;
+    val = 0;
 
   switch (fixP->fx_r_type)
     {
 
   switch (fixP->fx_r_type)
     {
@@ -3592,6 +3657,22 @@ cris_number_to_imm (char *bufp, long val, int n, fixS *fixP, segT seg)
         regression tests on the object file contents.  FIXME:  Seems
         uninteresting now that we have a test suite.  */
 
         regression tests on the object file contents.  FIXME:  Seems
         uninteresting now that we have a test suite.  */
 
+    case BFD_RELOC_CRIS_32_GOT_GD:
+    case BFD_RELOC_CRIS_16_GOT_GD:
+    case BFD_RELOC_CRIS_32_GD:
+    case BFD_RELOC_CRIS_32_IE:
+    case BFD_RELOC_CRIS_32_DTPREL:
+    case BFD_RELOC_CRIS_16_DTPREL:
+    case BFD_RELOC_CRIS_32_GOT_TPREL:
+    case BFD_RELOC_CRIS_16_GOT_TPREL:
+    case BFD_RELOC_CRIS_32_TPREL:
+    case BFD_RELOC_CRIS_16_TPREL:
+#if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
+      if (IS_ELF && fixP->fx_addsy != NULL)
+       S_SET_THREAD_LOCAL (fixP->fx_addsy);
+#endif
+      /* Fall through.  */
+
     case BFD_RELOC_CRIS_16_GOT:
     case BFD_RELOC_CRIS_32_GOT:
     case BFD_RELOC_CRIS_32_GOTREL:
     case BFD_RELOC_CRIS_16_GOT:
     case BFD_RELOC_CRIS_32_GOT:
     case BFD_RELOC_CRIS_32_GOTREL:
@@ -3601,13 +3682,14 @@ cris_number_to_imm (char *bufp, long val, int n, fixS *fixP, segT seg)
     case BFD_RELOC_CRIS_32_PLT_PCREL:
       /* We don't want to put in any kind of non-zero bits in the data
         being relocated for these.  */
     case BFD_RELOC_CRIS_32_PLT_PCREL:
       /* We don't want to put in any kind of non-zero bits in the data
         being relocated for these.  */
+      md_number_to_chars (bufp, 0, n);
       break;
 
     case BFD_RELOC_32_PCREL:
       break;
 
     case BFD_RELOC_32_PCREL:
-      /* If this one isn't fully resolved, we don't want to put anything
+      /* If this one isn't fully resolved, we don't want to put non-zero
         in the object.  */
       if (fixP->fx_addsy != NULL || fixP->fx_pcrel)
         in the object.  */
       if (fixP->fx_addsy != NULL || fixP->fx_pcrel)
-       break;
+       val = 0;
 
       /* Fall through.  */
     case BFD_RELOC_32:
 
       /* Fall through.  */
     case BFD_RELOC_32:
@@ -3629,38 +3711,30 @@ cris_number_to_imm (char *bufp, long val, int n, fixS *fixP, segT seg)
       if (val > 0xffff || val < -32768)
        as_bad_where (fixP->fx_file, fixP->fx_line,
                      _("Value not in 16 bit range: %ld"), val);
       if (val > 0xffff || val < -32768)
        as_bad_where (fixP->fx_file, fixP->fx_line,
                      _("Value not in 16 bit range: %ld"), val);
-      if (! fixP->fx_addsy)
-       {
-         bufp[1] = (val >> 8) & 0xFF;
-         bufp[0] = val & 0xFF;
-       }
+      bufp[1] = (val >> 8) & 0xFF;
+      bufp[0] = val & 0xFF;
       break;
 
     case BFD_RELOC_CRIS_SIGNED_16:
       if (val > 32767 || val < -32768)
        as_bad_where (fixP->fx_file, fixP->fx_line,
                      _("Value not in 16 bit signed range: %ld"), val);
       break;
 
     case BFD_RELOC_CRIS_SIGNED_16:
       if (val > 32767 || val < -32768)
        as_bad_where (fixP->fx_file, fixP->fx_line,
                      _("Value not in 16 bit signed range: %ld"), val);
-      if (! fixP->fx_addsy)
-       {
-         bufp[1] = (val >> 8) & 0xFF;
-         bufp[0] = val & 0xFF;
-       }
+      bufp[1] = (val >> 8) & 0xFF;
+      bufp[0] = val & 0xFF;
       break;
 
     case BFD_RELOC_8:
     case BFD_RELOC_8_PCREL:
       if (val > 255 || val < -128)
        as_bad_where (fixP->fx_file, fixP->fx_line, _("Value not in 8 bit range: %ld"), val);
       break;
 
     case BFD_RELOC_8:
     case BFD_RELOC_8_PCREL:
       if (val > 255 || val < -128)
        as_bad_where (fixP->fx_file, fixP->fx_line, _("Value not in 8 bit range: %ld"), val);
-      if (! fixP->fx_addsy)
-       bufp[0] = val & 0xFF;
+      bufp[0] = val & 0xFF;
       break;
 
     case BFD_RELOC_CRIS_SIGNED_8:
       if (val > 127 || val < -128)
        as_bad_where (fixP->fx_file, fixP->fx_line,
                      _("Value not in 8 bit signed range: %ld"), val);
       break;
 
     case BFD_RELOC_CRIS_SIGNED_8:
       if (val > 127 || val < -128)
        as_bad_where (fixP->fx_file, fixP->fx_line,
                      _("Value not in 8 bit signed range: %ld"), val);
-      if (! fixP->fx_addsy)
-       bufp[0] = val & 0xFF;
+      bufp[0] = val & 0xFF;
       break;
 
     case BFD_RELOC_CRIS_LAPCQ_OFFSET:
       break;
 
     case BFD_RELOC_CRIS_LAPCQ_OFFSET:
@@ -3670,37 +3744,32 @@ cris_number_to_imm (char *bufp, long val, int n, fixS *fixP, segT seg)
       if (val > 15 || val < 0)
        as_bad_where (fixP->fx_file, fixP->fx_line,
                      _("Value not in 4 bit unsigned range: %ld"), val);
       if (val > 15 || val < 0)
        as_bad_where (fixP->fx_file, fixP->fx_line,
                      _("Value not in 4 bit unsigned range: %ld"), val);
-      if (! fixP->fx_addsy)
-       bufp[0] |= val & 0x0F;
+      bufp[0] |= val & 0x0F;
       break;
 
     case BFD_RELOC_CRIS_UNSIGNED_5:
       if (val > 31 || val < 0)
        as_bad_where (fixP->fx_file, fixP->fx_line,
                      _("Value not in 5 bit unsigned range: %ld"), val);
       break;
 
     case BFD_RELOC_CRIS_UNSIGNED_5:
       if (val > 31 || val < 0)
        as_bad_where (fixP->fx_file, fixP->fx_line,
                      _("Value not in 5 bit unsigned range: %ld"), val);
-      if (! fixP->fx_addsy)
-       bufp[0] |= val & 0x1F;
+      bufp[0] |= val & 0x1F;
       break;
 
     case BFD_RELOC_CRIS_SIGNED_6:
       if (val > 31 || val < -32)
        as_bad_where (fixP->fx_file, fixP->fx_line,
                      _("Value not in 6 bit range: %ld"), val);
       break;
 
     case BFD_RELOC_CRIS_SIGNED_6:
       if (val > 31 || val < -32)
        as_bad_where (fixP->fx_file, fixP->fx_line,
                      _("Value not in 6 bit range: %ld"), val);
-      if (! fixP->fx_addsy)
-       bufp[0] |= val & 0x3F;
+      bufp[0] |= val & 0x3F;
       break;
 
     case BFD_RELOC_CRIS_UNSIGNED_6:
       if (val > 63 || val < 0)
        as_bad_where (fixP->fx_file, fixP->fx_line,
                      _("Value not in 6 bit unsigned range: %ld"), val);
       break;
 
     case BFD_RELOC_CRIS_UNSIGNED_6:
       if (val > 63 || val < 0)
        as_bad_where (fixP->fx_file, fixP->fx_line,
                      _("Value not in 6 bit unsigned range: %ld"), val);
-      if (! fixP->fx_addsy)
-       bufp[0] |= val & 0x3F;
+      bufp[0] |= val & 0x3F;
       break;
 
     case BFD_RELOC_CRIS_BDISP8:
       break;
 
     case BFD_RELOC_CRIS_BDISP8:
-      if (! fixP->fx_addsy)
-       bufp[0] = branch_disp (val);
+      bufp[0] = branch_disp (val);
       break;
 
     case BFD_RELOC_NONE:
       break;
 
     case BFD_RELOC_NONE:
@@ -3733,7 +3802,7 @@ cris_number_to_imm (char *bufp, long val, int n, fixS *fixP, segT seg)
    GAS does not understand.  */
 
 int
    GAS does not understand.  */
 
 int
-md_parse_option (int arg, char *argp ATTRIBUTE_UNUSED)
+md_parse_option (int arg, const char *argp ATTRIBUTE_UNUSED)
 {
   switch (arg)
     {
 {
   switch (arg)
     {
@@ -3762,6 +3831,8 @@ md_parse_option (int arg, char *argp ATTRIBUTE_UNUSED)
       break;
 
     case OPTION_PIC:
       break;
 
     case OPTION_PIC:
+      if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
+       as_bad (_("--pic is invalid for this object format"));
       pic = TRUE;
       if (cris_arch != arch_crisv32)
        md_long_jump_size = cris_any_v0_v10_long_jump_size_pic;
       pic = TRUE;
       if (cris_arch != arch_crisv32)
        md_long_jump_size = cris_any_v0_v10_long_jump_size_pic;
@@ -3771,7 +3842,7 @@ md_parse_option (int arg, char *argp ATTRIBUTE_UNUSED)
 
     case OPTION_ARCH:
       {
 
     case OPTION_ARCH:
       {
-       char *str = argp;
+       const char *str = argp;
        enum cris_archs argarch = cris_arch_from_string (&str);
 
        if (argarch == arch_cris_unknown)
        enum cris_archs argarch = cris_arch_from_string (&str);
 
        if (argarch == arch_cris_unknown)
@@ -3870,6 +3941,16 @@ tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixP)
     case BFD_RELOC_CRIS_UNSIGNED_8:
     case BFD_RELOC_CRIS_UNSIGNED_16:
     case BFD_RELOC_CRIS_LAPCQ_OFFSET:
     case BFD_RELOC_CRIS_UNSIGNED_8:
     case BFD_RELOC_CRIS_UNSIGNED_16:
     case BFD_RELOC_CRIS_LAPCQ_OFFSET:
+    case BFD_RELOC_CRIS_32_GOT_GD:
+    case BFD_RELOC_CRIS_16_GOT_GD:
+    case BFD_RELOC_CRIS_32_GD:
+    case BFD_RELOC_CRIS_32_IE:
+    case BFD_RELOC_CRIS_32_DTPREL:
+    case BFD_RELOC_CRIS_16_DTPREL:
+    case BFD_RELOC_CRIS_32_GOT_TPREL:
+    case BFD_RELOC_CRIS_16_GOT_TPREL:
+    case BFD_RELOC_CRIS_32_TPREL:
+    case BFD_RELOC_CRIS_16_TPREL:
       code = fixP->fx_r_type;
       break;
     default:
       code = fixP->fx_r_type;
       break;
     default:
@@ -3878,9 +3959,9 @@ tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixP)
       return 0;
     }
 
       return 0;
     }
 
-  relP = (arelent *) xmalloc (sizeof (arelent));
-  assert (relP != 0);
-  relP->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
+  relP = XNEW (arelent);
+  gas_assert (relP != 0);
+  relP->sym_ptr_ptr = XNEW (asymbol *);
   *relP->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy);
   relP->address = fixP->fx_frag->fr_address + fixP->fx_where;
 
   *relP->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy);
   relP->address = fixP->fx_frag->fr_address + fixP->fx_where;
 
@@ -3949,8 +4030,10 @@ md_show_usage (FILE *stream)
           _("  --no-underscore         User symbols do not have any prefix.\n"));
   fprintf (stream, "%s",
           _("                          Registers will require a `$'-prefix.\n"));
           _("  --no-underscore         User symbols do not have any prefix.\n"));
   fprintf (stream, "%s",
           _("                          Registers will require a `$'-prefix.\n"));
+#if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
   fprintf (stream, "%s",
           _("  --pic                   Enable generation of position-independent code.\n"));
   fprintf (stream, "%s",
           _("  --pic                   Enable generation of position-independent code.\n"));
+#endif
   fprintf (stream, "%s",
           _("  --march=<arch>          Generate code for <arch>.  Valid choices for <arch>\n\
                                are v0_v10, v10, v32 and common_v10_v32.\n"));
   fprintf (stream, "%s",
           _("  --march=<arch>          Generate code for <arch>.  Valid choices for <arch>\n\
                                are v0_v10, v10, v32 and common_v10_v32.\n"));
@@ -4158,13 +4241,37 @@ s_cris_loc (int dummy)
     dwarf2_directive_loc (dummy);
 }
 
     dwarf2_directive_loc (dummy);
 }
 
+/* Worker for .dtpoffd: generate a R_CRIS_32_DTPREL reloc, as for
+   expr:DTPREL but for use in debug info.  */
+
+static void
+s_cris_dtpoff (int bytes)
+{
+  expressionS ex;
+  char *p;
+
+  if (bytes != 4)
+    as_fatal (_("internal inconsistency problem: %s called for %d bytes"),
+             __FUNCTION__, bytes);
+
+  expression (&ex);
+
+  p = frag_more (bytes);
+  md_number_to_chars (p, 0, bytes);
+  fix_new_exp (frag_now, p - frag_now->fr_literal, bytes, &ex, FALSE,
+              BFD_RELOC_CRIS_32_DTPREL);
+
+  demand_empty_rest_of_line ();
+}
+
+
 /* Translate a <arch> string (as common to --march=<arch> and .arch <arch>)
    into an enum.  If the string *STR is recognized, *STR is updated to point
    to the end of the string.  If the string is not recognized,
    arch_cris_unknown is returned.  */
 
 static enum cris_archs
 /* Translate a <arch> string (as common to --march=<arch> and .arch <arch>)
    into an enum.  If the string *STR is recognized, *STR is updated to point
    to the end of the string.  If the string is not recognized,
    arch_cris_unknown is returned.  */
 
 static enum cris_archs
-cris_arch_from_string (char **str)
+cris_arch_from_string (const char **str)
 {
   static const struct cris_arch_struct
   {
 {
   static const struct cris_arch_struct
   {
@@ -4220,7 +4327,7 @@ cris_insn_ver_valid_for_arch (enum cris_insn_version_usage iver,
         || iver == cris_ver_v8_10
         || iver == cris_ver_v10
         || iver == cris_ver_v10p);
         || iver == cris_ver_v8_10
         || iver == cris_ver_v10
         || iver == cris_ver_v10p);
-      
+
     case arch_crisv32:
       return
        (iver == cris_ver_version_all
     case arch_crisv32:
       return
        (iver == cris_ver_version_all
@@ -4291,7 +4398,7 @@ s_cris_arch (int dummy ATTRIBUTE_UNUSED)
      would be more useful than confusing, implementation-wise and
      user-wise.  */
 
      would be more useful than confusing, implementation-wise and
      user-wise.  */
 
-  char *str = input_line_pointer;
+  const char *str = input_line_pointer;
   enum cris_archs arch = cris_arch_from_string (&str);
 
   if (arch == arch_cris_unknown)
   enum cris_archs arch = cris_arch_from_string (&str);
 
   if (arch == arch_cris_unknown)
@@ -4307,7 +4414,7 @@ s_cris_arch (int dummy ATTRIBUTE_UNUSED)
   else if (arch != cris_arch)
     as_bad (_(".arch <arch> requires a matching --march=... option"));
 
   else if (arch != cris_arch)
     as_bad (_(".arch <arch> requires a matching --march=... option"));
 
-  input_line_pointer = str;
+  input_line_pointer = (char *) str;
   demand_empty_rest_of_line ();
   return;
 }
   demand_empty_rest_of_line ();
   return;
 }
This page took 0.080225 seconds and 4 git commands to generate.