* config/tc-s390.c (s390_elf_cons): Correct fixups for PLT
[deliverable/binutils-gdb.git] / gas / config / tc-i386.c
index 57b9b0fd03d6a6ffbce1f48c38b26891fc1e54c1..275b3e6c439d6ccef86aa3f5ccc2157d2cc16d6f 100644 (file)
@@ -157,7 +157,7 @@ const char extra_symbol_chars[] = "*%-(";
 
 /* This array holds the chars that always start a comment.  If the
    pre-processor is disabled, these aren't very useful.  */
-#if defined (TE_I386AIX) || ((defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)) && ! defined (TE_LINUX) && !defined(TE_FreeBSD))
+#if defined (TE_I386AIX) || ((defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)) && ! defined (TE_LINUX) && !defined(TE_FreeBSD) && !defined(TE_NetBSD))
 /* Putting '/' here makes it impossible to use the divide operator.
    However, we need it for compatibility with SVR4 systems.  */
 const char comment_chars[] = "#/";
@@ -175,7 +175,7 @@ const char comment_chars[] = "#";
    #NO_APP at the beginning of its output.
    Also note that comments started like this one will always work if
    '/' isn't otherwise defined.  */
-#if defined (TE_I386AIX) || ((defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)) && ! defined (TE_LINUX) && !defined(TE_FreeBSD))
+#if defined (TE_I386AIX) || ((defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)) && ! defined (TE_LINUX) && !defined(TE_FreeBSD) && !defined(TE_NetBSD))
 const char line_comment_chars[] = "";
 #else
 const char line_comment_chars[] = "/";
@@ -1231,10 +1231,6 @@ md_assemble (line)
   /* Points to template once we've found it.  */
   const template *t;
 
-  /* Count the size of the instruction generated.  Does not include
-     variable part of jump insns before relax.  */
-  int insn_size = 0;
-
   int j;
 
   char mnemonic[MAX_MNEM_SIZE];
@@ -1273,7 +1269,8 @@ md_assemble (line)
          }
        if (!is_space_char (*l)
            && *l != END_OF_INSN
-           && *l != PREFIX_SEPARATOR)
+           && *l != PREFIX_SEPARATOR
+           && *l != ',')
          {
            as_bad (_("invalid character %s in mnemonic"),
                    output_invalid (*l));
@@ -1364,6 +1361,38 @@ md_assemble (line)
          }
       }
 
