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>
Subject: [PATCH] x86/gas: support quoted address scale factor in AT&T syntax
Date: Tue, 13 Sep 2022 18:03:11 +0200	[thread overview]
Message-ID: <224f7123-1ed8-2a6c-12c5-70e2a2dab18f@suse.com> (raw)

An earlier attempt (e68c3d59acd0 ["x86: better respect quotes in
parse_operands()"]) needed undoing (cc0f96357e0b ["x86: permit
parenthesized expressions again as addressing scale factor"]) as far its
effect here went. As indicated back then, the issue is the backwards
scanning of the operand string to find the matching opening parenthesis.
Switch to forward scanning, finding the last outermost unquoted opening
parenthesis (which is the one matching the trailing closing one).

--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -11620,25 +11620,32 @@ i386_att_operand (char *operand_string)
       if (*base_string == ')')
 	{
 	  char *temp_string;
-	  unsigned int parens_not_balanced = 1;
+	  unsigned int parens_not_balanced = 0;
+	  bool in_quotes = false;
 
 	  /* We've already checked that the number of left & right ()'s are
-	     equal, so this loop will not be infinite.  */
-	  do
+	     equal, and that there's a matching set of double quotes.  */
+	  end_op = base_string;
+	  for (temp_string = op_string; temp_string < end_op; temp_string++)
 	    {
-	      base_string--;
-	      if (*base_string == ')')
-		parens_not_balanced++;
-	      if (*base_string == '(')
-		parens_not_balanced--;
+	      if (*temp_string == '\\' && temp_string[1] == '"')
+		++temp_string;
+	      else if (*temp_string == '"')
+		in_quotes = !in_quotes;
+	      else if (!in_quotes)
+		{
+		  if (*temp_string == '(' && !parens_not_balanced++)
+		    base_string = temp_string;
+		  if (*temp_string == ')')
+		    --parens_not_balanced;
+		}
 	    }
-	  while (parens_not_balanced && *base_string != '"');
 
 	  temp_string = base_string;
 
 	  /* Skip past '(' and whitespace.  */
-	  if (*base_string == '(')
-	    ++base_string;
+	  gas_assert (*base_string == '(');
+	  ++base_string;
 	  if (is_space_char (*base_string))
 	    ++base_string;
 
--- a/gas/testsuite/gas/i386/sib-intel.d
+++ b/gas/testsuite/gas/i386/sib-intel.d
@@ -34,6 +34,10 @@ Disassembly of section .text:
 [ 	]*[a-f0-9]+:	8b 04 40             	mov    eax,DWORD PTR \[eax\+eax\*2\]
 [ 	]*[a-f0-9]+:	8b 04 80             	mov    eax,DWORD PTR \[eax\+eax\*4\]
 [ 	]*[a-f0-9]+:	8b 04 c0             	mov    eax,DWORD PTR \[eax\+eax\*8\]
+[ 	]*[a-f0-9]+:	8b 14 08             	mov    edx,DWORD PTR \[eax\+ecx\*1\]
+[ 	]*[a-f0-9]+:	8b 14 48             	mov    edx,DWORD PTR \[eax\+ecx\*2\]
+[ 	]*[a-f0-9]+:	8b 14 88             	mov    edx,DWORD PTR \[eax\+ecx\*4\]
+[ 	]*[a-f0-9]+:	8b 14 c8             	mov    edx,DWORD PTR \[eax\+ecx\*8\]
 [ 	]*[a-f0-9]+:	8b 04 25 e2 ff ff ff 	mov    eax,DWORD PTR \[eiz\*1-0x1e\]
 [ 	]*[a-f0-9]+:	8b 04 65 e2 ff ff ff 	mov    eax,DWORD PTR \[eiz\*2-0x1e\]
 [ 	]*[a-f0-9]+:	8b 04 a5 e2 ff ff ff 	mov    eax,DWORD PTR \[eiz\*4-0x1e\]
--- a/gas/testsuite/gas/i386/sib.d
+++ b/gas/testsuite/gas/i386/sib.d
@@ -33,6 +33,10 @@ Disassembly of section .text:
 [ 	]*[a-f0-9]+:	8b 04 40             	mov    \(%eax,%eax,2\),%eax
 [ 	]*[a-f0-9]+:	8b 04 80             	mov    \(%eax,%eax,4\),%eax
 [ 	]*[a-f0-9]+:	8b 04 c0             	mov    \(%eax,%eax,8\),%eax
+[ 	]*[a-f0-9]+:	8b 14 08             	mov    \(%eax,%ecx,1\),%edx
+[ 	]*[a-f0-9]+:	8b 14 48             	mov    \(%eax,%ecx,2\),%edx
+[ 	]*[a-f0-9]+:	8b 14 88             	mov    \(%eax,%ecx,4\),%edx
+[ 	]*[a-f0-9]+:	8b 14 c8             	mov    \(%eax,%ecx,8\),%edx
 [ 	]*[a-f0-9]+:	8b 04 25 e2 ff ff ff 	mov    -0x1e\(,%eiz,1\),%eax
 [ 	]*[a-f0-9]+:	8b 04 65 e2 ff ff ff 	mov    -0x1e\(,%eiz,2\),%eax
 [ 	]*[a-f0-9]+:	8b 04 a5 e2 ff ff ff 	mov    -0x1e\(,%eiz,4\),%eax
--- a/gas/testsuite/gas/i386/sib.s
+++ b/gas/testsuite/gas/i386/sib.s
@@ -30,6 +30,14 @@ foo:
 	mov	(%eax, %eax, (1 << 1)), %eax
 	mov	(%eax, %eax, (1 << 2)), %eax
 	mov	(%eax, %eax, (1 << 3)), %eax
+	.equ "scale(1)", 1
+	mov	(%eax, %ecx, "scale(1)"), %edx
+	.equiv "scale[2]", 2
+	mov	(%eax, %ecx, "scale[2]"), %edx
+	.eqv "scale{4}", 4
+	mov	(%eax, %ecx, "scale{4}"), %edx
+	.set "scale<8>", 8
+	mov	(%eax, %ecx, "scale<8>"), %edx
 	.intel_syntax noprefix
         mov    eax,DWORD PTR [eiz*1-30]
         mov    eax,DWORD PTR [eiz*2-30]

                 reply	other threads:[~2022-09-13 16:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=224f7123-1ed8-2a6c-12c5-70e2a2dab18f@suse.com \
    --to=jbeulich@suse.com \
    --cc=binutils@sourceware.org \
    --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).