gas:
[deliverable/binutils-gdb.git] / gas / config / tc-vax.c
index acf78ee199f008290ca7478420a1e7eff5fecba8..0e0fbfa9cea816982d9455f80c56b2f393dc7b6d 100644 (file)
@@ -1,5 +1,6 @@
 /* tc-vax.c - vax-specific -
-   Copyright (C) 1987, 91, 92, 93, 94, 95, 98, 1999
+   Copyright 1987, 1991, 1992, 1993, 1994, 1995, 1998, 2000, 2001, 2002,
+   2003, 2004, 2005
    Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
 
    You should have received a copy of the GNU General Public License
    along with GAS; see the file COPYING.  If not, write to the Free
-   Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.  */
+   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
+   02110-1301, USA.  */
 
 #include "as.h"
 
 #include "vax-inst.h"
 #include "obstack.h"           /* For FRAG_APPEND_1_CHAR macro in "frags.h" */
+#include "subsegs.h"
+
+#ifdef OBJ_ELF
+#include "elf/vax.h"
+#endif
+
+#if defined (OBJ_AOUT) && !defined (BFD_ASSEMBLER) && defined (TE_NetBSD)
+#include <netinet/in.h>
+#endif
 
 /* These chars start a comment anywhere in a source file (except inside
    another comment */
 const char comment_chars[] = "#";
 
-/* These chars only start a comment at the beginning of a line. */
-/* Note that for the VAX the are the same as comment_chars above. */
+/* These chars only start a comment at the beginning of a line.  */
+/* Note that for the VAX the are the same as comment_chars above.  */
 const char line_comment_chars[] = "#";
 
 const char line_separator_chars[] = ";";
@@ -50,18 +60,28 @@ const char FLT_CHARS[] = "dDfFgGhH";
 static expressionS exp_of_operand[VIT_MAX_OPERANDS];
 static segT seg_of_operand[VIT_MAX_OPERANDS];
 
-/* A vax instruction after decoding. */
+/* A vax instruction after decoding.  */
 static struct vit v;
 
-/* Hold details of big operands. */
+/* Hold details of big operands.  */
 LITTLENUM_TYPE big_operand_bits[VIT_MAX_OPERANDS][SIZE_OF_LARGE_NUMBER];
 FLONUM_TYPE float_operand[VIT_MAX_OPERANDS];
-/* Above is made to point into big_operand_bits by md_begin(). */
+/* Above is made to point into big_operand_bits by md_begin().  */
+
+#ifdef OBJ_ELF
+#define GLOBAL_OFFSET_TABLE_NAME       "_GLOBAL_OFFSET_TABLE_"
+#define PROCEDURE_LINKAGE_TABLE_NAME   "_PROCEDURE_LINKAGE_TABLE_"
+symbolS *GOT_symbol;           /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
+symbolS *PLT_symbol;           /* Pre-defined "_PROCEDURE_LINKAGE_TABLE_" */
+#endif
 
 int flag_hash_long_names;      /* -+ */
 int flag_one;                  /* -1 */
 int flag_show_after_trunc;     /* -H */
 int flag_no_hash_mixed_case;   /* -h NUM */
+#ifdef OBJ_ELF
+int flag_want_pic;             /* -k */
+#endif
 \f
 /*
  * For VAX, relative addresses of "just the right length" are easy.
@@ -113,8 +133,6 @@ int flag_no_hash_mixed_case;        /* -h NUM */
  bbcs          e3
  bbsc          e4
  bbcc          e5
- bbssi         e6
- bbcci         e7
  Always, you complement 0th bit to reverse condition.
  Always, 1-byte opcde, longword-address, byte-address, 1-byte-displacement
 
@@ -173,17 +191,18 @@ int flag_no_hash_mixed_case;      /* -h NUM */
 \f
 /* These displacements are relative to the start address of the
    displacement.  The first letter is Byte, Word.  2nd letter is
-   Forward, Backward. */
+   Forward, Backward.  */
 #define BF (1+ 127)
 #define BB (1+-128)
 #define WF (2+ 32767)
 #define WB (2+-32768)
 /* Dont need LF, LB because they always reach. [They are coded as 0.] */
 
-
 #define C(a,b) ENCODE_RELAX(a,b)
-/* This macro has no side-effects. */
+/* This macro has no side-effects.  */
 #define ENCODE_RELAX(what,length) (((what) << 2) + (length))
+#define RELAX_STATE(s) ((s) >> 2)
+#define RELAX_LENGTH(s) ((s) & 3)
 
 const relax_typeS md_relax_table[] =
 {
@@ -191,25 +210,31 @@ const relax_typeS md_relax_table[] =
   {1, 1, 0, 0},                        /* unused           0,1 */
   {1, 1, 0, 0},                        /* unused           0,2 */
   {1, 1, 0, 0},                        /* unused           0,3 */
+
   {BF + 1, BB + 1, 2, C (1, 1)},/* B^"foo"         1,0 */
   {WF + 1, WB + 1, 3, C (1, 2)},/* W^"foo"         1,1 */
   {0, 0, 5, 0},                        /* L^"foo"          1,2 */
   {1, 1, 0, 0},                        /* unused           1,3 */
+
   {BF, BB, 1, C (2, 1)},       /* b<cond> B^"foo"  2,0 */
   {WF + 2, WB + 2, 4, C (2, 2)},/* br.+? brw X     2,1 */
   {0, 0, 7, 0},                        /* br.+? jmp X      2,2 */
   {1, 1, 0, 0},                        /* unused           2,3 */
+
   {BF, BB, 1, C (3, 1)},       /* brb B^foo        3,0 */
   {WF, WB, 2, C (3, 2)},       /* brw W^foo        3,1 */
   {0, 0, 5, 0},                        /* Jmp L^foo        3,2 */
   {1, 1, 0, 0},                        /* unused           3,3 */
+
   {1, 1, 0, 0},                        /* unused           4,0 */
   {WF, WB, 2, C (4, 2)},       /* acb_ ^Wfoo       4,1 */
   {0, 0, 10, 0},               /* acb_,br,jmp L^foo4,2 */
   {1, 1, 0, 0},                        /* unused           4,3 */
+
   {BF, BB, 1, C (5, 1)},       /* Xob___,,foo      5,0 */
   {WF + 4, WB + 4, 6, C (5, 2)},/* Xob.+2,brb.+3,brw5,1 */
   {0, 0, 9, 0},                        /* Xob.+2,brb.+6,jmp5,2 */
+  {1, 1, 0, 0},                        /* unused           5,3 */
 };
 
 #undef C
@@ -218,7 +243,7 @@ const relax_typeS md_relax_table[] =
 #undef WF
 #undef WB
 
-void float_cons ();
+void float_cons PARAMS ((int));
 
 const pseudo_typeS md_pseudo_table[] =
 {
@@ -226,12 +251,16 @@ const pseudo_typeS md_pseudo_table[] =
   {"ffloat", float_cons, 'f'},
   {"gfloat", float_cons, 'g'},
   {"hfloat", float_cons, 'h'},
-  {0},
+  {"d_floating", float_cons, 'd'},
+  {"f_floating", float_cons, 'f'},
+  {"g_floating", float_cons, 'g'},
+  {"h_floating", float_cons, 'h'},
+  {NULL, NULL, 0},
 };
 
 #define STATE_PC_RELATIVE              (1)
 #define STATE_CONDITIONAL_BRANCH       (2)
-#define STATE_ALWAYS_BRANCH            (3)     /* includes BSB... */
+#define STATE_ALWAYS_BRANCH            (3)     /* includes BSB...  */
 #define STATE_COMPLEX_BRANCH           (4)
 #define STATE_COMPLEX_HOP              (5)
 
@@ -240,17 +269,19 @@ const pseudo_typeS md_pseudo_table[] =
 #define STATE_LONG                     (2)
 #define STATE_UNDF                     (3)     /* Symbol undefined in pass1 */
 
-
 #define min(a, b)      ((a) < (b) ? (a) : (b))
 
 int flonum_gen2vax PARAMS ((char format_letter, FLONUM_TYPE * f,
                            LITTLENUM_TYPE * words));
 static const char *vip_begin PARAMS ((int, const char *, const char *,
                                      const char *));
+static void vip_op_1 PARAMS ((int, const char *));
 static void vip_op_defaults PARAMS ((const char *, const char *, const char *));
 static void vip_op PARAMS ((char *, struct vop *));
 static void vip PARAMS ((struct vit *, char *));
 
+static int vax_reg_parse PARAMS ((char, char, char, char));
+
 void
 md_begin ()
 {
@@ -284,19 +315,30 @@ md_number_to_chars (con, value, nbytes)
 /* Fix up some data or instructions after we find out the value of a symbol
    that they reference.  */
 
-void                           /* Knows about order of bytes in address. */
-md_apply_fix (fixP, value)
+void                           /* Knows about order of bytes in address.  */
+md_apply_fix (fixP, valueP, seg)
      fixS *fixP;
-     long value;
+     valueT *valueP;
+     segT seg ATTRIBUTE_UNUSED;
 {
-  number_to_chars_littleendian (fixP->fx_where + fixP->fx_frag->fr_literal,
-                               (valueT) value, fixP->fx_size);
+  valueT value = * valueP;
+#ifdef BFD_ASSEMBLER
+  if (((fixP->fx_addsy == NULL && fixP->fx_subsy == NULL)
+       && fixP->fx_r_type != BFD_RELOC_32_PLT_PCREL
+       && fixP->fx_r_type != BFD_RELOC_32_GOT_PCREL)
+      || fixP->fx_r_type == NO_RELOC)
+#endif
+    number_to_chars_littleendian (fixP->fx_where + fixP->fx_frag->fr_literal,
+                                 value, fixP->fx_size);
+
+  if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
+    fixP->fx_done = 1;
 }
 
 long
 md_chars_to_number (con, nbytes)
-     unsigned char con[];      /* Low order byte 1st. */
-     int nbytes;               /* Number of bytes in the input. */
+     unsigned char con[];      /* Low order byte 1st.  */
+     int nbytes;               /* Number of bytes in the input.  */
 {
   long retval;
   for (retval = 0, con += nbytes - 1; nbytes--; con--)
@@ -306,24 +348,80 @@ md_chars_to_number (con, nbytes)
     }
   return retval;
 }
