[binutils-gdb] x86: Allow R_386_TLS_LE_32 with KMOVD

H.J. Lu hjl@sourceware.org
Tue Aug 27 20:21:20 GMT 2024


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d660d20c0ce197fc195f3f5ac1c908009b520c7e

commit d660d20c0ce197fc195f3f5ac1c908009b520c7e
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Aug 27 05:58:32 2024 -0700

    x86: Allow R_386_TLS_LE_32 with KMOVD
    
    Since there is no TLS IE transition, allow R_386_TLS_LE_32 with KMOVD.
    
    gas/
    
            PR gas/28595
            * config/tc-i386.c (i386_assemble): Remove BFD_RELOC_386_TLS_LE_32
            from TLS code check.
            * testsuite/gas/i386/inval-tls.s: Remove foo@tpoff(%eax).
            * testsuite/gas/i386/inval-tls.l: Updated.
    
    ld/
    
            PR gas/28595
            * testsuite/ld-i386/i386.exp: Run tlsle1.
            * testsuite/ld-i386/tlsle1.d: New file.
            * testsuite/ld-i386/tlsle1.s: Likewise.
    
    Signed-off-by: H.J. Lu <hjl.tools@gmail.com>

Diff:
---
 gas/config/tc-i386.c               |  4 ++--
 gas/testsuite/gas/i386/inval-tls.l |  1 -
 gas/testsuite/gas/i386/inval-tls.s |  1 -
 ld/testsuite/ld-i386/i386.exp      |  1 +
 ld/testsuite/ld-i386/tlsle1.d      | 16 ++++++++++++++++
 ld/testsuite/ld-i386/tlsle1.s      | 14 ++++++++++++++
 6 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index ad68ba9322d..20dcb38919e 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -6578,13 +6578,13 @@ i386_assemble (char *line)
 	  return;
 	}
 
-      /* Don't allow e.g. KMOV in TLS code sequences.  */
+      /* Don't allow e.g. KMOV in TLS code sequences which will trigger
+	 linker error later.  */
       for (j = i.imm_operands; j < i.operands; ++j)
 	switch (i.reloc[j])
 	  {
 	  case BFD_RELOC_X86_64_GOTTPOFF:
 	  case BFD_RELOC_386_TLS_GOTIE:
-	  case BFD_RELOC_386_TLS_LE_32:
 	  case BFD_RELOC_X86_64_TLSLD:
 	    as_bad (_("TLS relocation cannot be used with `%s'"), insn_name (&i.tm));
 	    return;
diff --git a/gas/testsuite/gas/i386/inval-tls.l b/gas/testsuite/gas/i386/inval-tls.l
index 59e7c30f46f..907e80610a8 100644
--- a/gas/testsuite/gas/i386/inval-tls.l
+++ b/gas/testsuite/gas/i386/inval-tls.l
@@ -1,3 +1,2 @@
 .*: Assembler messages:
 .*:3: Error: .* `kmovd'
-.*:4: Error: .* `kmovd'
diff --git a/gas/testsuite/gas/i386/inval-tls.s b/gas/testsuite/gas/i386/inval-tls.s
index 3fe85c31ff3..ba0e1b81dc9 100644
--- a/gas/testsuite/gas/i386/inval-tls.s
+++ b/gas/testsuite/gas/i386/inval-tls.s
@@ -1,4 +1,3 @@
 	.text
 # All the following should be illegal
 	kmovd	foo@gotntpoff(%eax), %k0
-	kmovd	foo@tpoff(%eax), %k0
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index adc88e42ad8..6f97f5daa23 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -314,6 +314,7 @@ run_dump_test "tlsie2"
 run_dump_test "tlsie3"
 run_dump_test "tlsie4"
 run_dump_test "tlsie5"
+run_dump_test "tlsle1"
 run_dump_test "hidden1"
 run_dump_test "hidden2"
 run_dump_test "hidden3"
diff --git a/ld/testsuite/ld-i386/tlsle1.d b/ld/testsuite/ld-i386/tlsle1.d
new file mode 100644
index 00000000000..d304e7b5170
--- /dev/null
+++ b/ld/testsuite/ld-i386/tlsle1.d
@@ -0,0 +1,16 @@
+#name: TLS LE with kmovd
+#as: --32
+#ld: -melf_i386
+#objdump: -dw
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+0+8049000 <_start>:
+ +[a-f0-9]+:	65 c4 e1 f9 90 05 04 00 00 00 	kmovd  %gs:0x4,%k0
+ +[a-f0-9]+:	c4 e1 f9 90 80 04 00 00 00 	kmovd  0x4\(%eax\),%k0
+ +[a-f0-9]+:	65 c4 e1 f9 90 05 fc ff ff ff 	kmovd  %gs:0xfffffffc,%k0
+ +[a-f0-9]+:	c4 e1 f9 90 80 fc ff ff ff 	kmovd  -0x4\(%eax\),%k0
+#pass
diff --git a/ld/testsuite/ld-i386/tlsle1.s b/ld/testsuite/ld-i386/tlsle1.s
new file mode 100644
index 00000000000..283b903aa2f
--- /dev/null
+++ b/ld/testsuite/ld-i386/tlsle1.s
@@ -0,0 +1,14 @@
+	.text
+	.globl _start
+_start:
+	kmovd %gs:foo@tpoff,%k0
+	kmovd foo@tpoff(%eax),%k0
+	kmovd %gs:foo@ntpoff,%k0
+	kmovd foo@ntpoff(%eax),%k0
+	.globl foo
+	.section	.tdata,"awT",@progbits
+	.align 4
+	.type	foo, @object
+	.size	foo, 4
+foo:
+	.long	100


More information about the Binutils-cvs mailing list