x86: Don't allow KMOV in TLS code sequences
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 16 Nov 2021 15:21:11 +0000 (07:21 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 16 Nov 2021 15:34:46 +0000 (07:34 -0800)
Don't allow KMOV in TLS code sequences which require integer MOV
instructions.

PR target/28595
* config/tc-i386.c (match_template): Don't allow KMOV in TLS
code sequences.
* testsuite/gas/i386/i386.exp: Run inval-tls and x86-64-inval-tls
tests.
* testsuite/gas/i386/inval-tls.l: New file.
* testsuite/gas/i386/inval-tls.s: Likewise.
* testsuite/gas/i386/x86-64-inval-tls.l: Likewise.
* testsuite/gas/i386/x86-64-inval-tls.s: Likewise.

gas/config/tc-i386.c
gas/testsuite/gas/i386/i386.exp
gas/testsuite/gas/i386/inval-tls.l [new file with mode: 0644]
gas/testsuite/gas/i386/inval-tls.s [new file with mode: 0644]
gas/testsuite/gas/i386/x86-64-inval-tls.l [new file with mode: 0644]
gas/testsuite/gas/i386/x86-64-inval-tls.s [new file with mode: 0644]

index 320ea7e5185dbe8bcac25e0091a753e5ff1524da..9674ec4368b4d4c34e319db5adde4222ded70511 100644 (file)
@@ -6639,11 +6639,25 @@ match_template (char mnem_suffix)
            }
        }
 
-      /* Force 0x8b encoding for "mov foo@GOT, %eax".  */
-      if (i.reloc[0] == BFD_RELOC_386_GOT32
-         && t->base_opcode == 0xa0
-         && t->opcode_modifier.opcodespace == SPACE_BASE)
-       continue;
+      switch (i.reloc[0])
+       {
+       case BFD_RELOC_386_GOT32:
+         /* Force 0x8b encoding for "mov foo@GOT, %eax".  */
+         if (t->base_opcode == 0xa0
+             && t->opcode_modifier.opcodespace == SPACE_BASE)
+           continue;
+         break;
+       case BFD_RELOC_386_TLS_GOTIE:
+       case BFD_RELOC_386_TLS_LE_32:
+       case BFD_RELOC_X86_64_GOTTPOFF:
+       case BFD_RELOC_X86_64_TLSLD:
+         /* Don't allow KMOV in TLS code sequences.  */
+         if (t->opcode_modifier.vex)
+           continue;
+         break;
+       default:
+         break;
+       }
 
       /* We check register size if needed.  */
       if (t->opcode_modifier.checkregsize)
index 378e32b39cb71ab67221e120a2aee17edaa7af46..864624b170a84a48defb3c0ba77842b94dab4612 100644 (file)
@@ -616,6 +616,7 @@ if [gas_32_check] then {
        run_dump_test "tlsd"
        run_dump_test "tlspic"
        run_dump_test "tlsnopic"
+       run_list_test "inval-tls"
        run_dump_test "bss"
        run_dump_test "reloc32"
        run_list_test "reloc32" "--defsym _bad_=1"
@@ -1276,6 +1277,7 @@ if [gas_64_check] then {
 
        run_dump_test "reloc64"
        run_list_test "reloc64" "--defsym _bad_=1"
+       run_list_test "x86-64-inval-tls"
        run_dump_test "mixed-mode-reloc64"
        run_dump_test "rela"
        run_dump_test "x86-64-ifunc"
diff --git a/gas/testsuite/gas/i386/inval-tls.l b/gas/testsuite/gas/i386/inval-tls.l
new file mode 100644 (file)
index 0000000..dc8a326
--- /dev/null
@@ -0,0 +1,3 @@
+.*: Assembler messages:
+.*:3: Error: operand size mismatch for `kmovd'
+.*:4: Error: operand size mismatch for `kmovd'
diff --git a/gas/testsuite/gas/i386/inval-tls.s b/gas/testsuite/gas/i386/inval-tls.s
new file mode 100644 (file)
index 0000000..3fe85c3
--- /dev/null
@@ -0,0 +1,4 @@
+       .text
+# All the following should be illegal
+       kmovd   foo@gotntpoff(%eax), %k0
+       kmovd   foo@tpoff(%eax), %k0
diff --git a/gas/testsuite/gas/i386/x86-64-inval-tls.l b/gas/testsuite/gas/i386/x86-64-inval-tls.l
new file mode 100644 (file)
index 0000000..11fa63e
--- /dev/null
@@ -0,0 +1,3 @@
+.*: Assembler messages:
+.*:3: Error: operand size mismatch for `kmovq'
+.*:4: Error: operand size mismatch for `kmovq'
diff --git a/gas/testsuite/gas/i386/x86-64-inval-tls.s b/gas/testsuite/gas/i386/x86-64-inval-tls.s
new file mode 100644 (file)
index 0000000..71e1927
--- /dev/null
@@ -0,0 +1,4 @@
+       .text
+# All the following should be illegal
+       kmovq   foo@gottpoff(%rip), %k0
+       kmovq   foo@tlsld(%rip), %k0