x86: Do not dump DS/CS segment overrides for branch hints
authorBorislav Petkov <bp@suse.de>
Sat, 28 Nov 2020 13:20:06 +0000 (14:20 +0100)
committerH.J. Lu <hjl.tools@gmail.com>
Sun, 29 Nov 2020 17:08:56 +0000 (09:08 -0800)
The previous change

  "x86: Ignore CS/DS/ES/SS segment-override prefixes in 64-bit mode"

to ignore segment override prefixes in 64-bit mode lead to dumping
branch hints as excessive prefixes:

  ffffffff8109d5a0 <vmx_get_rflags>:
  ...
  ffffffff8109d601:       3e 77 0a                ds ja,pt ffffffff8109d60e <vmx_get_rflags+0x6e>
   ^^^^^

In this particular case, those prefixes are not excessive but are used
to provide branch hints - taken/not-taken - to the CPU.

Assign active_seg_prefix in that particular case to consume them.

gas/

2002-11-29  Borislav Petkov  <bp@suse.de>

        * testsuite/gas/i386/branch.d: Add new branch insns test.
        * testsuite/gas/i386/branch.s: Likewise.
        * testsuite/gas/i386/i386.exp: Insert the new branch test.
        * testsuite/gas/i386/x86-64-branch.d: Test for branch hints insns.
        * testsuite/gas/i386/x86-64-branch.s: Likewise.
        * testsuite/gas/i386/ilp32/x86-64-branch.d: Likewise.

opcodes/

2020-11-28 Borislav Petkov  <bp@suse.de>

        * i386-dis.c (print_insn): Set active_seg_prefix for branch hint insns
        to not dump branch hint prefixes 0x2E and 0x3E as unused prefixes.

gas/ChangeLog
gas/testsuite/gas/i386/branch.d [new file with mode: 0644]
gas/testsuite/gas/i386/branch.s [new file with mode: 0644]
gas/testsuite/gas/i386/i386.exp
gas/testsuite/gas/i386/ilp32/x86-64-branch.d
gas/testsuite/gas/i386/x86-64-branch.d
gas/testsuite/gas/i386/x86-64-branch.s
opcodes/ChangeLog
opcodes/i386-dis.c

index 97754267be9b8fce3654bb4add3b560dd711cd58..8d07dc9bbb9a224bd9d024b0c6a4de964ecc0d68 100644 (file)
@@ -1,3 +1,12 @@
+2002-11-29  Borislav Petkov  <bp@suse.de>
+
+       * testsuite/gas/i386/branch.d: Add new branch insns test.
+       * testsuite/gas/i386/branch.s: Likewise.
+       * testsuite/gas/i386/i386.exp: Insert the new branch test.
+       * testsuite/gas/i386/x86-64-branch.d: Test for branch hints insns.
+       * testsuite/gas/i386/x86-64-branch.s: Likewise.
+       * testsuite/gas/i386/ilp32/x86-64-branch.d: Likewise.
+
 2020-11-27  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
 
        * testsuite/gas/elf/elf.exp: Run new tests.
