public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Binutils <binutils@sourceware.org>
Cc: "H.J. Lu" <hjl.tools@gmail.com>, bouanto@zoho.com
Subject: [PATCH 1/2] x86-64: fix suffix-less PUSH of symbol address
Date: Fri, 22 Sep 2023 09:52:02 +0200	[thread overview]
Message-ID: <bad05471-aa90-0ae8-3c82-8115fc2a5bf2@suse.com> (raw)
In-Reply-To: <e503162e-b4ce-8106-eb83-db781e100553@suse.com>

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.

--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -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;)
--- a/gas/testsuite/gas/i386/immed64.d
+++ b/gas/testsuite/gas/i386/immed64.d
@@ -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
--- a/gas/testsuite/gas/i386/immed64.s
+++ b/gas/testsuite/gas/i386/immed64.s
@@ -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


  reply	other threads:[~2023-09-22  7:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-22  7:50 [PATCH 0/2] x86-64: immediate insn operand fixes Jan Beulich
2023-09-22  7:52 ` Jan Beulich [this message]
2023-09-22  7:52 ` [PATCH 2/2] x86-64: REX.W overrides DATA_PREFIX Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bad05471-aa90-0ae8-3c82-8115fc2a5bf2@suse.com \
    --to=jbeulich@suse.com \
    --cc=binutils@sourceware.org \
    --cc=bouanto@zoho.com \
    --cc=hjl.tools@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).