+
+/*
+ * Copy a bignum from in to out.
+ * If the output is shorter than the input, copy lower-order
+ * littlenums.  Return 0 or the number of significant littlenums
+ * dropped.  Assumes littlenum arrays are densely packed: no unused
+ * chars between the littlenums. Uses memcpy() to move littlenums, and
+ * wants to know length (in chars) of the input bignum.
+ */
+
+static int
+bignum_copy (register LITTLENUM_TYPE *in,
+            register int in_length,    /* in sizeof(littlenum)s */
+            register LITTLENUM_TYPE *out,
+            register int out_length    /* in sizeof(littlenum)s */)
+{
+  int significant_littlenums_dropped;
+
+  if (out_length < in_length)
+    {
+      LITTLENUM_TYPE *p;       /* -> most significant (non-zero) input
+                                     littlenum.  */
+
+      memcpy ((void *) out, (void *) in,
+             (unsigned int) out_length << LITTLENUM_SHIFT);
+      for (p = in + in_length - 1; p >= in; --p)
+       {
+         if (*p)
+           break;
+       }
+      significant_littlenums_dropped = p - in - in_length + 1;
+
+      if (significant_littlenums_dropped < 0)
+       {
+         significant_littlenums_dropped = 0;
+       }
+    }
+  else
+    {
+      memcpy ((char *) out, (char *) in,
+             (unsigned int) in_length << LITTLENUM_SHIFT);
+
+      if (out_length > in_length)
+       {
+         memset ((char *) (out + in_length),
+                 '\0',
+                 (unsigned int) (out_length - in_length) << LITTLENUM_SHIFT);
+       }
+
+      significant_littlenums_dropped = 0;
+    }
+
+  return (significant_littlenums_dropped);
+}
 \f
 /* vax:md_assemble() emit frags for 1 instruction */
 
 void
 md_assemble (instruction_string)