diff --git a/gas/testsuite/gas/i386/branch.d b/gas/testsuite/gas/i386/branch.d
new file mode 100644 (file)
index 0000000..6d25b95
--- /dev/null
@@ -0,0 +1,12 @@
+#as: -J
+#objdump: -dw
+#name: i386 branch
+
+.*: +file format .*
+
+Disassembly of section .text:
+
+0+ <.text>:
+[      ]*[a-f0-9]+:    3e 74 03[       ]+je,pt  +0x[0-9a-f]+
+[      ]*[a-f0-9]+:    2e 74 00[       ]+je,pn  +0x[0-9a-f]+
+#pass
diff --git a/gas/testsuite/gas/i386/branch.s b/gas/testsuite/gas/i386/branch.s
new file mode 100644 (file)
index 0000000..968a181
--- /dev/null
@@ -0,0 +1,4 @@
+.text
+       jz,pt .Llabel
+       jz,pn .Llabel
+.Llabel:
index c85ced1c918153e51d4f92f23c639a2b310f6273..432cf0192d49a414789685c2ea6d3820f6ecc142 100644 (file)
@@ -565,6 +565,7 @@ if [gas_32_check] then {
     run_dump_test "lfence-ret-c"
     run_dump_test "lfence-ret-d"
     run_dump_test "lfence-byte"
+    run_dump_test "branch"
 
     # These tests require support for 8 and 16 bit relocs,
     # so we only run them for ELF and COFF targets.
index 8be91de922f38247fcd7db7a8d7ccb77a3ee6b31..d5f2358546fcf1073ab9323373f676c04c4a0803 100644 (file)
@@ -25,6 +25,8 @@ Disassembly of section .text:
 [      ]*[a-f0-9]+:    66 0f 82 00 00 00 00    data16 jb 0x37  33: R_X86_64_PLT32      foo-0x4
 [      ]*[a-f0-9]+:    66 c3                   data16 ret *
 [      ]*[a-f0-9]+:    66 c2 08 00             data16 ret \$0x8
+[      ]*[a-f0-9]+:    3e 74 03[       ]+je,pt  +0x[0-9a-f]+
+[      ]*[a-f0-9]+:    2e 74 00[       ]+je,pn  +0x[0-9a-f]+
 [      ]*[a-f0-9]+:    ff d0                   call   \*%rax
 [      ]*[a-f0-9]+:    ff d0                   call   \*%rax
 [      ]*[a-f0-9]+:    66 ff d0                data16 call \*%rax
index 2618134b40110b38150419ade6a49a59668bf3a5..b963f9f051e47ff472ccc2cec36a78b2de8061a0 100644 (file)
@@ -24,6 +24,8 @@ Disassembly of section .text:
 [      ]*[a-f0-9]+:    66 0f 82 00 00 00 00    data16 jb (0x37|37 <.text\+0x37>)
 [      ]*[a-f0-9]+:    66 c3                   data16 ret *
 [      ]*[a-f0-9]+:    66 c2 08 00             data16 ret \$0x8
+[      ]*[a-f0-9]+:    3e 74 03[       ]+je,pt  +0x[0-9a-f]+
+[      ]*[a-f0-9]+:    2e 74 00[       ]+je,pn  +0x[0-9a-f]+
 [      ]*[a-f0-9]+:    ff d0                   call   \*%rax
 [      ]*[a-f0-9]+:    ff d0                   call   \*%rax
 [      ]*[a-f0-9]+:    66 ff d0                data16 call \*%rax
index eb40dd4d4cd1a3c07e96cb93a550177ff6302392..496e1bb089fb7c3d5f00995f0ac4216b28b1de99 100644 (file)
        retw
        retw    $8
 
+       jz,pt .Llabel
+       jz,pn .Llabel
+.Llabel:
+
        .intel_syntax noprefix
        call    rax
        callq   rax
index 1e7e40fd9664ec53368c46b85e832a62aa0b3b48..02fd2f5b583701d46ed6f4bb0df1882b980ae400 100644 (file)
@@ -1,3 +1,8 @@
+2020-11-28 Borislav Petkov  <bp@suse.de>
+
+       * i386-dis.c (print_insn): Set active_seg_prefix for branch hint insns
+       to not dump branch hint prefixes 0x2E and 0x3E as unused prefixes.
+
 2020-11-16  Przemyslaw Wirkus  <przemyslaw.wirkus@arm.com>
 
        * aarch64-tbl.h (FLAGM): Handle for FLAGM feature.
index 58cf001080bcc0f831ea9e6901b1cb96e636d706..a1e47c57251f7d85e7ba723cefcd84f56a68e275 100644 (file)
@@ -10910,10 +10910,19 @@ putop (const char *in_template, int sizeflag)
              used_prefixes |= prefixes & (PREFIX_CS | PREFIX_DS);
              *obufp++ = ',';
              *obufp++ = 'p';
+
+             /* Set active_seg_prefix even if not set in 64-bit mode
+                because here it is a valid branch hint. */
              if (prefixes & PREFIX_DS)
-               *obufp++ = 't';
+               {
+                 active_seg_prefix = PREFIX_DS;
+                 *obufp++ = 't';
+               }
              else
-               *obufp++ = 'n';
+               {
+                 active_seg_prefix = PREFIX_CS;
+                 *obufp++ = 'n';
+               }
            }
          break;
        case 'K':