x86-64: fix suffix-less PUSH of symbol address
authorJan Beulich <jbeulich@suse.com>
Wed, 27 Sep 2023 08:53:38 +0000 (10:53 +0200)
committerJan Beulich <jbeulich@suse.com>
Wed, 27 Sep 2023 08:53:38 +0000 (10:53 +0200)
PR gas/30856

In 5cc007751cdb ("x86: further adjust extend-to-32bit-address
conditions") I neglected the case of PUSH, which is the only insn
allowing (proper) symbol addresses to be used as immediates (not
displacements, like CALL/JMP) in the absence of any register operands.
Since it defaults to 64-bit operand size, guessing an L suffix is wrong
there.

gas/config/tc-i386.c
gas/testsuite/gas/i386/immed64.d
gas/testsuite/gas/i386/immed64.s

index cec9a02be529d632912ee8b967bb8b3ff8780837..2e3154cb59f270ebdf95997fcb0c09f3355ae452 100644 (file)
@@ -6214,7 +6214,12 @@ optimize_imm (void)
     }
   else if ((flag_code == CODE_16BIT) ^ (i.prefix[DATA_PREFIX] != 0))
     guess_suffix = WORD_MNEM_SUFFIX;
-  else if (flag_code != CODE_64BIT || !(i.prefix[REX_PREFIX] & REX_W))
+  else if (flag_code != CODE_64BIT
+          || (!(i.prefix[REX_PREFIX] & REX_W)
+              /* A more generic (but also more involved) way of dealing
+                 with the special case(s) would be to go look for
+                 DefaultSize attributes on any of the templates.  */
+              && current_templates->start->mnem_off != MN_push))
     guess_suffix = LONG_MNEM_SUFFIX;
 
   for (op = i.operands; --op >= 0;)
index 35492a5a458c24b3a031defca75c0e0153918718..a83ab2c6e1ed037aaea9972693797a272bc753e2 100644 (file)
@@ -24,6 +24,12 @@ Disassembly of section \.text:
 [      ]*[0-9a-fA-F]+:[        ]+48 b8 04 00 00 00 00 00 00 00[        ]+movabsq? +\$0x4,%rax
 [      ]*[0-9a-fA-F]+:[        ]+48 b8 08 00 00 00 00 00 00 00[        ]+movabsq? +\$0x8,%rax
 [      ]*[0-9a-fA-F]+:[        ]+48 b8 00 00 00 00 00 00 00 00[        ]+movabsq? +\$0x0,%rax
+[      ]*[0-9a-fA-F]+:[        ]+6a 04[        ]+pushq? +\$0x4
+[      ]*[0-9a-fA-F]+:[        ]+68 08 00 00 00[       ]+pushq? +\$0x8
+[      ]*[0-9a-fA-F]+:[        ]+66 6a 04[     ]+pushw +\$0x4
+[      ]*[0-9a-fA-F]+:[        ]+66 68 08 00[  ]+pushw +\$0x8
+[      ]*[0-9a-fA-F]+:[        ]+6a 04[        ]+pushq? +\$0x4
+[      ]*[0-9a-fA-F]+:[        ]+68 08 00 00 00[       ]+pushq? +\$0x8
 [      ]*[0-9a-fA-F]+:[        ]+04 04[        ]+addb? +\$0x4,%al
 [      ]*[0-9a-fA-F]+:[        ]+04 08[        ]+addb? +\$0x8,%al
 [      ]*[0-9a-fA-F]+:[        ]+04 00[        ]+addb? +\$0x0,%al
index 265b41924e89f9465d7f8b680061a13bc5997fa5..21c30ec48606de4e235e0ffb63332f3743820791 100644 (file)
@@ -19,6 +19,12 @@ _start:
        movabsq $early, %rax
        movabsq $late, %rax
        movabsq $xtrn, %rax
+       pushq   $early
+       pushq   $late
+       pushw   $early
+       pushw   $late
+       push    $early
+       push    $late
        addb    $early, %al
        addb    $late, %al
        addb    $xtrn, %al