-     char *instruction_string; /* A string: assemble 1 instruction. */
+     char *instruction_string; /* A string: assemble 1 instruction.  */
 {
-  /* Non-zero if operand expression's segment is not known yet. */
+  /* Non-zero if operand expression's segment is not known yet.  */
   int is_undefined;
+  /* Non-zero if operand expression's segment is absolute.  */
+  int is_absolute;
 
   int length_code;
   char *p;
-  /* An operand. Scans all operands. */
+  /* An operand. Scans all operands.  */
   struct vop *operandP;
   char *save_input_line_pointer;
-                       /* What used to live after an expression. */
+                       /* What used to live after an expression.  */
   char c_save;
-  /* 1: instruction_string bad for all passes. */
+  /* 1: instruction_string bad for all passes.  */
   int goofed;
   /* Points to slot just after last operand.  */
   struct vop *end_operandP;
@@ -331,28 +429,28 @@ md_assemble (instruction_string)
   expressionS *expP;
   segT *segP;
 
-  /* These refer to an instruction operand expression. */
+  /* These refer to an instruction operand expression.  */
   /* Target segment of the address.     */
   segT to_seg;
   valueT this_add_number;
-  /* Positive (minuend) symbol. */
+  /* Positive (minuend) symbol.  */
   symbolS *this_add_symbol;
-  /* As a number. */
+  /* As a number.  */
   long opcode_as_number;
-  /* Least significant byte 1st. */
+  /* Least significant byte 1st.  */
   char *opcode_as_chars;
-  /* As an array of characters. */
+  /* As an array of characters.  */
   /* Least significant byte 1st */
   char *opcode_low_byteP;
-  /* length (bytes) meant by vop_short. */
+  /* length (bytes) meant by vop_short.  */
   int length;
-  /* 0, or 1 if '@' is in addressing mode. */
+  /* 0, or 1 if '@' is in addressing mode.  */
   int at;
   /* From vop_nbytes: vax_operand_width (in bytes) */
   int nbytes;
   FLONUM_TYPE *floatP;
   LITTLENUM_TYPE literal_float[8];
-  /* Big enough for any floating point literal. */
+  /* Big enough for any floating point literal.  */
 
   vip (&v, instruction_string);
 
@@ -365,7 +463,7 @@ md_assemble (instruction_string)
    */
   if ((goofed = (*v.vit_error)) != 0)
     {
-      as_warn (_("Ignoring statement due to \"%s\""), v.vit_error);
+      as_fatal (_("Ignoring statement due to \"%s\""), v.vit_error);
     }
   /*
    * We need to use expression() and friends, which require us to diddle
@@ -384,18 +482,18 @@ md_assemble (instruction_string)
     {                          /* for each operand */
       if (operandP->vop_error)
        {
-         as_warn (_("Ignoring statement because \"%s\""), operandP->vop_error);
+         as_fatal (_("Aborting because statement has \"%s\""), operandP->vop_error);
          goofed = 1;
        }
       else
        {
          /* Statement has no syntax goofs: let's sniff the expression.  */
-         int can_be_short = 0; /* 1 if a bignum can be reduced to a short literal. */
+         int can_be_short = 0; /* 1 if a bignum can be reduced to a short literal.  */
 
          input_line_pointer = operandP->vop_expr_begin;
          c_save = operandP->vop_expr_end[1];
          operandP->vop_expr_end[1] = '\0';
-         /* If to_seg == SEG_PASS1, expression() will have set need_pass_2 = 1. */
+         /* If to_seg == SEG_PASS1, expression() will have set need_pass_2 = 1.  */
          *segP = expression (expP);
          switch (expP->X_op)
            {
@@ -431,11 +529,11 @@ md_assemble (instruction_string)
               * instruction operands.
               */
              need_pass_2 = 1;
-             as_warn (_("Can't relocate expression"));
+             as_fatal (_("Can't relocate expression"));
              break;
 
            case O_big:
-             /* Preserve the bits. */
+             /* Preserve the bits.  */
              if (expP->X_add_number > 0)
                {
                  bignum_copy (generic_bignum, expP->X_add_number,
@@ -498,20 +596,20 @@ md_assemble (instruction_string)
                      && operandP->vop_reg == 0xF
                      && (operandP->vop_mode & 0xE) == 0x8))
                {
-                 /* Saw a '#'. */
+                 /* Saw a '#'.  */
                  if (operandP->vop_short == ' ')
                    {
-                     /* We must chose S^ or I^. */
+                     /* We must chose S^ or I^.  */
                      if (expP->X_add_number > 0)
                        {
-                         /* Bignum: Short literal impossible. */
+                         /* Bignum: Short literal impossible.  */
                          operandP->vop_short = 'i';
                          operandP->vop_mode = 8;
-                         operandP->vop_reg = 0xF;      /* VAX PC. */
+                         operandP->vop_reg = 0xF;      /* VAX PC.  */
                        }
                      else
                        {
-                         /* Flonum: Try to do it. */
+                         /* Flonum: Try to do it.  */
                          if (can_be_short)
                            {
                              operandP->vop_short = 's';
@@ -527,17 +625,17 @@ md_assemble (instruction_string)
                              operandP->vop_reg = 0xF;  /* VAX PC */
                            }
                        }       /* bignum or flonum ? */
-                   }           /*  if #, but no S^ or I^ seen. */
-                 /* No more ' ' case: either 's' or 'i'. */
+                   }           /*  if #, but no S^ or I^ seen.  */
+                 /* No more ' ' case: either 's' or 'i'.  */
                  if (operandP->vop_short == 's')
                    {
-                     /* Wants to be a short literal. */
+                     /* Wants to be a short literal.  */
                      if (expP->X_add_number > 0)
                        {
                          as_warn (_("Bignum not permitted in short literal. Immediate mode assumed."));
                          operandP->vop_short = 'i';
                          operandP->vop_mode = 8;
-                         operandP->vop_reg = 0xF;      /* VAX PC. */
+                         operandP->vop_reg = 0xF;      /* VAX PC.  */
                        }
                      else
                        {
@@ -546,10 +644,10 @@ md_assemble (instruction_string)
                              as_warn (_("Can't do flonum short literal: immediate mode used."));
                              operandP->vop_short = 'i';
                              operandP->vop_mode = 8;
-                             operandP->vop_reg = 0xF;  /* VAX PC. */
+                             operandP->vop_reg = 0xF;  /* VAX PC.  */
                            }
                          else
-                           {   /* Encode short literal now. */
+                           {   /* Encode short literal now.  */
                              int temp = 0;
 
                              switch (-expP->X_add_number)
@@ -579,18 +677,18 @@ md_assemble (instruction_string)
                        }       /* flonum or bignum ? */
                    }
                  else
-                   {           /* I^# seen: set it up if float. */
+                   {           /* I^# seen: set it up if float.  */
                      if (expP->X_add_number < 0)
                        {
                          memcpy (floatP->low, literal_float, sizeof (literal_float));
                        }
-                   }           /* if S^# seen. */
+                   }           /* if S^# seen.  */
                }
              else
                {
                  as_warn (_("A bignum/flonum may not be a displacement: 0x%lx used"),
                           (expP->X_add_number = 0x80000000L));
-                 /* Chosen so luser gets the most offset bits to patch later. */
+                 /* Chosen so luser gets the most offset bits to patch later.  */
                }
              expP->X_add_number = floatP->low[0]
                | ((LITTLENUM_MASK & (floatP->low[1])) << LITTLENUM_NUMBER_OF_BITS);
@@ -609,7 +707,7 @@ md_assemble (instruction_string)
            }
          if (input_line_pointer != operandP->vop_expr_end + 1)
            {
-             as_warn ("Junk at end of expression \"%s\"", input_line_pointer);
+             as_fatal ("Junk at end of expression \"%s\"", input_line_pointer);
              goofed = 1;
            }
          operandP->vop_expr_end[1] = c_save;
@@ -623,12 +721,12 @@ md_assemble (instruction_string)
       return;
     }
 
-
-  /* Emit op-code. */
-  /* Remember where it is, in case we want to modify the op-code later. */
+  /* Emit op-code.  */
+  /* Remember where it is, in case we want to modify the op-code later.  */
   opcode_low_byteP = frag_more (v.vit_opcode_nbytes);
   memcpy (opcode_low_byteP, v.vit_opcode, v.vit_opcode_nbytes);
-  opcode_as_number = md_chars_to_number (opcode_as_chars = v.vit_opcode, 4);
+  opcode_as_chars = v.vit_opcode;
+  opcode_as_number = md_chars_to_number ((unsigned char *) opcode_as_chars, 4);
   for (operandP = v.vit_operand,
        expP = exp_of_operand,
        segP = seg_of_operand,
@@ -649,11 +747,17 @@ md_assemble (instruction_string)
          FRAG_APPEND_1_CHAR (0x40 + operandP->vop_ndx);
        }                       /* if(vop_ndx>=0) */
 
-      /* Here to make main operand frag(s). */
+      /* Here to make main operand frag(s).  */
       this_add_number = expP->X_add_number;
       this_add_symbol = expP->X_add_symbol;
       to_seg = *segP;
+#ifdef BFD_ASSEMBLER
+      is_undefined = (to_seg == undefined_section);
+      is_absolute = (to_seg == absolute_section);
+#else
       is_undefined = (to_seg == SEG_UNKNOWN);
+      is_absolute = (to_seg == SEG_ABSOLUTE);
+#endif
       at = operandP->vop_mode & 1;
       length = (operandP->vop_short == 'b'
                ? 1 : (operandP->vop_short == 'w'
@@ -664,7 +768,7 @@ md_assemble (instruction_string)
        {
          if (to_seg == now_seg || is_undefined)
            {
-             /* If is_undefined, then it might BECOME now_seg. */
+             /* If is_undefined, then it might BECOME now_seg.  */
              if (nbytes)
                {
                  p = frag_more (nbytes);
@@ -722,16 +826,20 @@ md_assemble (instruction_string)
              /*
               * --- SEG FLOAT MAY APPEAR HERE ----
               */
-             if (to_seg == SEG_ABSOLUTE)
+             if (is_absolute)
                {
                  if (nbytes)
                    {
                      know (!(opcode_as_number & VIT_OPCODE_SYNTHETIC));
                      p = frag_more (nbytes);
-                     /* Conventional relocation. */
-                     fix_new (frag_now, p - frag_now->fr_literal,
-                              nbytes, &abs_symbol, this_add_number,
-                              1, NO_RELOC);
+                     /* Conventional relocation.  */
+                     fix_new (frag_now, p - frag_now->fr_literal, nbytes,
+#ifdef BFD_ASSEMBLER
+                              section_symbol (absolute_section),
+#else
+                              &abs_symbol,
+#endif
+                              this_add_number, 1, NO_RELOC);
                    }
                  else
                    {
@@ -744,9 +852,9 @@ md_assemble (instruction_string)
                              *opcode_low_byteP = opcode_as_chars[0] + VAX_WIDEN_LONG;
                              know (opcode_as_chars[1] == 0);
                              p = frag_more (5);
-                             p[0] = VAX_ABSOLUTE_MODE; /* @#... */
+                             p[0] = VAX_ABSOLUTE_MODE; /* @#...  */
                              md_number_to_chars (p + 1, this_add_number, 4);
-                             /* Now (eg) JMP @#foo or JSB @#foo. */
+                             /* Now (eg) JMP @#foo or JSB @#foo.  */
                            }
                          else
                            {
@@ -758,7 +866,7 @@ md_assemble (instruction_string)
                                  p[2] = VAX_BRB;
                                  p[3] = 6;
                                  p[4] = VAX_JMP;
-                                 p[5] = VAX_ABSOLUTE_MODE;     /* @#... */
+                                 p[5] = VAX_ABSOLUTE_MODE;     /* @#...  */
                                  md_number_to_chars (p + 6, this_add_number, 4);
                                  /*
                                   * Now (eg)   ACBx    1f
@@ -775,7 +883,7 @@ md_assemble (instruction_string)
                                  p[1] = VAX_BRB;
                                  p[2] = 6;
                                  p[3] = VAX_JMP;
-                                 p[4] = VAX_PC_RELATIVE_MODE + 1;      /* @#... */
+                                  p[4] = VAX_ABSOLUTE_MODE;     /* @#...  */
                                  md_number_to_chars (p + 5, this_add_number, 4);
                                  /*
                                   * Now (eg)   xOBxxx  1f
@@ -791,11 +899,11 @@ md_assemble (instruction_string)
                          /* b<cond> */
                          *opcode_low_byteP ^= 1;
                          /* To reverse the condition in a VAX branch,
-                            complement the lowest order bit. */
+                            complement the lowest order bit.  */
                          p = frag_more (7);
                          p[0] = 6;
                          p[1] = VAX_JMP;
-                         p[2] = VAX_ABSOLUTE_MODE;     /* @#... */
+                         p[2] = VAX_ABSOLUTE_MODE;     /* @#...  */
                          md_number_to_chars (p + 3, this_add_number, 4);
                          /*
                           * Now (eg)   BLEQ    1f
@@ -807,15 +915,19 @@ md_assemble (instruction_string)
                }
              else
                {
-                 /* to_seg != now_seg && to_seg != SEG_UNKNOWN && to_Seg != SEG_ABSOLUTE */
+                 /* to_seg != now_seg && !is_undefinfed && !is_absolute */
                  if (nbytes > 0)
                    {
-                     /* Pc-relative. Conventional relocation. */
+                     /* Pc-relative. Conventional relocation.  */
                      know (!(opcode_as_number & VIT_OPCODE_SYNTHETIC));
                      p = frag_more (nbytes);
-                     fix_new (frag_now, p - frag_now->fr_literal,
-                              nbytes, &abs_symbol, this_add_number,
-                              1, NO_RELOC);
+                     fix_new (frag_now, p - frag_now->fr_literal, nbytes,
+#ifdef BFD_ASSEMBLER
+                              section_symbol (absolute_section),
+#else
+                              &abs_symbol,
+#endif
+                              this_add_number, 1, NO_RELOC);
                    }
                  else
                    {
@@ -833,7 +945,7 @@ md_assemble (instruction_string)
                                       p + 1 - frag_now->fr_literal, 4,
                                       this_add_symbol,
                                       this_add_number, 1, NO_RELOC);
-                             /* Now eg JMP foo or JSB foo. */
+                             /* Now eg JMP foo or JSB foo.  */
                            }
                          else
                            {
@@ -882,7 +994,7 @@ md_assemble (instruction_string)
                      else
                        {
                          know (operandP->vop_width == VAX_WIDTH_CONDITIONAL_JUMP);
-                         *opcode_low_byteP ^= 1;       /* Reverse branch condition. */
+                         *opcode_low_byteP ^= 1;       /* Reverse branch condition.  */
                          p = frag_more (7);
                          p[0] = 6;
                          p[1] = VAX_JMP;
@@ -897,8 +1009,8 @@ md_assemble (instruction_string)
        }
       else
        {
-         know (operandP->vop_access != 'b');   /* So it is ordinary operand. */
-         know (operandP->vop_access != ' ');   /* ' ' target-independent: elsewhere. */
+         know (operandP->vop_access != 'b');   /* So it is ordinary operand.  */
+         know (operandP->vop_access != ' ');   /* ' ' target-independent: elsewhere.  */
          know (operandP->vop_access == 'a'
                || operandP->vop_access == 'm'
                || operandP->vop_access == 'r'
@@ -906,7 +1018,7 @@ md_assemble (instruction_string)
                || operandP->vop_access == 'w');
          if (operandP->vop_short == 's')
            {
-             if (to_seg == SEG_ABSOLUTE)
+             if (is_absolute)
                {
                  if (this_add_number >= 64)
                    {
@@ -929,10 +1041,10 @@ md_assemble (instruction_string)
          if (operandP->vop_reg >= 0 && (operandP->vop_mode < 8
                  || (operandP->vop_reg != 0xF && operandP->vop_mode < 10)))
            {
-             /* One byte operand. */
+             /* One byte operand.  */
              know (operandP->vop_mode > 3);
              FRAG_APPEND_1_CHAR (operandP->vop_mode << 4 | operandP->vop_reg);
-             /* All 1-bytes except S^# happen here. */
+             /* All 1-bytes except S^# happen here.  */
            }
          else
            {
@@ -945,8 +1057,14 @@ md_assemble (instruction_string)
                      if (length == 0)
                        {
                          know (operandP->vop_short == ' ');
+                         length_code = STATE_BYTE;
+#ifdef OBJ_ELF
+                         if (S_IS_EXTERNAL (this_add_symbol)
+                             || S_IS_WEAK (this_add_symbol))
+                           length_code = STATE_UNDF;
+#endif
                          p = frag_var (rs_machine_dependent, 10, 2,
-                              ENCODE_RELAX (STATE_PC_RELATIVE, STATE_BYTE),
+                              ENCODE_RELAX (STATE_PC_RELATIVE, length_code),
                                        this_add_symbol, this_add_number,
                                        opcode_low_byteP);
                          know (operandP->vop_mode == 10 + at);
@@ -954,7 +1072,7 @@ md_assemble (instruction_string)
                          /* At is the only context we need to carry
                             to other side of relax() process.  Must
                             be in the correct bit position of VAX
-                            operand spec. byte. */
+                            operand spec. byte.  */
                        }
                      else
                        {
@@ -971,10 +1089,10 @@ md_assemble (instruction_string)
                    {           /* to_seg != now_seg */
                      if (this_add_symbol == NULL)
                        {
-                         know (to_seg == SEG_ABSOLUTE);
-                         /* Do @#foo: simpler relocation than foo-.(pc) anyway. */
+                         know (is_absolute);
+                         /* Do @#foo: simpler relocation than foo-.(pc) anyway.  */
                          p = frag_more (5);
-                         p[0] = VAX_ABSOLUTE_MODE;     /* @#... */
+                         p[0] = VAX_ABSOLUTE_MODE;     /* @#...  */
                          md_number_to_chars (p + 1, this_add_number, 4);
                          if (length && length != 4)
                            {
@@ -986,17 +1104,29 @@ md_assemble (instruction_string)
                          /* {@}{q^}other_seg */
                          know ((length == 0 && operandP->vop_short == ' ')
                             || (length > 0 && operandP->vop_short != ' '));
-                         if (is_undefined)
+                         if (is_undefined
+#ifdef OBJ_ELF
+                             || S_IS_WEAK(this_add_symbol)
+                             || S_IS_EXTERNAL(this_add_symbol)
+#endif
+                             )
                            {
+                             switch (length)
+                               {
+                               default: length_code = STATE_UNDF; break;
+                               case 1: length_code = STATE_BYTE; break;
+                               case 2: length_code = STATE_WORD; break;
+                               case 4: length_code = STATE_LONG; break;
+                               }
                              /*
                               * We have a SEG_UNKNOWN symbol. It might
                               * turn out to be in the same segment as
                               * the instruction, permitting relaxation.
                               */
                              p = frag_var (rs_machine_dependent, 5, 2,
-                              ENCODE_RELAX (STATE_PC_RELATIVE, STATE_UNDF),
+                              ENCODE_RELAX (STATE_PC_RELATIVE, length_code),
                                            this_add_symbol, this_add_number,
-                                           0);
+                                           opcode_low_byteP);
                              p[0] = at << 4;
                            }
                          else
@@ -1004,7 +1134,7 @@ md_assemble (instruction_string)
                              if (length == 0)
                                {
                                  know (operandP->vop_short == ' ');
-                                 length = 4;   /* Longest possible. */
+                                 length = 4;   /* Longest possible.  */
                                }
                              p = frag_more (length + 1);
                              p[0] = 0xF | ((at + "?\12\14?\16"[length]) << 4);
@@ -1034,8 +1164,8 @@ md_assemble (instruction_string)
                             one case.  */
                        }
                      if (length == 0
-                         && to_seg == SEG_ABSOLUTE && (expP->X_op != O_big)
-                         && operandP->vop_mode == 8    /* No '@'. */
+                         && is_absolute && (expP->X_op != O_big)
+                         && operandP->vop_mode == 8    /* No '@'.  */
                          && this_add_number < 64)
                        {
                          operandP->vop_short = 's';
@@ -1046,25 +1176,31 @@ md_assemble (instruction_string)
                        }
                      else
                        {
-                         /* I^#... */
+                         /* I^#...  */
                          know (nbytes);
                          p = frag_more (nbytes + 1);
                          know (operandP->vop_reg == 0xF);
+#ifdef OBJ_ELF
+                         if (flag_want_pic && operandP->vop_mode == 8
+                               && this_add_symbol != NULL)
+                           {
+                             as_warn (_("Symbol used as immediate operand in PIC mode."));
+                           }
+#endif
                          p[0] = (operandP->vop_mode << 4) | 0xF;
-                         if ((to_seg == SEG_ABSOLUTE) && (expP->X_op != O_big))
+                         if ((is_absolute) && (expP->X_op != O_big))
                            {
-                             /*
-                              * If nbytes > 4, then we are scrod. We
-                              * don't know if the high order bytes
-                              * are to be 0xFF or 0x00.  BSD4.2 & RMS
-                              * say use 0x00. OK --- but this
-                              * assembler needs ANOTHER rewrite to
-                              * cope properly with this bug. */
-                             md_number_to_chars (p + 1, this_add_number, min (4, nbytes));
-                             if (nbytes > 4)
-                               {
-                                 memset (p + 5, '\0', nbytes - 4);
-                               }
+                             /* If nbytes > 4, then we are scrod. We
+                                don't know if the high order bytes
+                                are to be 0xFF or 0x00.  BSD4.2 & RMS
+                                say use 0x00. OK --- but this
+                                assembler needs ANOTHER rewrite to
+                                cope properly with this bug.  */
+                             md_number_to_chars (p + 1, this_add_number,
+                                                 min (sizeof (valueT),
+                                                      (size_t) nbytes));
+                             if ((size_t) nbytes > sizeof (valueT))
+                               memset (p + 5, '\0', nbytes - sizeof (valueT));
                            }
                          else
                            {
@@ -1074,7 +1210,7 @@ md_assemble (instruction_string)
                                   * Problem here is to get the bytes
                                   * in the right order.  We stored
                                   * our constant as LITTLENUMs, not
-                                  * bytes. */
+                                  * bytes.  */
                                  LITTLENUM_TYPE *lP;
 
                                  lP = floatP->low;
@@ -1106,7 +1242,7 @@ md_assemble (instruction_string)
                            || (length > 0 && operandP->vop_short != ' '));
                      if (length == 0)
                        {
-                         if (to_seg == SEG_ABSOLUTE)
+                         if (is_absolute)
                            {
                              long test;
 
@@ -1128,7 +1264,7 @@ md_assemble (instruction_string)
                      know (operandP->vop_reg >= 0);
                      p[0] = operandP->vop_reg
                        | ((at | "?\12\14?\16"[length]) << 4);
-                     if (to_seg == SEG_ABSOLUTE)
+                     if (is_absolute)
                        {
                          md_number_to_chars (p + 1, this_add_number, length);
                        }
@@ -1145,127 +1281,155 @@ md_assemble (instruction_string)
     }                          /* for(operandP) */
 }                              /* vax_assemble() */
 \f
-/*
- *                     md_estimate_size_before_relax()
- *
- * Called just before relax().
- * Any symbol that is now undefined will not become defined.
- * Return the correct fr_subtype in the frag.
- * Return the initial "guess for fr_var" to caller.
- * The guess for fr_var is ACTUALLY the growth beyond fr_fix.
- * Whatever we do to grow fr_fix or fr_var contributes to our returned value.
- * Although it may not be explicit in the frag, pretend fr_var starts with a
- * 0 value.
- */
+/* md_estimate_size_before_relax(), called just before relax().
+   Any symbol that is now undefined will not become defined.
+   Return the correct fr_subtype in the frag and the growth beyond
+   fr_fix.  */
 int
 md_estimate_size_before_relax (fragP, segment)
      fragS *fragP;
      segT segment;
 {
-  char *p;
-  int old_fr_fix;
-
-  old_fr_fix = fragP->fr_fix;
-  switch (fragP->fr_subtype)
+  if (RELAX_LENGTH (fragP->fr_subtype) == STATE_UNDF)
     {
-    case ENCODE_RELAX (STATE_PC_RELATIVE, STATE_UNDF):
-      if (S_GET_SEGMENT (fragP->fr_symbol) == segment)
-       {                       /* A relaxable case. */
-         fragP->fr_subtype = ENCODE_RELAX (STATE_PC_RELATIVE, STATE_BYTE);
-       }
-      else
+      if (S_GET_SEGMENT (fragP->fr_symbol) != segment
+#ifdef OBJ_ELF
+         || S_IS_WEAK (fragP->fr_symbol)
+         || S_IS_EXTERNAL (fragP->fr_symbol)
+#endif
+         )
        {
-         p = fragP->fr_literal + old_fr_fix;
-         p[0] |= VAX_PC_RELATIVE_MODE; /* Preserve @ bit. */
-         fragP->fr_fix += 1 + 4;
-         fix_new (fragP, old_fr_fix + 1, 4, fragP->fr_symbol,
-                  fragP->fr_offset, 1, NO_RELOC);
-         frag_wane (fragP);
-       }
-      break;
+         /* Non-relaxable cases.  */
+         int reloc_type = NO_RELOC;
+         char *p;
+         int old_fr_fix;
 
-    case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_UNDF):
-      if (S_GET_SEGMENT (fragP->fr_symbol) == segment)
-       {
-         fragP->fr_subtype = ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_BYTE);
-       }
-      else
-       {
+         old_fr_fix = fragP->fr_fix;
          p = fragP->fr_literal + old_fr_fix;
-         *fragP->fr_opcode ^= 1;       /* Reverse sense of branch. */
-         p[0] = 6;
-         p[1] = VAX_JMP;
-         p[2] = VAX_PC_RELATIVE_MODE;  /* ...(PC) */
-         fragP->fr_fix += 1 + 1 + 1 + 4;
-         fix_new (fragP, old_fr_fix + 3, 4, fragP->fr_symbol,
-                  fragP->fr_offset, 1, NO_RELOC);
-         frag_wane (fragP);
-       }
-      break;
+#ifdef OBJ_ELF
+         /* If this is to an undefined symbol, then if it's an indirect
+            reference indicate that is can mutated into a GLOB_DAT or
+            JUMP_SLOT by the loader.  We restrict ourselves to no offset
+            due to a limitation in the NetBSD linker.  */
+
+         if (GOT_symbol == NULL)
+           GOT_symbol = symbol_find (GLOBAL_OFFSET_TABLE_NAME);
+         if (PLT_symbol == NULL)
+           PLT_symbol = symbol_find (PROCEDURE_LINKAGE_TABLE_NAME);
+         if ((GOT_symbol == NULL || fragP->fr_symbol != GOT_symbol)
+             && (PLT_symbol == NULL || fragP->fr_symbol != PLT_symbol)
+             && fragP->fr_symbol != NULL
+             && flag_want_pic
+             && (!S_IS_DEFINED (fragP->fr_symbol)
+                 || S_IS_WEAK (fragP->fr_symbol)
+                 || S_IS_EXTERNAL (fragP->fr_symbol)))
+           {
+             if (p[0] & 0x10)
+               {
+                 if (flag_want_pic)
+                   as_fatal ("PIC reference to %s is indirect.\n",
+                             S_GET_NAME (fragP->fr_symbol));
+               }
+             else
+               {
+                 if (((unsigned char *) fragP->fr_opcode)[0] == VAX_CALLS
+                     || ((unsigned char *) fragP->fr_opcode)[0] == VAX_CALLG
+                     || ((unsigned char *) fragP->fr_opcode)[0] == VAX_JSB
+                     || ((unsigned char *) fragP->fr_opcode)[0] == VAX_JMP
+                     || S_IS_FUNCTION (fragP->fr_symbol))
+                   reloc_type = BFD_RELOC_32_PLT_PCREL;
+                 else
+                   reloc_type = BFD_RELOC_32_GOT_PCREL;
+               }
+           }
+#endif
+         switch (RELAX_STATE (fragP->fr_subtype))
+           {
+           case STATE_PC_RELATIVE:
+             p[0] |= VAX_PC_RELATIVE_MODE;     /* Preserve @ bit.  */
+             fragP->fr_fix += 1 + 4;
+             fix_new (fragP, old_fr_fix + 1, 4, fragP->fr_symbol,
+                      fragP->fr_offset, 1, reloc_type);
+             break;
 
-    case ENCODE_RELAX (STATE_COMPLEX_BRANCH, STATE_UNDF):
-      if (S_GET_SEGMENT (fragP->fr_symbol) == segment)
-       {
-         fragP->fr_subtype = ENCODE_RELAX (STATE_COMPLEX_BRANCH, STATE_WORD);
-       }
-      else
-       {
-         p = fragP->fr_literal + old_fr_fix;
-         p[0] = 2;
-         p[1] = 0;
-         p[2] = VAX_BRB;
-         p[3] = 6;
-         p[4] = VAX_JMP;
-         p[5] = VAX_PC_RELATIVE_MODE;  /* ...(pc) */
-         fragP->fr_fix += 2 + 2 + 1 + 1 + 4;
-         fix_new (fragP, old_fr_fix + 6, 4, fragP->fr_symbol,
-                  fragP->fr_offset, 1, NO_RELOC);
-         frag_wane (fragP);
-       }
-      break;
+           case STATE_CONDITIONAL_BRANCH:
+             *fragP->fr_opcode ^= 1;           /* Reverse sense of branch.  */
+             p[0] = 6;
+             p[1] = VAX_JMP;
+             p[2] = VAX_PC_RELATIVE_MODE;      /* ...(PC) */
+             fragP->fr_fix += 1 + 1 + 1 + 4;
+             fix_new (fragP, old_fr_fix + 3, 4, fragP->fr_symbol,
+                      fragP->fr_offset, 1, NO_RELOC);
+             break;
 
-    case ENCODE_RELAX (STATE_COMPLEX_HOP, STATE_UNDF):
-      if (S_GET_SEGMENT (fragP->fr_symbol) == segment)
-       {
-         fragP->fr_subtype = ENCODE_RELAX (STATE_COMPLEX_HOP, STATE_BYTE);
-       }
-      else
-       {
-         p = fragP->fr_literal + old_fr_fix;
-         p[0] = 2;
-         p[1] = VAX_BRB;
-         p[2] = 6;
-         p[3] = VAX_JMP;
-         p[4] = VAX_PC_RELATIVE_MODE;  /* ...(pc) */
-         fragP->fr_fix += 1 + 2 + 1 + 1 + 4;
-         fix_new (fragP, old_fr_fix + 5, 4, fragP->fr_symbol,
-                  fragP->fr_offset, 1, NO_RELOC);
+           case STATE_COMPLEX_BRANCH:
+             p[0] = 2;
+             p[1] = 0;
+             p[2] = VAX_BRB;
+             p[3] = 6;
+             p[4] = VAX_JMP;
+             p[5] = VAX_PC_RELATIVE_MODE;      /* ...(pc) */
+             fragP->fr_fix += 2 + 2 + 1 + 1 + 4;
+             fix_new (fragP, old_fr_fix + 6, 4, fragP->fr_symbol,
+                      fragP->fr_offset, 1, NO_RELOC);
+             break;
+
+           case STATE_COMPLEX_HOP:
+             p[0] = 2;
+             p[1] = VAX_BRB;
+             p[2] = 6;
+             p[3] = VAX_JMP;
+             p[4] = VAX_PC_RELATIVE_MODE;      /* ...(pc) */
+             fragP->fr_fix += 1 + 2 + 1 + 1 + 4;
+             fix_new (fragP, old_fr_fix + 5, 4, fragP->fr_symbol,
+                      fragP->fr_offset, 1, NO_RELOC);
+             break;
+
+           case STATE_ALWAYS_BRANCH:
+             *fragP->fr_opcode += VAX_WIDEN_LONG;
+             p[0] = VAX_PC_RELATIVE_MODE;      /* ...(PC) */
+             fragP->fr_fix += 1 + 4;
+             fix_new (fragP, old_fr_fix + 1, 4, fragP->fr_symbol,
+                      fragP->fr_offset, 1, NO_RELOC);
+             break;
+
+           default:
+             abort ();
+           }
          frag_wane (fragP);
+
+         /* Return the growth in the fixed part of the frag.  */
+         return fragP->fr_fix - old_fr_fix;
        }
-      break;
 
-    case ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_UNDF):
-      if (S_GET_SEGMENT (fragP->fr_symbol) == segment)
+      /* Relaxable cases.  Set up the initial guess for the variable
+        part of the frag.  */
+      switch (RELAX_STATE (fragP->fr_subtype))
        {
+       case STATE_PC_RELATIVE:
+         fragP->fr_subtype = ENCODE_RELAX (STATE_PC_RELATIVE, STATE_BYTE);
+         break;
+       case STATE_CONDITIONAL_BRANCH:
+         fragP->fr_subtype = ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_BYTE);
+         break;
+       case STATE_COMPLEX_BRANCH:
+         fragP->fr_subtype = ENCODE_RELAX (STATE_COMPLEX_BRANCH, STATE_WORD);
+         break;
+       case STATE_COMPLEX_HOP:
+         fragP->fr_subtype = ENCODE_RELAX (STATE_COMPLEX_HOP, STATE_BYTE);
+         break;
+       case STATE_ALWAYS_BRANCH:
          fragP->fr_subtype = ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_BYTE);
+         break;
        }
-      else
-       {
-         p = fragP->fr_literal + old_fr_fix;
-         *fragP->fr_opcode += VAX_WIDEN_LONG;
-         p[0] = VAX_PC_RELATIVE_MODE;  /* ...(PC) */
-         fragP->fr_fix += 1 + 4;
-         fix_new (fragP, old_fr_fix + 1, 4, fragP->fr_symbol,
-                  fragP->fr_offset, 1, NO_RELOC);
-         frag_wane (fragP);
-       }
-      break;
-
-    default:
-      break;
     }
-  return (fragP->fr_var + fragP->fr_fix - old_fr_fix);
-}                              /* md_estimate_size_before_relax() */
+
+  if (fragP->fr_subtype >= sizeof (md_relax_table) / sizeof (md_relax_table[0]))
+    abort ();
+
+  /* Return the size of the variable part of the frag.  */
+  return md_relax_table[fragP->fr_subtype].rlx_length;
+}
 \f
 /*
  *                     md_convert_frag();
@@ -1278,101 +1442,110 @@ md_estimate_size_before_relax (fragP, segment)
  * Out:        Any fixSs and constants are set up.
  *     Caller will turn frag into a ".space 0".
  */
+#ifdef BFD_ASSEMBLER
 void
 md_convert_frag (headers, seg, fragP)
-     object_headers *headers;
-     segT seg;
+     bfd *headers ATTRIBUTE_UNUSED;
+     segT seg ATTRIBUTE_UNUSED;
+     fragS *fragP;
+#else
+void
+md_convert_frag (headers, seg, fragP)
+     object_headers *headers ATTRIBUTE_UNUSED;
+     segT seg ATTRIBUTE_UNUSED;
      fragS *fragP;
+#endif
 {
-  char *addressP;              /* -> _var to change. */
-  char *opcodeP;               /* -> opcode char(s) to change. */
-  short int length_code;       /* 2=long 1=word 0=byte */
-  short int extension = 0;     /* Size of relaxed address. */
-  /* Added to fr_fix: incl. ALL var chars. */
+  char *addressP;              /* -> _var to change.  */
+  char *opcodeP;               /* -> opcode char(s) to change.  */
+  short int extension = 0;     /* Size of relaxed address.  */
+  /* Added to fr_fix: incl. ALL var chars.  */
   symbolS *symbolP;
   long where;
-  long address_of_var;
-  /* Where, in file space, is _var of *fragP? */
-  long target_address = 0;
-  /* Where, in file space, does addr point? */
 
   know (fragP->fr_type == rs_machine_dependent);
-  length_code = fragP->fr_subtype & 3; /* depends on ENCODE_RELAX() */
-  know (length_code >= 0 && length_code < 3);
   where = fragP->fr_fix;
   addressP = fragP->fr_literal + where;
   opcodeP = fragP->fr_opcode;
   symbolP = fragP->fr_symbol;
   know (symbolP);
-  target_address = S_GET_VALUE (symbolP) + fragP->fr_offset;
-  address_of_var = fragP->fr_address + where;
 
   switch (fragP->fr_subtype)
     {
 
     case ENCODE_RELAX (STATE_PC_RELATIVE, STATE_BYTE):
-      know (*addressP == 0 || *addressP == 0x10);      /* '@' bit. */
+      know (*addressP == 0 || *addressP == 0x10);      /* '@' bit.  */
       addressP[0] |= 0xAF;     /* Byte displacement. */
-      addressP[1] = target_address - (address_of_var + 2);
+      fix_new (fragP, fragP->fr_fix + 1, 1, fragP->fr_symbol,
+              fragP->fr_offset, 1, NO_RELOC);
       extension = 2;
       break;
 
     case ENCODE_RELAX (STATE_PC_RELATIVE, STATE_WORD):
-      know (*addressP == 0 || *addressP == 0x10);      /* '@' bit. */
+      know (*addressP == 0 || *addressP == 0x10);      /* '@' bit.  */
       addressP[0] |= 0xCF;     /* Word displacement. */
-      md_number_to_chars (addressP + 1, target_address - (address_of_var + 3), 2);
+      fix_new (fragP, fragP->fr_fix + 1, 2, fragP->fr_symbol,
+              fragP->fr_offset, 1, NO_RELOC);
       extension = 3;
       break;
 
     case ENCODE_RELAX (STATE_PC_RELATIVE, STATE_LONG):
-      know (*addressP == 0 || *addressP == 0x10);      /* '@' bit. */
+      know (*addressP == 0 || *addressP == 0x10);      /* '@' bit.  */
       addressP[0] |= 0xEF;     /* Long word displacement. */
-      md_number_to_chars (addressP + 1, target_address - (address_of_var + 5), 4);
+      fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
+              fragP->fr_offset, 1, NO_RELOC);
       extension = 5;
       break;
 
     case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_BYTE):
-      addressP[0] = target_address - (address_of_var + 1);
+      fix_new (fragP, fragP->fr_fix, 1, fragP->fr_symbol,
+              fragP->fr_offset, 1, NO_RELOC);
       extension = 1;
       break;
 
     case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_WORD):
-      opcodeP[0] ^= 1;         /* Reverse sense of test. */
+      opcodeP[0] ^= 1;         /* Reverse sense of test.  */
       addressP[0] = 3;
-      addressP[1] = VAX_BRB + VAX_WIDEN_WORD;
-      md_number_to_chars (addressP + 2, target_address - (address_of_var + 4), 2);
+      addressP[1] = VAX_BRW;
+      fix_new (fragP, fragP->fr_fix + 2, 2, fragP->fr_symbol,
+              fragP->fr_offset, 1, NO_RELOC);
       extension = 4;
       break;
 
     case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_LONG):
-      opcodeP[0] ^= 1;         /* Reverse sense of test. */
+      opcodeP[0] ^= 1;         /* Reverse sense of test.  */
       addressP[0] = 6;
       addressP[1] = VAX_JMP;
       addressP[2] = VAX_PC_RELATIVE_MODE;
-      md_number_to_chars (addressP + 3, target_address, 4);
+      fix_new (fragP, fragP->fr_fix + 3, 4, fragP->fr_symbol,
+              fragP->fr_offset, 1, NO_RELOC);
       extension = 7;
       break;
 
     case ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_BYTE):
-      addressP[0] = target_address - (address_of_var + 1);
+      fix_new (fragP, fragP->fr_fix, 1, fragP->fr_symbol,
+              fragP->fr_offset, 1, NO_RELOC);
       extension = 1;
       break;
 
     case ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_WORD):
       opcodeP[0] += VAX_WIDEN_WORD;    /* brb -> brw, bsbb -> bsbw */
-      md_number_to_chars (addressP, target_address - (address_of_var + 2), 2);
+      fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
+              1, NO_RELOC);
       extension = 2;
       break;
 
     case ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_LONG):
       opcodeP[0] += VAX_WIDEN_LONG;    /* brb -> jmp, bsbb -> jsb */
       addressP[0] = VAX_PC_RELATIVE_MODE;
-      md_number_to_chars (addressP + 1, target_address - (address_of_var + 5), 4);
+      fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
+              fragP->fr_offset, 1, NO_RELOC);
       extension = 5;
       break;
 
     case ENCODE_RELAX (STATE_COMPLEX_BRANCH, STATE_WORD):
-      md_number_to_chars (addressP, target_address - (address_of_var + 2), 2);
+      fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
+              fragP->fr_offset, 1, NO_RELOC);
       extension = 2;
       break;
 
@@ -1383,12 +1556,14 @@ md_convert_frag (headers, seg, fragP)
       addressP[3] = 6;
       addressP[4] = VAX_JMP;
       addressP[5] = VAX_PC_RELATIVE_MODE;
-      md_number_to_chars (addressP + 6, target_address, 4);
+      fix_new (fragP, fragP->fr_fix + 6, 4, fragP->fr_symbol,
+              fragP->fr_offset, 1, NO_RELOC);
       extension = 10;
       break;
 
     case ENCODE_RELAX (STATE_COMPLEX_HOP, STATE_BYTE):
-      addressP[0] = target_address - (address_of_var + 1);
+      fix_new (fragP, fragP->fr_fix, 1, fragP->fr_symbol,
+              fragP->fr_offset, 1, NO_RELOC);
       extension = 1;
       break;
 
@@ -1397,7 +1572,8 @@ md_convert_frag (headers, seg, fragP)
       addressP[1] = VAX_BRB;
       addressP[2] = 3;
       addressP[3] = VAX_BRW;
-      md_number_to_chars (addressP + 4, target_address - (address_of_var + 6), 2);
+      fix_new (fragP, fragP->fr_fix + 4, 2, fragP->fr_symbol,
+              fragP->fr_offset, 1, NO_RELOC);
       extension = 6;
       break;
 
@@ -1407,7 +1583,8 @@ md_convert_frag (headers, seg, fragP)
       addressP[2] = 6;
       addressP[3] = VAX_JMP;
       addressP[4] = VAX_PC_RELATIVE_MODE;
-      md_number_to_chars (addressP + 5, target_address, 4);
+      fix_new (fragP, fragP->fr_fix + 5, 4, fragP->fr_symbol,
+              fragP->fr_offset, 1, NO_RELOC);
       extension = 9;
       break;
 
@@ -1423,7 +1600,7 @@ md_convert_frag (headers, seg, fragP)
    On vax: first 4 bytes are normal unsigned long, next three bytes
    are symbolnum, least sig. byte first.  Last byte is broken up with
    the upper nibble as nuthin, bit 3 as extern, bits 2 & 1 as length, and
-   bit 0 as pcrel. */
+   bit 0 as pcrel.  */
 #ifdef comment
 void
 md_ri_to_chars (the_bytes, ri)
@@ -1442,7 +1619,9 @@ md_ri_to_chars (the_bytes, ri)
 
 #endif /* comment */
 
-void 
+#ifdef OBJ_AOUT
+#ifndef BFD_ASSEMBLER
+void
 tc_aout_fix_to_chars (where, fixP, segment_address_in_file)
      char *where;
      fixS *fixP;
@@ -1473,6 +1652,8 @@ tc_aout_fix_to_chars (where, fixP, segment_address_in_file)
              | ((nbytes_r_length[fixP->fx_size] << 1) & 0x06)
              | (((fixP->fx_pcrel << 0) & 0x01) & 0x0f));
 }
