[PATCH] i386: Don't mitigation for lret/iret since they's UD in SGX enclaves.

Hongtao Liu crazylht@gmail.com
Sat May 9 07:29:00 GMT 2020


Don't handle lret/iret when -mlfence-before-ret=[or|not|shl|yes] since
they are invalid in SGX enclaves.

gas/ChangeLog
        * gas/config/tc-i386.c: Not handle lret/iret.
        * gas/testsuite/gas/i386/lfence-ret-a.d: Adjust testcase.
        * gas/testsuite/gas/i386/lfence-ret-b.d: Ditto.
        * gas/testsuite/gas/i386/lfence-ret-c.d: Ditto.
        * gas/testsuite/gas/i386/lfence-ret-d.d: Ditto.
        * gas/testsuite/gas/i386/lfence-ret.s: Ditto.
        * gas/testsuite/gas/i386/x86-64-lfence-ret-a.d: Ditto.
        * gas/testsuite/gas/i386/x86-64-lfence-ret-b.d: Ditto.
        * gas/testsuite/gas/i386/x86-64-lfence-ret-c.d: Ditto.
        * gas/testsuite/gas/i386/x86-64-lfence-ret-d.d: Ditto.
        * gas/testsuite/gas/i386/x86-64-lfence-ret-e.d: Ditto.
        * gas/testsuite/gas/i386/x86-64-lfence-ret.s: Ditto.
        * gas/testsuite/gas/i386/x86-64-lfence-ret.e: Deleted.
---
 gas/config/tc-i386.c                         | 20 ++++------------
 gas/testsuite/gas/i386/lfence-ret-a.d        | 12 ----------
 gas/testsuite/gas/i386/lfence-ret-b.d        | 16 -------------
 gas/testsuite/gas/i386/lfence-ret-c.d        | 14 +----------
 gas/testsuite/gas/i386/lfence-ret-d.d        | 12 ----------
 gas/testsuite/gas/i386/lfence-ret.s          |  4 ----
 gas/testsuite/gas/i386/x86-64-lfence-ret-a.d | 19 ---------------
 gas/testsuite/gas/i386/x86-64-lfence-ret-b.d | 25 --------------------
 gas/testsuite/gas/i386/x86-64-lfence-ret-c.d | 19 ---------------
 gas/testsuite/gas/i386/x86-64-lfence-ret-d.d | 19 ---------------
 gas/testsuite/gas/i386/x86-64-lfence-ret-e.d | 19 ---------------
 gas/testsuite/gas/i386/x86-64-lfence-ret.e   |  3 ---
 gas/testsuite/gas/i386/x86-64-lfence-ret.s   |  6 -----
 13 files changed, 6 insertions(+), 182 deletions(-)
 delete mode 100644 gas/testsuite/gas/i386/x86-64-lfence-ret.e

diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index 32fd6c15e1..ae1bd0d5bb 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -4591,13 +4591,10 @@ insert_lfence_before (void)
       return;
     }

-  /* Output or/not/shl and lfence before ret/lret/iret.  */
+  /* Output or/not/shl and lfence before near ret.  */
   if (lfence_before_ret != lfence_before_ret_none
       && (i.tm.base_opcode == 0xc2
-          || i.tm.base_opcode == 0xc3
-          || i.tm.base_opcode == 0xca
-          || i.tm.base_opcode == 0xcb
-          || i.tm.base_opcode == 0xcf))
+          || i.tm.base_opcode == 0xc3))
     {
       if (last_insn.kind != last_insn_other
           && last_insn.seg == now_seg)
@@ -4608,17 +4605,10 @@ insert_lfence_before (void)
           return;
         }

-      /* lret or iret.  */
-      bfd_boolean lret = (i.tm.base_opcode | 0x5) == 0xcf;
-      bfd_boolean has_rexw = i.prefix[REX_PREFIX] & REX_W;
-      char prefix = 0x0;
-      /* Default operand size for far return is 32 bits,
-         64 bits for near return.  */
       /* Near ret ingore operand size override under CPU64.  */
