x86-64: REX.W overrides DATA_PREFIX
authorJan Beulich <jbeulich@suse.com>
Wed, 27 Sep 2023 08:53:59 +0000 (10:53 +0200)
committerJan Beulich <jbeulich@suse.com>
Wed, 27 Sep 2023 08:53:59 +0000 (10:53 +0200)
REX.W needs to be respected when immediate size and relocation type are
determined.

gas/config/tc-i386.c

index 2e3154cb59f270ebdf95997fcb0c09f3355ae452..aec4f211faada4344687e7c77c153326399d3432 100644 (file)
@@ -6212,7 +6212,8 @@ optimize_imm (void)
            break;
          }
     }
-  else if ((flag_code == CODE_16BIT) ^ (i.prefix[DATA_PREFIX] != 0))
+  else if ((flag_code == CODE_16BIT)
+           ^ (i.prefix[DATA_PREFIX] != 0 && !(i.prefix[REX_PREFIX] & REX_W)))
     guess_suffix = WORD_MNEM_SUFFIX;
   else if (flag_code != CODE_64BIT
           || (!(i.prefix[REX_PREFIX] & REX_W)
@@ -8186,7 +8187,8 @@ update_imm (unsigned int j)
               || operand_type_equal (&overlap, &imm16_32)
               || operand_type_equal (&overlap, &imm16_32s))
        {
-         if ((flag_code == CODE_16BIT) ^ (i.prefix[DATA_PREFIX] != 0))
+         if ((flag_code == CODE_16BIT)
+             ^ (i.prefix[DATA_PREFIX] != 0 && !(i.prefix[REX_PREFIX] & REX_W)))
            overlap = imm16;
          else
            overlap = imm32s;
@@ -10426,6 +10428,7 @@ output_imm (fragS *insn_start_frag, offsetT insn_start_off)
              if (i.types[n].bitfield.imm32s
                  && (i.suffix == QWORD_MNEM_SUFFIX
                      || (!i.suffix && i.tm.opcode_modifier.no_lsuf)
+                     || (i.prefix[REX_PREFIX] & REX_W)
                      || dot_insn ()))
                sign = 1;
              else