+#endif /* !BFD_ASSEMBLER */
+#endif /* OBJ_AOUT */
 
 /*
  *       BUGS, GRIPES,  APOLOGIA, etc.
@@ -1556,10 +1737,10 @@ static const short int vax_operand_width_size[256] =
   0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
   0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
   0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
-  0, 0, 1, 0, 8, 0, 4, 8, 16, 0, 0, 0, 4, 0, 0,16,     /* ..b.d.fgh...l..o */
-  0, 8, 0, 0, 0, 0, 0, 2,  0, 0, 0, 0, 0, 0, 0, 0,     /* .q.....w........ */
-  0, 0, 1, 0, 8, 0, 4, 8, 16, 0, 0, 0, 4, 0, 0,16,     /* ..b.d.fgh...l..o */
-  0, 8, 0, 0, 0, 0, 0, 2,  0, 0, 0, 0, 0, 0, 0, 0,     /* .q.....w........ */
+  0, 0, 1, 0, 8, 0, 4, 8, 16, 0, 0, 0, 4, 0, 0,16,     /* ..b.d.fgh...l..o  */
+  0, 8, 0, 0, 0, 0, 0, 2,  0, 0, 0, 0, 0, 0, 0, 0,     /* .q.....w........  */
+  0, 0, 1, 0, 8, 0, 4, 8, 16, 0, 0, 0, 4, 0, 0,16,     /* ..b.d.fgh...l..o  */
+  0, 8, 0, 0, 0, 0, 0, 2,  0, 0, 0, 0, 0, 0, 0, 0,     /* .q.....w........  */
   0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
   0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
   0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