+    if (current_templates->start->opcode_modifier & (Jump | JumpByte))
+      {
+       /* Check for a branch hint.  We allow ",pt" and ",pn" for
+          predict taken and predict not taken respectively.
+          I'm not sure that branch hints actually do anything on loop
+          and jcxz insns (JumpByte) for current Pentium4 chips.  They
+          may work in the future and it doesn't hurt to accept them
+          now.  */
+       if (l[0] == ',' && l[1] == 'p')
+         {
+           if (l[2] == 't')
+             {
+               if (! add_prefix (DS_PREFIX_OPCODE))
+                 return;
+               l += 3;
+             }
+           else if (l[2] == 'n')
+             {
+               if (! add_prefix (CS_PREFIX_OPCODE))
+                 return;
+               l += 3;
+             }
+         }
+      }
+    /* Any other comma loses.  */
+    if (*l == ',')
+      {
+       as_bad (_("invalid character %s in mnemonic"),
+               output_invalid (*l));
+       return;
+      }
+
     /* Check if instruction is supported on specified architecture.  */
     if (cpu_arch_flags != 0)
       {
@@ -2702,6 +2731,11 @@ md_assemble (line)
   {
     register char *p;
 
+    /* Tie dwarf2 debug info to the address at the start of the insn.
+       We can't do this after the insn has been output as the current
+       frag may have been closed off.  eg. by frag_var.  */
+    dwarf2_emit_insn (0);
+
     /* Output jumps.  */
     if (i.tm.opcode_modifier & Jump)
       {
@@ -2719,6 +2753,13 @@ md_assemble (line)
            i.prefixes -= 1;
            code16 ^= CODE16;
          }
+       /* Pentium4 branch hints.  */
+       if (i.prefix[SEG_PREFIX] == CS_PREFIX_OPCODE /* not taken */
+           || i.prefix[SEG_PREFIX] == DS_PREFIX_OPCODE /* taken */)
+         {
+           prefix++;
+           i.prefixes--;
+         }
        if (i.prefix[REX_PREFIX])
          {
            prefix++;
@@ -2734,11 +2775,13 @@ md_assemble (line)
           bytes for the opcode and room for the prefix and largest
           displacement.  */
        frag_grow (prefix + 2 + 4);
-       insn_size += prefix + 1;
        /* Prefix and 1 opcode byte go in fr_fix.  */
        p = frag_more (prefix + 1);
        if (i.prefix[DATA_PREFIX])
          *p++ = DATA_PREFIX_OPCODE;
+       if (i.prefix[SEG_PREFIX] == CS_PREFIX_OPCODE
+           || i.prefix[SEG_PREFIX] == DS_PREFIX_OPCODE)
+         *p++ = i.prefix[SEG_PREFIX];
        if (i.prefix[REX_PREFIX])
          *p++ = i.prefix[REX_PREFIX];
        *p = i.tm.base_opcode;
@@ -2766,10 +2809,16 @@ md_assemble (line)
            size = 1;
            if (i.prefix[ADDR_PREFIX])
              {
-               insn_size += 1;
                FRAG_APPEND_1_CHAR (ADDR_PREFIX_OPCODE);
                i.prefixes -= 1;
              }
+           /* Pentium4 branch hints.  */
+           if (i.prefix[SEG_PREFIX] == CS_PREFIX_OPCODE /* not taken */
+               || i.prefix[SEG_PREFIX] == DS_PREFIX_OPCODE /* taken */)
+             {
+               FRAG_APPEND_1_CHAR (i.prefix[SEG_PREFIX]);
+               i.prefixes--;
+             }
          }
        else
          {
@@ -2781,7 +2830,6 @@ md_assemble (line)
 
            if (i.prefix[DATA_PREFIX])
              {
-               insn_size += 1;
                FRAG_APPEND_1_CHAR (DATA_PREFIX_OPCODE);
                i.prefixes -= 1;
                code16 ^= CODE16;
@@ -2795,26 +2843,14 @@ md_assemble (line)
        if (i.prefix[REX_PREFIX])
          {
            FRAG_APPEND_1_CHAR (i.prefix[REX_PREFIX]);
-           insn_size++;
            i.prefixes -= 1;
          }
 
        if (i.prefixes != 0 && !intel_syntax)
          as_warn (_("skipping prefixes on this instruction"));
 
-       if (fits_in_unsigned_byte (i.tm.base_opcode))
-         {
-           insn_size += 1 + size;
-           p = frag_more (1 + size);
-         }
-       else
-         {
-           /* Opcode can be at most two bytes.  */
-           insn_size += 2 + size;
-           p = frag_more (2 + size);
-           *p++ = (i.tm.base_opcode >> 8) & 0xff;
-         }
-       *p++ = i.tm.base_opcode & 0xff;
+       p = frag_more (1 + size);
+       *p++ = i.tm.base_opcode;
 
        fix_new_exp (frag_now, p - frag_now->fr_literal, size,
                     i.op[0].disps, 1, reloc (size, 1, 1, i.reloc[0]));
@@ -2850,7 +2886,6 @@ md_assemble (line)
          as_warn (_("skipping prefixes on this instruction"));
 
        /* 1 opcode; 2 segment; offset  */
-       insn_size += prefix + 1 + 2 + size;
        p = frag_more (prefix + 1 + 2 + size);
 
        if (i.prefix[DATA_PREFIX])
@@ -2898,7 +2933,6 @@ md_assemble (line)
          {
            if (*q)
              {
-               insn_size += 1;
                p = frag_more (1);
                md_number_to_chars (p, (valueT) *q, 1);
              }
@@ -2907,12 +2941,10 @@ md_assemble (line)
        /* Now the opcode; be careful about word order here!  */
        if (fits_in_unsigned_byte (i.tm.base_opcode))
          {
-           insn_size += 1;
            FRAG_APPEND_1_CHAR (i.tm.base_opcode);
          }
        else
          {
-           insn_size += 2;
            p = frag_more (2);
            /* Put out high byte first: can't use md_number_to_chars!  */
            *p++ = (i.tm.base_opcode >> 8) & 0xff;
@@ -2922,7 +2954,6 @@ md_assemble (line)
        /* Now the modrm byte and sib byte (if present).  */
        if (i.tm.opcode_modifier & Modrm)
          {
-           insn_size += 1;
            p = frag_more (1);
            md_number_to_chars (p,
                                (valueT) (i.rm.regmem << 0
@@ -2937,7 +2968,6 @@ md_assemble (line)
                && i.rm.mode != 3
                && !(i.base_reg && (i.base_reg->reg_type & Reg16) != 0))
              {
-               insn_size += 1;
                p = frag_more (1);
                md_number_to_chars (p,
                                    (valueT) (i.sib.base << 0
@@ -2971,7 +3001,6 @@ md_assemble (line)
                          }
                        val = offset_in_range (i.op[n].disps->X_add_number,
                                               size);
-                       insn_size += size;
                        p = frag_more (size);
                        md_number_to_chars (p, val, size);
                      }
@@ -3018,7 +3047,6 @@ md_assemble (line)
                              size = 8;
                          }
 
-                       insn_size += size;
                        p = frag_more (size);
                        fix_new_exp (frag_now, p - frag_now->fr_literal, size,
                                     i.op[n].disps, pcrel,
@@ -3053,7 +3081,6 @@ md_assemble (line)
                          }
                        val = offset_in_range (i.op[n].imms->X_add_number,
                                               size);
-                       insn_size += size;
                        p = frag_more (size);
                        md_number_to_chars (p, val, size);
                      }
@@ -3079,7 +3106,6 @@ md_assemble (line)
                              size = 8;
                          }
 
-                       insn_size += size;
                        p = frag_more (size);
                        reloc_type = reloc (size, 0, sign, i.reloc[n]);
 #ifdef BFD_ASSEMBLER
@@ -3107,8 +3133,6 @@ md_assemble (line)
          }
       }
 
-    dwarf2_emit_insn (insn_size);
-
 #ifdef DEBUG386
     if (flag_debug)
       {
@@ -3157,27 +3181,41 @@ lex_got (reloc, adjust)
       int len;
 
       len = strlen (gotrel[j].str);
-      if (strncmp (cp + 1, gotrel[j].str, len) == 0)
+      if (strncasecmp (cp + 1, gotrel[j].str, len) == 0)
        {
          if (gotrel[j].rel[(unsigned int) flag_code] != 0)
            {
-             int first;
-             char *tmpbuf;
+             int first, second;
+             char *tmpbuf, *past_reloc;
 
              *reloc = gotrel[j].rel[(unsigned int) flag_code];
+             if (adjust)
+               *adjust = len;
 
              if (GOT_symbol == NULL)
                GOT_symbol = symbol_find_or_make (GLOBAL_OFFSET_TABLE_NAME);
 
              /* Replace the relocation token with ' ', so that
                 errors like foo@GOTOFF1 will be detected.  */
+
+             /* The length of the first part of our input line.  */
              first = cp - input_line_pointer;
-             tmpbuf = xmalloc (strlen (input_line_pointer));
+
+             /* The second part goes from after the reloc token until
+                (and including) an end_of_line char.  Don't use strlen
+                here as the end_of_line char may not be a NUL.  */
+             past_reloc = cp + 1 + len;
+             for (cp = past_reloc; !is_end_of_line[(unsigned char) *cp++]; )
+               ;
+             second = cp - past_reloc;
+
+             /* Allocate and copy string.  The trailing NUL shouldn't
+                be necessary, but be safe.  */
+             tmpbuf = xmalloc (first + second + 2);
              memcpy (tmpbuf, input_line_pointer, first);
              tmpbuf[first] = ' ';
-             strcpy (tmpbuf + first + 1, cp + 1 + len);
-             if (adjust)
-               *adjust = len;
+             memcpy (tmpbuf + first + 1, past_reloc, second);
+             tmpbuf[first + second + 1] = '\0';
              return tmpbuf;
            }
 
@@ -4064,10 +4102,6 @@ md_convert_frag (abfd, sec, fragP)
 
   /* Address we want to reach in file space.  */
   target_address = S_GET_VALUE (fragP->fr_symbol) + fragP->fr_offset;
-#ifdef BFD_ASSEMBLER
-  /* Not needed otherwise?  */
-  target_address += symbol_get_frag (fragP->fr_symbol)->fr_address;
-#endif
 
   /* Address opcode resides at in file space.  */
   opcode_address = fragP->fr_address + fragP->fr_fix;
@@ -4751,8 +4785,9 @@ tc_gen_reloc (section, fixp)
          switch (fixp->fx_size)
            {
            default:
-             as_bad (_("can not do %d byte pc-relative relocation"),
-                     fixp->fx_size);
+             as_bad_where (fixp->fx_file, fixp->fx_line,
+                           _("can not do %d byte pc-relative relocation"),
+                           fixp->fx_size);
              code = BFD_RELOC_32_PCREL;
              break;
            case 1: code = BFD_RELOC_8_PCREL;  break;
@@ -4765,7 +4800,9 @@ tc_gen_reloc (section, fixp)
          switch (fixp->fx_size)
            {
            default:
-             as_bad (_("can not do %d byte relocation"), fixp->fx_size);
+             as_bad_where (fixp->fx_file, fixp->fx_line,
+                           _("can not do %d byte relocation"),
+                           fixp->fx_size);
              code = BFD_RELOC_32;
              break;
            case 1: code = BFD_RELOC_8;  break;
This page took 0.028239 seconds and 4 git commands to generate.