x86/Intel: issue diagnostics for redundant segment override prefixes
authorJan Beulich <jbeulich@novell.com>
Thu, 30 Nov 2017 10:46:26 +0000 (11:46 +0100)
committerJan Beulich <jbeulich@suse.com>
Thu, 30 Nov 2017 10:46:26 +0000 (11:46 +0100)
While we shouldn't outright reject such (as was wrongly done by commit
4d36230d59 ("x86: Update segment register check in Intel syntax"), as
MASM accepts them even silently, issue (by default) a warning for such
questionable constructs.

gas/ChangeLog
gas/config/tc-i386-intel.c
gas/testsuite/gas/i386/intelok.d
gas/testsuite/gas/i386/intelok.e [new file with mode: 0644]
gas/testsuite/gas/i386/inval-seg.l
gas/testsuite/gas/i386/inval-seg.s

index 1b6401fe17fbd2eea9739dcb7301b6e6bd2adbed..a46f8deb40193f1fd2e23720dc984c7618aeee95 100644 (file)
@@ -1,3 +1,15 @@
+2017-11-29  Jan Beulich  <jbeulich@suse.com>
+
+       PR gas/21874
+       * config/tc-i386-intel.c (i386_intel_simplify): Chain together
+       multiple segment override expressions.
+       (i386_intel_operand): Issue diagnostic for redundant segment
+       overrides.
+       * testsuite/gas/i386/intelok.e: New.
+       * testsuite/gas/i386/intelok.d: Reference intelok.e.
+       * testsuite/gas/i386/inval-seg.s: Add redundant override checks.
+       * testsuite/gas/i386/inval-seg.l: Adjust expectations.
+
 2017-11-29  Jim Wilson  <jimw@sifive.com>
            Palmer Dabbelt  <palmer@sifive.com>
 
index 74aae24c41ba80c7ce5dc68104c4cdc43ec03148..99d215e8eff3d088ee9cd01b41c5e90de58aef4b 100644 (file)
@@ -413,7 +413,19 @@ static int i386_intel_simplify (expressionS *e)
                               intel_state.index))
        return 0;
       if (!intel_state.in_offset)
-       intel_state.seg = e->X_add_symbol;
+       {
+         if (!intel_state.seg)
+           intel_state.seg = e->X_add_symbol;
+         else
+           {
+             expressionS exp;
+
+             exp.X_op = O_full_ptr;
+             exp.X_add_symbol = e->X_add_symbol;
+             exp.X_op_symbol = intel_state.seg;
+             intel_state.seg = make_expr_symbol (&exp);
+           }
+       }
       i386_intel_fold (e, e->X_op_symbol);
       break;
 
@@ -956,10 +968,12 @@ i386_intel_operand (char *operand_string, int got_a_float)
 
       if (intel_state.seg)
        {
-         for (;;)
+         for (ret = check_none; ; ret = operand_check)
            {
              expP = symbol_get_value_expression (intel_state.seg);
-             if (expP->X_op != O_full_ptr)
+             if (expP->X_op != O_full_ptr 
+                 || symbol_get_value_expression (expP->X_op_symbol)->X_op
+                    != O_register)
                break;
              intel_state.seg = expP->X_add_symbol;
            }
@@ -974,6 +988,15 @@ i386_intel_operand (char *operand_string, int got_a_float)
              as_bad (_("invalid use of register"));
              return 0;
            }
+         switch (ret)
+           {
+           case check_error:
+             as_bad (_("redundant segment overrides"));
+             return 0;
+           case check_warning:
+             as_warn (_("redundant segment overrides"));
+             break;
+           }
          switch (i386_regtab[expP->X_add_number].reg_num)
            {
            case 0: i.seg[i.mem_operands] = &es; break;
index bad81e41e2c78760ddeb297af67da07772ce62e6..41e65b3984fc0d2cdb1363577f7fde91e40abd16 100644 (file)
@@ -1,6 +1,7 @@
 #as: -J --divide
 #objdump: -dwMintel
 #name: i386 intel-ok
+#stderr: intelok.e
 
 .*: +file format .*
 
diff --git a/gas/testsuite/gas/i386/intelok.e b/gas/testsuite/gas/i386/intelok.e
new file mode 100644 (file)
index 0000000..585eaf4
--- /dev/null
@@ -0,0 +1,2 @@
+.*: Assembler messages:
+.*:153: Warning: redundant segment overrides
index efe190e9998f76f177b34614248a4c32e6dd4c88..c081b0e24e99c5f330d640ef3b8b4a0c5c9000b0 100644 (file)
@@ -1,10 +1,22 @@
 .*: Assembler messages:
 .*:3: Error: .*
 .*:4: Error: .*
+.*:7: Error: .*
+.*:8: Error: .*
+.*:9: Error: .*
+.*:10: Error: .*
+.*:11: Error: .*
 GAS LISTING .*
 
 
-   1 [         ]*      .text
-   2 [         ]*# All the following should be illegal
-   3 [         ]*      movl    %ds,\(%eax\)
-   4 [         ]*      movl    \(%eax\),%ds
+[      ]*[1-9][0-9]*[  ]*\.text
+[      ]*[1-9][0-9]*[  ]*# All the following should be illegal
+[      ]*[1-9][0-9]*[  ]*movl  %ds,\(%eax\)
+[      ]*[1-9][0-9]*[  ]*movl  \(%eax\),%ds
+[      ]*[1-9][0-9]*[  ]*
+[      ]*[1-9][0-9]*[  ]*\.intel_syntax noprefix
+[      ]*[1-9][0-9]*[  ]*mov   eax, es:foo:\[eax\]
+[      ]*[1-9][0-9]*[  ]*mov   eax, es:fs:foo:\[eax\]
+[      ]*[1-9][0-9]*[  ]*mov   eax, fs:foo:bar:\[eax\]
+[      ]*[1-9][0-9]*[  ]*mov   eax, fs:foo:gs:\[eax\]
+[      ]*[1-9][0-9]*[  ]*mov   eax, bar:gs:\[eax\]
index 4cc222145e8a79ae052cb42cab4a682ab5e086d1..bf09d4d3ccd9503bf00cc24b567908a85a02886b 100644 (file)
@@ -2,3 +2,10 @@
 # All the following should be illegal
        movl    %ds,(%eax)
        movl    (%eax),%ds
+
+       .intel_syntax noprefix
+       mov     eax, es:foo:[eax]
+       mov     eax, es:fs:foo:[eax]
+       mov     eax, fs:foo:bar:[eax]
+       mov     eax, fs:foo:gs:[eax]
+       mov     eax, bar:gs:[eax]