@@ -1666,8 +1847,6 @@ static const struct vot
   {"jbcs",     {"rlvbb?", 0x800000e3}},
   {"jbsc",     {"rlvbb?", 0x800000e4}},
   {"jbcc",     {"rlvbb?", 0x800000e5}},
-  {"jbssi",    {"rlvbb?", 0x800000e6}},
-  {"jbcci",    {"rlvbb?", 0x800000e7}},
   {"jlbs",     {"rlb?", 0x800000e8}},
   {"jlbc",     {"rlb?", 0x800000e9}},
 
@@ -1676,8 +1855,8 @@ static const struct vot
   {"jsobgeq",  {"mlb:", 0xC00000f4}},
   {"jsobgtr",  {"mlb:", 0xC00000f5}},
 
-/* CASEx has no branch addresses in our conception of it. */
-/* You should use ".word ..." statements after the "case ...". */
+/* CASEx has no branch addresses in our conception of it.  */
+/* You should use ".word ..." statements after the "case ...".  */
 
   {"", {"", 0}}                        /* empty is end sentinel */
 
@@ -1696,7 +1875,7 @@ static const struct vot
 
 static const char *
 vip_begin (synthetic_too, immediate, indirect, displen)
-     int synthetic_too;                /* 1 means include jXXX op-codes. */
+     int synthetic_too;                /* 1 means include jXXX op-codes.  */
      const char *immediate, *indirect, *displen;
 {
   const struct vot *vP;                /* scan votstrs */
@@ -1718,7 +1897,6 @@ vip_begin (synthetic_too, immediate, indirect, displen)
   return retval;
 }
 