-      if ((!lret && flag_code == CODE_64BIT) || has_rexw)
-        prefix = 0x48;
-      else if (i.prefix[DATA_PREFIX])
-        prefix = 0x66;
+      char prefix = flag_code == CODE_64BIT
+                    ? 0x48
+                    : i.prefix[DATA_PREFIX] ? 0x66 : 0x0;

       if (lfence_before_ret == lfence_before_ret_not)
         {
diff --git a/gas/testsuite/gas/i386/lfence-ret-a.d
b/gas/testsuite/gas/i386/lfence-ret-a.d
index aa35857664..613d1d50a2 100644
--- a/gas/testsuite/gas/i386/lfence-ret-a.d
+++ b/gas/testsuite/gas/i386/lfence-ret-a.d
@@ -21,16 +21,4 @@ Disassembly of section .text:
  +[a-f0-9]+: 83 0c 24 00          orl    \$0x0,\(%esp\)
  +[a-f0-9]+: 0f ae e8              lfence
  +[a-f0-9]+: c2 1e 00              ret    \$0x1e
- +[a-f0-9]+: 66 83 0c 24 00        orw    \$0x0,\(%esp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 66 cb                lretw
- +[a-f0-9]+: 66 83 0c 24 00        orw    \$0x0,\(%esp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 66 ca 28 00          lretw  \$0x28
- +[a-f0-9]+: 83 0c 24 00          orl    \$0x0,\(%esp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: cb                    lret
- +[a-f0-9]+: 83 0c 24 00          orl    \$0x0,\(%esp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: ca 28 00              lret   \$0x28
 #pass
diff --git a/gas/testsuite/gas/i386/lfence-ret-b.d
b/gas/testsuite/gas/i386/lfence-ret-b.d
index 77001c425e..e6dd4f4bf6 100644
--- a/gas/testsuite/gas/i386/lfence-ret-b.d
+++ b/gas/testsuite/gas/i386/lfence-ret-b.d
@@ -25,20 +25,4 @@ Disassembly of section .text:
  +[a-f0-9]+: f7 14 24              notl   \(%esp\)
  +[a-f0-9]+: 0f ae e8              lfence
  +[a-f0-9]+: c2 1e 00              ret    \$0x1e
- +[a-f0-9]+: 66 f7 14 24          notw   \(%esp\)
- +[a-f0-9]+: 66 f7 14 24          notw   \(%esp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 66 cb                lretw
- +[a-f0-9]+: 66 f7 14 24          notw   \(%esp\)
- +[a-f0-9]+: 66 f7 14 24          notw   \(%esp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 66 ca 28 00          lretw  \$0x28
- +[a-f0-9]+: f7 14 24              notl   \(%esp\)
- +[a-f0-9]+: f7 14 24              notl   \(%esp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: cb                    lret
- +[a-f0-9]+: f7 14 24              notl   \(%esp\)
- +[a-f0-9]+: f7 14 24              notl   \(%esp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: ca 28 00              lret   \$0x28
 #pass
diff --git a/gas/testsuite/gas/i386/lfence-ret-c.d
b/gas/testsuite/gas/i386/lfence-ret-c.d
index fceb0eb182..02f57fee70 100644
--- a/gas/testsuite/gas/i386/lfence-ret-c.d
+++ b/gas/testsuite/gas/i386/lfence-ret-c.d
@@ -1,7 +1,7 @@
 #source: lfence-ret.s
 #as: -mlfence-before-ret=or -mlfence-before-indirect-branch=all
 #objdump: -dw
-
+#name -mlfence-before-ret=or -mlfence-before-indirect-branch=all
 .*: +file format .*


@@ -20,16 +20,4 @@ Disassembly of section .text:
  +[a-f0-9]+: 83 0c 24 00          orl    \$0x0,\(%esp\)
  +[a-f0-9]+: 0f ae e8              lfence
  +[a-f0-9]+: c2 1e 00              ret    \$0x1e
- +[a-f0-9]+: 66 83 0c 24 00        orw    \$0x0,\(%esp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 66 cb                lretw
- +[a-f0-9]+: 66 83 0c 24 00        orw    \$0x0,\(%esp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 66 ca 28 00          lretw  \$0x28
- +[a-f0-9]+: 83 0c 24 00          orl    \$0x0,\(%esp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: cb                    lret
- +[a-f0-9]+: 83 0c 24 00          orl    \$0x0,\(%esp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: ca 28 00              lret   \$0x28
 #pass
diff --git a/gas/testsuite/gas/i386/lfence-ret-d.d
b/gas/testsuite/gas/i386/lfence-ret-d.d
index 03f8f88fd7..9078216e53 100644
--- a/gas/testsuite/gas/i386/lfence-ret-d.d
+++ b/gas/testsuite/gas/i386/lfence-ret-d.d
@@ -21,16 +21,4 @@ Disassembly of section .text:
  +[a-f0-9]+: c1 24 24 00          shll   \$0x0,\(%esp\)
  +[a-f0-9]+: 0f ae e8              lfence
  +[a-f0-9]+: c2 1e 00              ret    \$0x1e
- +[a-f0-9]+: 66 c1 24 24 00        shlw   \$0x0,\(%esp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 66 cb                lretw
- +[a-f0-9]+: 66 c1 24 24 00        shlw   \$0x0,\(%esp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 66 ca 28 00          lretw  \$0x28
- +[a-f0-9]+: c1 24 24 00          shll   \$0x0,\(%esp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: cb                    lret
- +[a-f0-9]+: c1 24 24 00          shll   \$0x0,\(%esp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: ca 28 00              lret   \$0x28
 #pass
diff --git a/gas/testsuite/gas/i386/lfence-ret.s
b/gas/testsuite/gas/i386/lfence-ret.s
index f27fa5839e..5de4f08447 100644
--- a/gas/testsuite/gas/i386/lfence-ret.s
+++ b/gas/testsuite/gas/i386/lfence-ret.s
@@ -4,7 +4,3 @@ _start:
  retw $20
  ret
  ret $30
- lretw
- lretw $40
- lret
- lret $40
diff --git a/gas/testsuite/gas/i386/x86-64-lfence-ret-a.d
b/gas/testsuite/gas/i386/x86-64-lfence-ret-a.d
index 345217b17c..96881677b6 100644
--- a/gas/testsuite/gas/i386/x86-64-lfence-ret-a.d
+++ b/gas/testsuite/gas/i386/x86-64-lfence-ret-a.d
@@ -1,6 +1,5 @@
 #source: x86-64-lfence-ret.s
 #as: -mlfence-before-ret=or
-#warning_output: x86-64-lfence-ret.e
 #objdump: -dw -Mintel64
 #name: x86-64 -mlfence-before-ret=or

@@ -28,22 +27,4 @@ Disassembly of section .text:
  +[a-f0-9]+: 48 83 0c 24 00        orq    \$0x0,\(%rsp\)
  +[a-f0-9]+: 0f ae e8              lfence
  +[a-f0-9]+: 66 48 c2 28 00        data16 rex.W retq \$0x28
- +[a-f0-9]+: 66 83 0c 24 00        orw    \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 66 cb                lretw
- +[a-f0-9]+: 66 83 0c 24 00        orw    \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 66 ca 28 00          lretw  \$0x28
- +[a-f0-9]+: 83 0c 24 00          orl    \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: cb                    lret
- +[a-f0-9]+: 83 0c 24 00          orl    \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: ca 28 00              lret   \$0x28
- +[a-f0-9]+: 48 83 0c 24 00        orq    \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 48 cb                lretq
- +[a-f0-9]+: 48 83 0c 24 00        orq    \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 48 ca 28 00          lretq  \$0x28
 #pass
diff --git a/gas/testsuite/gas/i386/x86-64-lfence-ret-b.d
b/gas/testsuite/gas/i386/x86-64-lfence-ret-b.d
index 3947660fea..4afad79bc6 100644
--- a/gas/testsuite/gas/i386/x86-64-lfence-ret-b.d
+++ b/gas/testsuite/gas/i386/x86-64-lfence-ret-b.d
@@ -1,6 +1,5 @@
 #source: x86-64-lfence-ret.s
 #as: -mlfence-before-ret=not
-#warning_output: x86-64-lfence-ret.e
 #objdump: -dw -Mintel64
 #name: x86-64 -mlfence-before-ret=not

@@ -34,28 +33,4 @@ Disassembly of section .text:
  +[a-f0-9]+: 48 f7 14 24          notq   \(%rsp\)
  +[a-f0-9]+: 0f ae e8              lfence
  +[a-f0-9]+: 66 48 c2 28 00        data16 rex.W retq \$0x28
- +[a-f0-9]+: 66 f7 14 24          notw   \(%rsp\)
- +[a-f0-9]+: 66 f7 14 24          notw   \(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 66 cb                lretw
- +[a-f0-9]+: 66 f7 14 24          notw   \(%rsp\)
- +[a-f0-9]+: 66 f7 14 24          notw   \(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 66 ca 28 00          lretw  \$0x28
- +[a-f0-9]+: f7 14 24              notl   \(%rsp\)
- +[a-f0-9]+: f7 14 24              notl   \(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: cb                    lret
- +[a-f0-9]+: f7 14 24              notl   \(%rsp\)
- +[a-f0-9]+: f7 14 24              notl   \(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: ca 28 00              lret   \$0x28
- +[a-f0-9]+: 48 f7 14 24          notq   \(%rsp\)
- +[a-f0-9]+: 48 f7 14 24          notq   \(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 48 cb                lretq
- +[a-f0-9]+: 48 f7 14 24          notq   \(%rsp\)
- +[a-f0-9]+: 48 f7 14 24          notq   \(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 48 ca 28 00          lretq  \$0x28
 #pass
diff --git a/gas/testsuite/gas/i386/x86-64-lfence-ret-c.d
b/gas/testsuite/gas/i386/x86-64-lfence-ret-c.d
index cd89a95bc4..55b0ecb2f0 100644
--- a/gas/testsuite/gas/i386/x86-64-lfence-ret-c.d
+++ b/gas/testsuite/gas/i386/x86-64-lfence-ret-c.d
@@ -1,6 +1,5 @@
 #source: x86-64-lfence-ret.s
 #as: -mlfence-before-ret=or -mlfence-before-indirect-branch=all
-#warning_output: x86-64-lfence-ret.e
 #objdump: -dw -Mintel64

 .*: +file format .*
@@ -27,22 +26,4 @@ Disassembly of section .text:
  +[a-f0-9]+: 48 83 0c 24 00        orq    \$0x0,\(%rsp\)
  +[a-f0-9]+: 0f ae e8              lfence
  +[a-f0-9]+: 66 48 c2 28 00        data16 rex.W retq \$0x28
- +[a-f0-9]+: 66 83 0c 24 00        orw    \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 66 cb                lretw
- +[a-f0-9]+: 66 83 0c 24 00        orw    \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 66 ca 28 00          lretw  \$0x28
- +[a-f0-9]+: 83 0c 24 00          orl    \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: cb                    lret
- +[a-f0-9]+: 83 0c 24 00          orl    \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: ca 28 00              lret   \$0x28
- +[a-f0-9]+: 48 83 0c 24 00        orq    \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 48 cb                lretq
- +[a-f0-9]+: 48 83 0c 24 00        orq    \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 48 ca 28 00          lretq  \$0x28
 #pass
diff --git a/gas/testsuite/gas/i386/x86-64-lfence-ret-d.d
b/gas/testsuite/gas/i386/x86-64-lfence-ret-d.d
index 593b889435..efe928acee 100644
--- a/gas/testsuite/gas/i386/x86-64-lfence-ret-d.d
+++ b/gas/testsuite/gas/i386/x86-64-lfence-ret-d.d
@@ -1,6 +1,5 @@
 #source: x86-64-lfence-ret.s
 #as: -mlfence-before-ret=shl
-#warning_output: x86-64-lfence-ret.e
 #objdump: -dw -Mintel64
 #name: x86-64 -mlfence-before-ret=shl

@@ -28,22 +27,4 @@ Disassembly of section .text:
  +[a-f0-9]+: 48 c1 24 24 00        shlq   \$0x0,\(%rsp\)
  +[a-f0-9]+: 0f ae e8              lfence
  +[a-f0-9]+: 66 48 c2 28 00        data16 rex.W retq \$0x28
- +[a-f0-9]+: 66 c1 24 24 00        shlw   \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 66 cb                lretw
- +[a-f0-9]+: 66 c1 24 24 00        shlw   \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 66 ca 28 00          lretw  \$0x28
- +[a-f0-9]+: c1 24 24 00          shll   \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: cb                    lret
- +[a-f0-9]+: c1 24 24 00          shll   \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: ca 28 00              lret   \$0x28
- +[a-f0-9]+: 48 c1 24 24 00        shlq   \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 48 cb                lretq
- +[a-f0-9]+: 48 c1 24 24 00        shlq   \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 48 ca 28 00          lretq  \$0x28
 #pass
diff --git a/gas/testsuite/gas/i386/x86-64-lfence-ret-e.d
b/gas/testsuite/gas/i386/x86-64-lfence-ret-e.d
index b4d229654c..31286662de 100644
--- a/gas/testsuite/gas/i386/x86-64-lfence-ret-e.d
+++ b/gas/testsuite/gas/i386/x86-64-lfence-ret-e.d
@@ -1,6 +1,5 @@
 #source: x86-64-lfence-ret.s
 #as: -mlfence-before-ret=shl
-#warning_output: x86-64-lfence-ret.e
 #objdump: -dw -Mintel64
 #name: x86-64 -mlfence-before-ret=yes

@@ -28,22 +27,4 @@ Disassembly of section .text:
  +[a-f0-9]+: 48 c1 24 24 00        shlq   \$0x0,\(%rsp\)
  +[a-f0-9]+: 0f ae e8              lfence
  +[a-f0-9]+: 66 48 c2 28 00        data16 rex.W retq \$0x28
- +[a-f0-9]+: 66 c1 24 24 00        shlw   \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 66 cb                lretw
- +[a-f0-9]+: 66 c1 24 24 00        shlw   \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 66 ca 28 00          lretw  \$0x28
- +[a-f0-9]+: c1 24 24 00          shll   \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: cb                    lret
- +[a-f0-9]+: c1 24 24 00          shll   \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: ca 28 00              lret   \$0x28
- +[a-f0-9]+: 48 c1 24 24 00        shlq   \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 48 cb                lretq
- +[a-f0-9]+: 48 c1 24 24 00        shlq   \$0x0,\(%rsp\)
- +[a-f0-9]+: 0f ae e8              lfence
- +[a-f0-9]+: 48 ca 28 00          lretq  \$0x28
 #pass
diff --git a/gas/testsuite/gas/i386/x86-64-lfence-ret.e
b/gas/testsuite/gas/i386/x86-64-lfence-ret.e
deleted file mode 100644
index 13730e50e6..0000000000
--- a/gas/testsuite/gas/i386/x86-64-lfence-ret.e
+++ /dev/null
@@ -1,3 +0,0 @@
-.*: Assembler messages:
-.*:??: Warning: no instruction mnemonic suffix given and no register
operands; using default for `lret'
-.*:??: Warning: no instruction mnemonic suffix given and no register
operands; using default for `lret'
diff --git a/gas/testsuite/gas/i386/x86-64-lfence-ret.s
b/gas/testsuite/gas/i386/x86-64-lfence-ret.s
index 986239c222..dd0961a49c 100644
--- a/gas/testsuite/gas/i386/x86-64-lfence-ret.s
+++ b/gas/testsuite/gas/i386/x86-64-lfence-ret.s
@@ -6,9 +6,3 @@ _start:
  ret $30
  data16 rex.w ret
  data16 rex.w ret $40
- lretw
- lretw $40
- lret
- lret $40
- lretq
- lretq $40
-- 
2.18.1


-- 
BR,
Hongtao


More information about the Binutils mailing list