From: H.J. Lu Date: Tue, 16 Nov 2021 15:21:11 +0000 (-0800) Subject: x86: Don't allow KMOV in TLS code sequences X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d7e3e627027fcf37d63e284144fe27ff4eba36b5;p=binutils-gdb.git x86: Don't allow KMOV in TLS code sequences 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. --- diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c index 320ea7e5185..9674ec4368b 100644 --- a/gas/config/tc-i386.c +++ b/gas/config/tc-i386.c @@ -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) diff --git a/gas/testsuite/gas/i386/i386.exp b/gas/testsuite/gas/i386/i386.exp index 378e32b39cb..864624b170a 100644 --- a/gas/testsuite/gas/i386/i386.exp +++ b/gas/testsuite/gas/i386/i386.exp @@ -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 index 00000000000..dc8a326390c --- /dev/null +++ b/gas/testsuite/gas/i386/inval-tls.l @@ -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 index 00000000000..3fe85c31ff3 --- /dev/null +++ b/gas/testsuite/gas/i386/inval-tls.s @@ -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 index 00000000000..11fa63e459c --- /dev/null +++ b/gas/testsuite/gas/i386/x86-64-inval-tls.l @@ -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 index 00000000000..71e19272ba9 --- /dev/null +++ b/gas/testsuite/gas/i386/x86-64-inval-tls.s @@ -0,0 +1,4 @@ + .text +# All the following should be illegal + kmovq foo@gottpoff(%rip), %k0 + kmovq foo@tlsld(%rip), %k0