-
 /*
  *                  v i p ( )
  *
@@ -1745,10 +1923,10 @@ vip_begin (synthetic_too, immediate, indirect, displen)
 
 static void
 vip (vitP, instring)
-     struct vit *vitP;         /* We build an exploded instruction here. */
-     char *instring;           /* Text of a vax instruction: we modify. */
+     struct vit *vitP;         /* We build an exploded instruction here.  */
+     char *instring;           /* Text of a vax instruction: we modify.  */
 {
-  /* How to bit-encode this opcode. */
+  /* How to bit-encode this opcode.  */
   struct vot_wot *vwP;
   /* 1/skip whitespace.2/scan vot_how */
   char *p;
@@ -1759,16 +1937,16 @@ vip (vitP, instring)
   struct vop *operandp;
   /* error over all operands */
   const char *alloperr;
-  /* Remember char, (we clobber it with '\0' temporarily). */
+  /* Remember char, (we clobber it with '\0' temporarily).  */
   char c;
-  /* Op-code of this instruction. */
+  /* Op-code of this instruction.  */
   vax_opcodeT oc;
 
   if (*instring == ' ')
-    ++instring;                        /* Skip leading whitespace. */
-  for (p = instring; *p && *p != ' '; p++);;   /* MUST end in end-of-string or exactly 1 space. */
-  /* Scanned up to end of operation-code. */
-  /* Operation-code is ended with whitespace. */
+    ++instring;                        /* Skip leading whitespace.  */
+  for (p = instring; *p && *p != ' '; p++);;   /* MUST end in end-of-string or exactly 1 space.  */
+  /* Scanned up to end of operation-code.  */
+  /* Operation-code is ended with whitespace.  */
   if (p - instring == 0)
     {
       vitP->vit_error = _("No operator");
@@ -1785,7 +1963,7 @@ vip (vitP, instring)
        * We trust instring points to an op-name, with no whitespace.
        */
       vwP = (struct vot_wot *) hash_find (op_hash, instring);
-      *p = c;                  /* Restore char after op-code. */
+      *p = c;                  /* Restore char after op-code.  */
       if (vwP == 0)
        {
          vitP->vit_error = _("Unknown operator");
@@ -1797,7 +1975,7 @@ vip (vitP, instring)
          /*
           * We found a match! So let's pick up as many operands as the
           * instruction wants, and even gripe if there are too many.
-          * We expect comma to seperate each operand.
+          * We expect comma to separate each operand.
           * We let instring track the text, while p tracks a part of the
           * struct vot.
           */
@@ -1808,7 +1986,7 @@ vip (vitP, instring)
           * we return 32 bits of opcode, including bucky bits, BUT
           * an opcode length is either 8 or 16 bits for vit_opcode_nbytes.
           */
-         oc = vwP->vot_code;   /* The op-code. */
+         oc = vwP->vot_code;   /* The op-code.  */
          vitP->vit_opcode_nbytes = (oc & 0xFF) >= 0xFD ? 2 : 1;
          md_number_to_chars (vitP->vit_opcode, oc, 4);
          count = 0;            /* no operands seen yet */
@@ -1837,7 +2015,7 @@ vip (vitP, instring)
                  operandp->vop_nbytes = vax_operand_width_size[(unsigned) howp[1]];
                  operandp->vop_access = howp[0];
                  vip_op (instring, operandp);
-                 *q = c;       /* Restore input text. */
+                 *q = c;       /* Restore input text.  */
                  if (operandp->vop_error)
                    alloperr = _("Bad operand");
                  instring = q + (c ? 1 : 0);   /* next operand (if any) */
@@ -1849,7 +2027,7 @@ vip (vitP, instring)
          if (!*alloperr)
            {
              if (*instring == ' ')
-               instring++;     /* Skip whitespace. */
+               instring++;     /* Skip whitespace.  */
              if (*instring)
                alloperr = _("Too many operands");
            }
@@ -1870,7 +2048,7 @@ char answer[100];         /* human types a line of vax assembler here */
 char *mybug;                   /* "" or an internal logic diagnostic */
 int mycount;                   /* number of operands */
 struct vop *myvop;             /* scan operands from myvit */
-int mysynth;                   /* 1 means want synthetic opcodes. */
+int mysynth;                   /* 1 means want synthetic opcodes.  */
 char my_immediate[200];
 char my_indirect[200];
 char my_displen[200];
@@ -1949,7 +2127,7 @@ main ()
 
 /* vax_reg_parse.c - convert a VAX register name to a number */
 
-/* Copyright (C) 1987 Free Software Foundation, Inc. A part of GNU. */
+/* Copyright (C) 1987 Free Software Foundation, Inc. A part of GNU.  */
 
 /*
  *          v a x _ r e g _ p a r s e ( )
@@ -1983,28 +2161,48 @@ main ()
  *
  */
 
-#include <ctype.h>
+#include "safe-ctype.h"
 #define AP (12)
 #define FP (13)
 #define SP (14)
 #define PC (15)
 \f
 int                            /* return -1 or 0:15 */
-vax_reg_parse (c1, c2, c3)     /* 3 chars of register name */
-     char c1, c2, c3;          /* c3 == 0 if 2-character reg name */
+vax_reg_parse (c1, c2, c3, c4) /* 3 chars of register name */
+     char c1, c2, c3, c4;      /* c3 == 0 if 2-character reg name */
 {
   int retval;          /* return -1:15 */
 
   retval = -1;
 
-  if (isupper (c1))
-    c1 = tolower (c1);
-  if (isupper (c2))
-    c2 = tolower (c2);
-  if (isdigit (c2) && c1 == 'r')
+#ifdef OBJ_ELF
+  if (c1 != '%')       /* register prefixes are mandatory for ELF */
+    return retval;
+  c1 = c2;
+  c2 = c3;
+  c3 = c4;
+#endif
+#ifdef OBJ_VMS
+  if (c4 != 0)         /* register prefixes are not allowed under VMS */
+    return retval;
+#endif
+#ifdef OBJ_AOUT
+  if (c1 == '%')       /* register prefixes are optional under a.out */
+    {
+      c1 = c2;
+      c2 = c3;
+      c3 = c4;
+    }
+  else if (c3 && c4)   /* can't be 4 characters long.  */
+    return retval;
+#endif
+
+  c1 = TOLOWER (c1);
+  c2 = TOLOWER (c2);
+  if (ISDIGIT (c2) && c1 == 'r')
     {
       retval = c2 - '0';
-      if (isdigit (c3))
+      if (ISDIGIT (c3))
        {
          retval = retval * 10 + c3 - '0';
          retval = (retval > 15) ? -1 : retval;
@@ -2066,7 +2264,7 @@ vax_reg_parse (c1, c2, c3)        /* 3 chars of register name */
  * There were a number of 'mismatched argument type' bugs to vip_op.
  * The most general solution is to typedef each (of many) arguments.
  * We used instead a typedef'd argument block. This is less modular
- * than using seperate return pointers for each result, but runs faster
+ * than using separate return pointers for each result, but runs faster
  * on most engines, and seems to keep programmers happy. It will have
  * to be done properly if we ever want to use vip_op as a general-purpose
  * module (it was designed to be).
@@ -2135,7 +2333,6 @@ vax_reg_parse (c1, c2, c3)        /* 3 chars of register name */
  * if the other outputs are to be taken seriously.
  */
 
-
 /*
  * Because this module is useful for both VMS and UN*X style assemblers
  * and because of the variety of UN*X assemblers we must recognise
@@ -2203,7 +2400,7 @@ vip_op_1 (bit, syms)
 }
 
 /* Can be called any time.  More arguments may appear in future.  */
-static void 
+static void
 vip_op_defaults (immediate, indirect, displen)
      const char *immediate;
      const char *indirect;
@@ -2251,7 +2448,7 @@ vip_op_defaults (immediate, indirect, displen)
  * We don't limit your choice of width character.
  *
  * DEC operands are hard work to parse. For example, '@' as the first
- * character means indirect (deferred) mode but elswhere it is a shift
+ * character means indirect (deferred) mode but elsewhere it is a shift
  * operator.
  * The long-winded explanation of how this is supposed to work is
  * cancelled. Read a DEC vax manual.
@@ -2282,7 +2479,7 @@ vip_op (optext, vopP)
      /* Input fields: vop_access, vop_width.
        Output fields: _ndx, _reg, _mode, _short, _warn,
        _error _expr_begin, _expr_end, _nbytes.
-       vop_nbytes : number of bytes in a datum. */
+       vop_nbytes : number of bytes in a datum.  */
      struct vop *vopP;
 {
   /* track operand text forward */
@@ -2305,7 +2502,7 @@ vip_op (optext, vopP)
   int ndx = 0;
   /* report illegal operand, ""==OK */
   /* " " is a FAKE error: means we won */
-  /* ANY err that begins with ' ' is a fake. */
+  /* ANY err that begins with ' ' is a fake.  */
   /* " " is converted to "" before return */
   const char *err;
   /* warn about weird modes pf address */
@@ -2321,8 +2518,8 @@ vip_op (optext, vopP)
    * get the types wrong below, we lose at compile time rather than at
    * lint or run time.
    */
-  char access_mode;            /* vop_access. */
-  char width;                  /* vop_width. */
+  char access_mode;            /* vop_access.  */
+  char width;                  /* vop_width.  */
 
   access_mode = vopP->vop_access;
   width = vopP->vop_width;
@@ -2332,13 +2529,13 @@ vip_op (optext, vopP)
 
   p = optext;
 
-  if (*p == ' ')               /* Expect all whitespace reduced to ' '. */
+  if (*p == ' ')               /* Expect all whitespace reduced to ' '.  */
     p++;                       /* skip over whitespace */
 
   if ((at = INDIRECTP (*p)) != 0)
     {                          /* 1 if *p=='@'(or '*' for Un*x) */
       p++;                     /* at is determined */
-      if (*p == ' ')           /* Expect all whitespace reduced to ' '. */
+      if (*p == ' ')           /* Expect all whitespace reduced to ' '.  */
        p++;                    /* skip over whitespace */
     }
 
@@ -2351,15 +2548,14 @@ vip_op (optext, vopP)
     char c;
 
     c = *p;
-    if (isupper (c))
-      c = tolower (c);
+    c = TOLOWER (c);
     if (DISPLENP (p[1]) && strchr ("bilws", len = c))
       p += 2;                  /* skip (letter) '^' */
     else                       /* no (letter) '^' seen */
       len = ' ';               /* len is determined */
   }
 
-  if (*p == ' ')               /* Expect all whitespace reduced to ' '. */
+  if (*p == ' ')               /* Expect all whitespace reduced to ' '.  */
     p++;                       /* skip over whitespace */
 
   if ((hash = IMMEDIATEP (*p)) != 0)   /* 1 if *p=='#' ('$' for Un*x) */
@@ -2377,7 +2573,7 @@ vip_op (optext, vopP)
     ;
   q--;                         /* now q points at last char of text */
 \f
-  if (*q == ' ' && q >= p)     /* Expect all whitespace reduced to ' '. */
+  if (*q == ' ' && q >= p)     /* Expect all whitespace reduced to ' '.  */
     q--;
   /* reverse over whitespace, but don't */
   /* run back over *p */
@@ -2404,9 +2600,11 @@ vip_op (optext, vopP)
           * name error. So again we don't need to check for early '\0'.
           */
          if (q[3] == ']')
-           ndx = vax_reg_parse (q[1], q[2], 0);
+           ndx = vax_reg_parse (q[1], q[2], 0, 0);
          else if (q[4] == ']')
-           ndx = vax_reg_parse (q[1], q[2], q[3]);
+           ndx = vax_reg_parse (q[1], q[2], q[3], 0);
+         else if (q[5] == ']')
+           ndx = vax_reg_parse (q[1], q[2], q[3], q[4]);
          else
            ndx = -1;
          /*
@@ -2430,7 +2628,7 @@ vip_op (optext, vopP)
    * Otherwise, ndx is index register number, and q points before "[...]".
    */
 \f
-  if (*q == ' ' && q >= p)     /* Expect all whitespace reduced to ' '. */
+  if (*q == ' ' && q >= p)     /* Expect all whitespace reduced to ' '.  */
     q--;
   /* reverse over whitespace, but don't */
   /* run back over *p */
@@ -2459,9 +2657,11 @@ vip_op (optext, vopP)
               * name error. So again we don't need to check for early '\0'.
               */
              if (q[3] == ')')
-               reg = vax_reg_parse (q[1], q[2], 0);
+               reg = vax_reg_parse (q[1], q[2], 0, 0);
              else if (q[4] == ')')
-               reg = vax_reg_parse (q[1], q[2], q[3]);
+               reg = vax_reg_parse (q[1], q[2], q[3], 0);
+             else if (q[5] == ')')
+               reg = vax_reg_parse (q[1], q[2], q[3], q[4]);
              else
                reg = -1;
              /*
@@ -2472,7 +2672,7 @@ vip_op (optext, vopP)
               */
              if (reg < 0)
                {
-                 /* JF allow parenthasized expressions.  I hope this works */
+                 /* JF allow parenthesized expressions.  I hope this works */
                  paren = 0;
                  while (*q != ')')
                    q++;
@@ -2527,12 +2727,15 @@ vip_op (optext, vopP)
           */
          if (!paren)
            {
-             if (*q == ' ' && q >= p)  /* Expect all whitespace reduced to ' '. */
+             if (*q == ' ' && q >= p)  /* Expect all whitespace reduced to ' '.  */
                q--;
              /* reverse over whitespace, but don't */
              /* run back over *p */
-             if (q > p && q < p + 3)   /* room for Rn or Rnn exactly? */
-               reg = vax_reg_parse (p[0], p[1], q < p + 2 ? 0 : p[2]);
+             /* room for Rn or Rnn (include prefix) exactly? */
+             if (q > p && q < p + 4)
+               reg = vax_reg_parse (p[0], p[1],
+                 q < p + 2 ? 0 : p[2],
+                 q < p + 3 ? 0 : p[3]);
              else
                reg = -1;       /* always comes here if no register at all */
              /*
@@ -2591,7 +2794,7 @@ vip_op (optext, vopP)
        err = " ";
     }
 \f
-  /* Since nobody seems to use it: comment this 'feature'(?) out for now. */
+  /* Since nobody seems to use it: comment this 'feature'(?) out for now.  */
 #ifdef NEVER
   /*
    * Case of stand-alone operand. e.g. ".long foo"
@@ -2821,7 +3024,7 @@ vip_op (optext, vopP)
    */
 \f
   /*
-   * Case of Rn. We seperate this one because it has a few special
+   * Case of Rn. We separate this one because it has a few special
    * errors the remaining modes lack.
    *
    * in:  at       optional
@@ -2944,7 +3147,7 @@ vip_op (optext, vopP)
 
   */
 \f
-#ifdef TEST                    /* #Define to use this testbed. */
+#ifdef TEST                    /* #Define to use this testbed.  */
 
 /*
  * Follows a test program for this function.
@@ -3074,16 +3277,17 @@ mumble (text, value)
 
 /* end: vip_op.c */
 
-const int md_short_jump_size = 3;
-const int md_long_jump_size = 6;
+int md_short_jump_size = 3;
+int md_long_jump_size = 6;
 const int md_reloc_size = 8;   /* Size of relocation record */
 
 void
 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
      char *ptr;
-     addressT from_addr, to_addr;
-     fragS *frag;
-     symbolS *to_symbol;
+     addressT from_addr;
+     addressT to_addr ATTRIBUTE_UNUSED;
+     fragS *frag ATTRIBUTE_UNUSED;
+     symbolS *to_symbol ATTRIBUTE_UNUSED;
 {
   valueT offset;
 
@@ -3099,7 +3303,8 @@ md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
 void
 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
      char *ptr;
-     addressT from_addr, to_addr;
+     addressT from_addr ATTRIBUTE_UNUSED;
+     addressT to_addr;
      fragS *frag;
      symbolS *to_symbol;
 {
@@ -3113,14 +3318,20 @@ md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
 }
 \f
 #ifdef OBJ_VMS
-CONST char *md_shortopts = "d:STt:V+1h:Hv::";
+const char *md_shortopts = "d:STt:V+1h:Hv::";
+#elif defined(OBJ_ELF)
+const char *md_shortopts = "d:STt:VkKQ:";
 #else
-CONST char *md_shortopts = "d:STt:V";
+const char *md_shortopts = "d:STt:V";
 #endif
 struct option md_longopts[] = {
+#ifdef OBJ_ELF
+#define OPTION_PIC (OPTION_MD_BASE)
+  {"pic", no_argument, NULL, OPTION_PIC},
+#endif
   {NULL, no_argument, NULL, 0}
 };
-size_t md_longopts_size = sizeof(md_longopts);
+size_t md_longopts_size = sizeof (md_longopts);
 
 int
 md_parse_option (c, arg)
@@ -3150,7 +3361,7 @@ md_parse_option (c, arg)
       break;
 
 #ifdef OBJ_VMS
-    case '+':                  /* For g++.  Hash any name > 31 chars long. */
+    case '+':                  /* For g++.  Hash any name > 31 chars long.  */
       flag_hash_long_names = 1;
       break;
 
@@ -3180,6 +3391,18 @@ md_parse_option (c, arg)
       break;
 #endif
 
+#ifdef OBJ_ELF
+    case OPTION_PIC:
+    case 'k':
+      flag_want_pic = 1;
+      break;                   /* -pic, Position Independent Code */
+
+     /* -Qy, -Qn: SVR4 arguments controlling whether a .comment
+       section should be emitted or not.  FIXME: Not implemented.  */
+    case 'Q':
+      break;
+#endif
+
     default:
       return 0;
     }
@@ -3191,7 +3414,7 @@ void
 md_show_usage (stream)
      FILE *stream;
 {
-  fprintf(stream, _("\
+  fprintf (stream, _("\
 VAX options:\n\
 -d LENGTH              ignored\n\
 -J                     ignored\n\
@@ -3213,10 +3436,9 @@ VMS options:\n\
 \f
 /* We have no need to default values of symbols.  */
 
-/* ARGSUSED */
 symbolS *
 md_undefined_symbol (name)
-     char *name;
+     char *name ATTRIBUTE_UNUSED;
 {
   return 0;
 }
@@ -3224,7 +3446,7 @@ md_undefined_symbol (name)
 /* Round up a section size to the appropriate boundary.  */
 valueT
 md_section_align (segment, size)
-     segT segment;
+     segT segment ATTRIBUTE_UNUSED;
      valueT size;
 {
   return size;                 /* Byte alignment is fine */
@@ -3232,7 +3454,7 @@ md_section_align (segment, size)
 
 /* Exactly what point is a PC-relative offset relative TO?
    On the vax, they're relative to the address of the offset, plus
-   its size. (??? Is this right?  FIXME-SOON) */
+   its size. */
 long
 md_pcrel_from (fixP)
      fixS *fixP;
@@ -3240,4 +3462,96 @@ md_pcrel_from (fixP)
   return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
 }
 
+#ifdef OBJ_AOUT
+#ifndef BFD_ASSEMBLER
+void
+tc_headers_hook(headers)
+     object_headers *headers;
+{
+#ifdef TE_NetBSD
+  N_SET_INFO(headers->header, OMAGIC, M_VAX4K_NETBSD, 0);
+  headers->header.a_info = htonl (headers->header.a_info);
+#endif
+}
+#endif /* !BFD_ASSEMBLER */
+#endif /* OBJ_AOUT */
+
+#ifdef BFD_ASSEMBLER
+arelent *
+tc_gen_reloc (section, fixp)
+     asection *section ATTRIBUTE_UNUSED;
+     fixS *fixp;
+{
+  arelent *reloc;
+  bfd_reloc_code_real_type code;
+
+  if (fixp->fx_tcbit)
+    abort();
+
+  if (fixp->fx_r_type != BFD_RELOC_NONE)
+    {
+      code = fixp->fx_r_type;
+
+      if (fixp->fx_pcrel)
+       {
+         switch (code)
+           {
+           case BFD_RELOC_8_PCREL:
+           case BFD_RELOC_16_PCREL:
+           case BFD_RELOC_32_PCREL:
+#ifdef OBJ_ELF
+           case BFD_RELOC_8_GOT_PCREL:
+           case BFD_RELOC_16_GOT_PCREL:
+           case BFD_RELOC_32_GOT_PCREL:
+           case BFD_RELOC_8_PLT_PCREL:
+           case BFD_RELOC_16_PLT_PCREL:
+           case BFD_RELOC_32_PLT_PCREL:
+#endif
+             break;
+           default:
+             as_bad_where (fixp->fx_file, fixp->fx_line,
+                           _("Cannot make %s relocation PC relative"),
+                           bfd_get_reloc_code_name (code));
+           }
+       }
+    }
+  else
+    {
+#define F(SZ,PCREL)            (((SZ) << 1) + (PCREL))
+      switch (F (fixp->fx_size, fixp->fx_pcrel))
+       {
+#define MAP(SZ,PCREL,TYPE)     case F(SZ,PCREL): code = (TYPE); break
+         MAP (1, 0, BFD_RELOC_8);
+         MAP (2, 0, BFD_RELOC_16);
+         MAP (4, 0, BFD_RELOC_32);
+         MAP (1, 1, BFD_RELOC_8_PCREL);
+         MAP (2, 1, BFD_RELOC_16_PCREL);
+         MAP (4, 1, BFD_RELOC_32_PCREL);
+       default:
+         abort ();
+       }
+    }
+#undef F
+#undef MAP
+
+  reloc = (arelent *) xmalloc (sizeof (arelent));
+  reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
+  *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
+  reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
+#ifndef OBJ_ELF
+  if (fixp->fx_pcrel)
+    reloc->addend = fixp->fx_addnumber;
+  else
+    reloc->addend = 0;
+#else
+  reloc->addend = fixp->fx_offset;
+#endif
+
+  reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
+  assert (reloc->howto != 0);
+
+  return reloc;
+}
+#endif /* BFD_ASSEMBLER */
+
 /* end of tc-vax.c */
This page took 0.053204 seconds and 4 git commands to generate.