]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
x86: permit parenthesized expressions again as addressing scale factor
authorJan Beulich <jbeulich@suse.com>
Tue, 15 Jun 2021 05:57:11 +0000 (07:57 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 15 Jun 2021 05:57:11 +0000 (07:57 +0200)
The description of e68c3d59acd0 ("x86: better respect quotes in
parse_operands()") wrongly states:

"In i386_att_operand(), which needs adjustment to remain in sync, besides
 respecting double quotes now, also change the logic such that we don't
 count parentheses anymore: Finding any opening or closing parenthesis or
 any double quote means we're done, because the subsequent parsing code
 wouldn't accept (extra) instances of these anyway."

I didn't pay attention to the possibility of the scale factor being
specified as an expression, which may contain parentheses. Thanks to
Martin for pointing this out. Restore prior behavior or matching
parentheses (backwards), while giving the variable a more suitable name.
Note that this simple and immediate fix is not ging to be enough: This
expression could itself involve quoted symbols. However, to address this
backwards parsing needs to be done away with altogether here (such that
parentheses which are part of such a quoted symbol name can also
properly be accounted for), which is going to be a more intrusive
change.

gas/ChangeLog
gas/config/tc-i386.c
gas/testsuite/gas/i386/sib-intel.d
gas/testsuite/gas/i386/sib.d
gas/testsuite/gas/i386/sib.s

index ecd0794b643046adc577f7d9419ae330376b686c..d766fd1a28c79ef23692b8007d4fc8b3298f4bd0 100644 (file)
@@ -1,3 +1,11 @@
+2021-06-15  Jan Beulich  <jbeulich@suse.com>
+
+       * config/tc-i386.c (i386_att_operand): Re-introduce (now
+       properly named) parens_not_balanced.
+       * testsuite/gas/i386/sib.s: Add more cases.
+       * testsuite/gas/i386/sib.d, testsuite/gas/i386/sib-intel.d:
+       Adjust expectations.
+
 2021-06-14  Jan Beulich  <jbeulich@suse.com>
 
        * read.c (emit_expr_with_reloc): Fold three as_warn().
index b3f9f31db768abac979ddf60a63937745a0ce6c7..858538055116b0c33d3edf235a18b7ba3ccbfc5a 100644 (file)
@@ -11566,15 +11566,19 @@ i386_att_operand (char *operand_string)
       if (*base_string == ')')
        {
          char *temp_string;
+         unsigned int parens_not_balanced = 1;
 
          /* We've already checked that the number of left & right ()'s are
             equal, so this loop will not be infinite.  */
          do
            {
              base_string--;
+             if (*base_string == ')')
+               parens_not_balanced++;
+             if (*base_string == '(')
+               parens_not_balanced--;
            }
-         while (*base_string != '(' && *base_string != ')'
-                && *base_string != '"');
+         while (parens_not_balanced && *base_string != '"');
 
          temp_string = base_string;
 
index 27709ebb95e728e436675d4f7044e26b714678bd..ccd2ea9643e517c9231114f322361efc9764b8c3 100644 (file)
@@ -30,6 +30,10 @@ Disassembly of section .text:
 [      ]*[a-f0-9]+:    8b 04 64                mov    eax,DWORD PTR \[esp\+eiz\*2\]
 [      ]*[a-f0-9]+:    8b 04 a4                mov    eax,DWORD PTR \[esp\+eiz\*4\]
 [      ]*[a-f0-9]+:    8b 04 e4                mov    eax,DWORD PTR \[esp\+eiz\*8\]
+[      ]*[a-f0-9]+:    8b 04 00                mov    eax,DWORD PTR \[eax\+eax\*1\]
+[      ]*[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 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\]
index 0ece4183af164eae03f151e84e928e3d3c992e1c..151935c62ec166d44f5d8d5d1e0696c815a54b25 100644 (file)
@@ -29,6 +29,10 @@ Disassembly of section .text:
 [      ]*[a-f0-9]+:    8b 04 64                mov    \(%esp,%eiz,2\),%eax
 [      ]*[a-f0-9]+:    8b 04 a4                mov    \(%esp,%eiz,4\),%eax
 [      ]*[a-f0-9]+:    8b 04 e4                mov    \(%esp,%eiz,8\),%eax
+[      ]*[a-f0-9]+:    8b 04 00                mov    \(%eax,%eax,1\),%eax
+[      ]*[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 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
index 430da42b73c55c6ba7068e0a96852b9942b04c77..c0e007f3108ebf8b8dc876c3dc4695398fac746b 100644 (file)
@@ -26,6 +26,10 @@ foo:
        mov     (%esp,%eiz,2),%eax
        mov     (%esp,%eiz,4),%eax
        mov     (%esp,%eiz,8),%eax
+       mov     (%eax, %eax, (1 << 0)), %eax
+       mov     (%eax, %eax, (1 << 1)), %eax
+       mov     (%eax, %eax, (1 << 2)), %eax
+       mov     (%eax, %eax, (1 << 3)), %eax
        .intel_syntax noprefix
         mov    eax,DWORD PTR [eiz*1-30]
         mov    eax,DWORD PTR [eiz*2-30]