+\f
+#ifdef OBJ_ELF
+/* Parse @got, etc. and return the desired relocation.
+ If we have additional arithmetic expression, then we fill in new_exp_p. */
+static bfd_reloc_code_real_type
+sh_elf_suffix (str_p, exp_p, new_exp_p)
+ char **str_p;
+ expressionS *exp_p, *new_exp_p;
+{
+ struct map_bfd {
+ char *string;
+ int length;
+ bfd_reloc_code_real_type reloc;
+ };
+
+ char ident[20];
+ char *str = *str_p;
+ char *str2;
+ int ch;
+ int len;
+ struct map_bfd *ptr;
+
+#define MAP(str,reloc) { str, sizeof (str)-1, reloc }
+
+ static struct map_bfd mapping[] = {
+ MAP ("got", BFD_RELOC_32_GOT_PCREL),
+ MAP ("plt", BFD_RELOC_32_PLT_PCREL),
+ MAP ("gotoff", BFD_RELOC_32_GOTOFF),
+ { (char *)0, 0, BFD_RELOC_UNUSED }
+ };
+
+ if (*str++ != '@')
+ return BFD_RELOC_UNUSED;
+
+ for (ch = *str, str2 = ident;
+ (str2 < ident + sizeof (ident) - 1
+ && (isalnum (ch) || ch == '@'));
+ ch = *++str)
+ {
+ *str2++ = (islower (ch)) ? ch : tolower (ch);
+ }
+
+ *str2 = '\0';
+ len = str2 - ident;
+
+ ch = ident[0];
+ for (ptr = &mapping[0]; ptr->length > 0; ptr++)
+ if (ch == ptr->string[0]
+ && len == ptr->length
+ && memcmp (ident, ptr->string, ptr->length) == 0)
+ {
+ /* Now check for identifier@suffix+constant */
+ if (*str == '-' || *str == '+')
+ {
+ char *orig_line = input_line_pointer;
+
+ input_line_pointer = str;
+ expression (new_exp_p);
+ if (new_exp_p->X_op == O_constant)
+ {
+ exp_p->X_add_number += new_exp_p->X_add_number;
+ str = input_line_pointer;
+ }
+ if (new_exp_p->X_op == O_subtract)
+ str = input_line_pointer;
+
+ if (&input_line_pointer != str_p)
+ input_line_pointer = orig_line;
+ }
+
+ *str_p = str;
+ return ptr->reloc;
+ }
+
+ return BFD_RELOC_UNUSED;
+}
+
+/* The regular cons() function, that reads constants, doesn't support
+ suffixes such as @GOT, @GOTOFF and @PLT, that generate
+ machine-specific relocation types. So we must define it here. */
+/* Clobbers input_line_pointer, checks end-of-line. */
+static void
+sh_elf_cons (nbytes)
+ register int nbytes; /* 1=.byte, 2=.word, 4=.long */
+{
+ expressionS exp, new_exp;
+ bfd_reloc_code_real_type reloc;
+ const char *name;
+
+ if (is_it_end_of_statement ())
+ {
+ demand_empty_rest_of_line ();
+ return;
+ }
+
+ do
+ {
+ expression (&exp);
+ new_exp.X_op = O_absent;
+ new_exp.X_add_symbol = new_exp.X_op_symbol = NULL;
+ /* If the _GLOBAL_OFFSET_TABLE_ symbol hasn't been found yet,
+ use the name of the symbol to tell whether it's the
+ _GLOBAL_OFFSET_TABLE_. If it has, comparing the symbols is
+ sufficient. */
+ if (! GOT_symbol && exp.X_add_symbol)
+ name = S_GET_NAME (exp.X_add_symbol);
+ else
+ name = NULL;
+ /* Check whether this expression involves the
+ _GLOBAL_OFFSET_TABLE_ symbol, by itself or added to a
+ difference of two other symbols. */
+ if (((GOT_symbol && GOT_symbol == exp.X_add_symbol)
+ || (! GOT_symbol && name
+ && strcmp (name, GLOBAL_OFFSET_TABLE_NAME) == 0))
+ && (exp.X_op == O_symbol
+ || (exp.X_op == O_add
+ && ((symbol_get_value_expression (exp.X_op_symbol)->X_op)
+ == O_subtract))))
+ {
+ reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput,
+ BFD_RELOC_32);
+ int size = bfd_get_reloc_size (reloc_howto);
+
+ if (GOT_symbol == NULL)
+ GOT_symbol = symbol_find_or_make (GLOBAL_OFFSET_TABLE_NAME);
+
+ if (size > nbytes)
+ as_bad (_("%s relocations do not fit in %d bytes\n"),
+ reloc_howto->name, nbytes);
+ else
+ {
+ register char *p = frag_more ((int) nbytes);
+ int offset = nbytes - size;
+
+ fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
+ size, &exp, 0, TC_RELOC_GLOBAL_OFFSET_TABLE);
+ }
+ }
+ /* Check if this symbol involves one of the magic suffixes, such
+ as @GOT, @GOTOFF or @PLT, and determine which relocation type
+ to use. */
+ else if ((exp.X_op == O_symbol || (exp.X_op == O_add && exp.X_op_symbol))
+ && *input_line_pointer == '@'
+ && ((reloc = sh_elf_suffix (&input_line_pointer, &exp, &new_exp))
+ != BFD_RELOC_UNUSED))
+ {
+ reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput,
+ reloc);
+ int size = bfd_get_reloc_size (reloc_howto);
+
+ /* Force a GOT to be generated. */
+ if (GOT_symbol == NULL)
+ GOT_symbol = symbol_find_or_make (GLOBAL_OFFSET_TABLE_NAME);
+
+ if (size > nbytes)
+ as_bad (_("%s relocations do not fit in %d bytes\n"),
+ reloc_howto->name, nbytes);
+ else
+ {
+ register char *p = frag_more ((int) nbytes);
+ int offset = nbytes - size;
+
+ fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size,
+ &exp, 0, reloc);
+ if (new_exp.X_op != O_absent)
+ fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size,
+ &new_exp, 0, BFD_RELOC_32);
+ }
+ }
+ else
+ emit_expr (&exp, (unsigned int) nbytes);
+ }
+ while (*input_line_pointer++ == ',');
+
+ input_line_pointer--; /* Put terminator back into stream. */
+ if (*input_line_pointer == '#' || *input_line_pointer == '!')
+ {
+ while (! is_end_of_line[(unsigned char) *input_line_pointer++]);
+ }
+ else
+ demand_empty_rest_of_line ();
+}
+#endif /* OBJ_ELF */
+
+\f
+/* This function is called once, at assembler startup time. This should
+ set up all the tables, etc that the MD part of the assembler needs. */