x86: fix "REP RET" with -madd-bnd-prefix
authorJan Beulich <jbeulich@novell.com>
Wed, 11 Jul 2018 08:23:48 +0000 (10:23 +0200)
committerJan Beulich <jbeulich@suse.com>
Wed, 11 Jul 2018 08:23:48 +0000 (10:23 +0200)
Just like any other branches, RET should gain a BND prefix also when
already prefixed in source by REP.

gas/ChangeLog
gas/config/tc-i386.c
gas/testsuite/gas/i386/mpx-add-bnd-prefix.d
gas/testsuite/gas/i386/mpx-add-bnd-prefix.e [new file with mode: 0644]
gas/testsuite/gas/i386/mpx-add-bnd-prefix.s
gas/testsuite/gas/i386/x86-64-mpx-add-bnd-prefix.d
gas/testsuite/gas/i386/x86-64-mpx-add-bnd-prefix.e [new file with mode: 0644]
gas/testsuite/gas/i386/x86-64-mpx-add-bnd-prefix.s

index d49fc1151acf9ac82942564aa58b7d23888084f9..6de7a6167fe36fd0b718558776e87986ba398ea2 100644 (file)
@@ -1,3 +1,16 @@
+2018-07-11  Jan Beulich  <jbeulich@suse.com>
+
+       * config/tc-i386.c (md_assemble): Also replace an already
+       present REP prefix.
+       * testsuite/gas/i386/mpx-add-bnd-prefix.s,
+       testsuite/gas/i386/x86-64-mpx-add-bnd-prefix.s: Test RET with
+       all REP flavors.
+       * testsuite/gas/i386/mpx-add-bnd-prefix.d,
+       testsuite/gas/i386/x86-64-mpx-add-bnd-prefix.d: Adjust
+       expectations.
+       * testsuite/gas/i386/mpx-add-bnd-prefix.e,
+       testsuite/gas/i386/x86-64-mpx-add-bnd-prefix.e: New.
+
 2018-07-09  Jeff Law  <law@redhat.com>
 
        * testsuite/nds32/ji-jr.d: Fix name tag.
index 2d20f1cae9470f57c5529aa6016373396c79f4be..a7b84000e05ab1971cee28fc468b340f777a036b 100644 (file)
@@ -4112,10 +4112,16 @@ md_assemble (char *line)
     }
 
   /* Insert BND prefix.  */
-  if (add_bnd_prefix
-      && i.tm.opcode_modifier.bndprefixok
-      && !i.prefix[BND_PREFIX])
-    add_prefix (BND_PREFIX_OPCODE);
+  if (add_bnd_prefix && i.tm.opcode_modifier.bndprefixok)
+    {
+      if (!i.prefix[BND_PREFIX])
+       add_prefix (BND_PREFIX_OPCODE);
+      else if (i.prefix[BND_PREFIX] != BND_PREFIX_OPCODE)
+       {
+         as_warn (_("replacing `rep'/`repe' prefix by `bnd'"));
+         i.prefix[BND_PREFIX] = BND_PREFIX_OPCODE;
+       }
+    }
 
   /* Check string instruction segment overrides.  */
   if (i.tm.opcode_modifier.isstring && i.mem_operands != 0)
index 571f0da58978f7bd8456a13bcd829716b9d1dc42..30f6502b0820a002fc6d0512e1302de857d31022 100644 (file)
@@ -1,4 +1,5 @@
 #as: -madd-bnd-prefix
+#stderr: mpx-add-bnd-prefix.e
 #objdump: -drw
 #name: Check -madd-bnd-prefix
 
@@ -18,7 +19,9 @@ Disassembly of section .text:
 0+14 <foo>:
 [      ]*[a-f0-9]+:    f2 c3                   bnd ret 
 [      ]*[a-f0-9]+:    f2 c3                   bnd ret 
-[      ]*[a-f0-9]+:    f2 e8 f6 ff ff ff       bnd call 14 <foo>
+[      ]*[a-f0-9]+:    f2 c3                   bnd ret 
+[      ]*[a-f0-9]+:    f2 c3                   bnd ret 
+[      ]*[a-f0-9]+:    f2 e8 f2 ff ff ff       bnd call 14 <foo>
 [      ]*[a-f0-9]+:    01 c3                   add    %eax,%ebx
-[      ]*[a-f0-9]+:    e2 f2                   loop   14 <foo>
+[      ]*[a-f0-9]+:    e2 ee                   loop   14 <foo>
 #pass
diff --git a/gas/testsuite/gas/i386/mpx-add-bnd-prefix.e b/gas/testsuite/gas/i386/mpx-add-bnd-prefix.e
new file mode 100644 (file)
index 0000000..4e99ad0
--- /dev/null
@@ -0,0 +1,3 @@
+.*: Assembler messages:
+.*:12: Warning: .*rep.*bnd.*
+.*:13: Warning: .*rep.*bnd.*
index 638dafab8ed793fdc5b5dd65e55a06a768cd5c0a..a75faa7c9f3f7f6a9450a3eee48481dac9440f31 100644 (file)
@@ -8,6 +8,9 @@
        jmp     *(%ebx)
        ret
 foo:
+       # Use of REP/REPE prefix - converted to BND with warning
+       rep ret
+       repe ret
        # Use of REPNE prefix - we shouldn't get any error
        repne ret
        # BND prefix already exists - we shouldn't get any error here
index cef644f5c9bc36f5cac8c233ae83e5699f113ce1..139faae7dc5f29f2a5968e7a1b81e0e98ed80a07 100644 (file)
@@ -1,4 +1,5 @@
 #as: -madd-bnd-prefix
+#stderr: x86-64-mpx-add-bnd-prefix.e
 #objdump: -drw
 #name: Check -madd-bnd-prefix (x86-64)
 
@@ -18,7 +19,9 @@ Disassembly of section .text:
 0+14 <foo>:
 [      ]*[a-f0-9]+:    f2 c3                   bnd retq 
 [      ]*[a-f0-9]+:    f2 c3                   bnd retq 
-[      ]*[a-f0-9]+:    f2 e8 f6 ff ff ff       bnd callq 14 <foo>
+[      ]*[a-f0-9]+:    f2 c3                   bnd retq 
+[      ]*[a-f0-9]+:    f2 c3                   bnd retq 
+[      ]*[a-f0-9]+:    f2 e8 f2 ff ff ff       bnd callq 14 <foo>
 [      ]*[a-f0-9]+:    48 01 c3                add    %rax,%rbx
-[      ]*[a-f0-9]+:    e2 f1                   loop   14 <foo>
+[      ]*[a-f0-9]+:    e2 ed                   loop   14 <foo>
 #pass
diff --git a/gas/testsuite/gas/i386/x86-64-mpx-add-bnd-prefix.e b/gas/testsuite/gas/i386/x86-64-mpx-add-bnd-prefix.e
new file mode 100644 (file)
index 0000000..4e99ad0
--- /dev/null
@@ -0,0 +1,3 @@
+.*: Assembler messages:
+.*:12: Warning: .*rep.*bnd.*
+.*:13: Warning: .*rep.*bnd.*
index f9a900cfd83d04eea3b3fe0573d270016b2bfc3e..c1be9efa339202fb81548cddba6126f528b04448 100644 (file)
@@ -8,6 +8,9 @@
        jmp     *(%rbx)
        ret
 foo:
+       # Use of REP/REPE prefix - converted to BND with warning
+       rep ret
+       repe ret
        # Use of REPNE prefix - we shouldn't get any error
        repne ret
        # BND prefix already exists - we shouldn't get any error here