[X86] Fix disassembly of x86-64 GDTLS code sequence
authorAndrew Ng <andrew.ng@sony.com>
Wed, 27 Jan 2021 16:47:21 +0000 (16:47 +0000)
committerAndrew Ng <andrew.ng@sony.com>
Tue, 2 Feb 2021 11:35:00 +0000 (11:35 +0000)
For x86-64 the REX.w prefix takes precedence over any other size
override (i.e. 0x66). Therefore, for x86-64 when REX.w is present set
'hasOpSize' to false to ensure that any size override is ignored.

Fixes PR48901.

Differential Revision: https://reviews.llvm.org/D95682

llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp
llvm/test/MC/Disassembler/X86/x86-64.txt
llvm/test/tools/llvm-objdump/X86/disassemble-gdtls.s [new file with mode: 0644]

index 05e482a..4e6d8e8 100644 (file)
@@ -492,6 +492,7 @@ static int readPrefixes(struct InternalInstruction *insn) {
       insn->addressSize = (insn->hasAdSize ? 4 : 8);
       insn->displacementSize = 4;
       insn->immediateSize = 4;
+      insn->hasOpSize = false;
     } else {
       insn->registerSize = (insn->hasOpSize ? 2 : 4);
       insn->addressSize = (insn->hasAdSize ? 4 : 8);
index d91ef25..5e56d4c 100644 (file)
 # CHECK: callw 32767
 0x66 0xe8 0xff 0x7f
 
-# CHECK: callw 32767
-0x66 0x66 0x48 0xe8 0xff 0x7f
+# TODO: Should display data16 prefixes.
+# CHECK-NOT: data16
+# CHECK: callq 32767
+0x66 0x66 0x48 0xe8 0xff 0x7f 0x00 0x00
 
 # CHECK: jmp -32769
 0xe9 0xff 0x7f 0xff 0xff
 # CHECK: jmp 32767
 0x66 0xe9 0xff 0x7f
 
+# TODO: Should display data16 prefixes.
+# CHECK-NOT: data16
 # CHECK: jmp 32767
-0x66 0x66 0x48 0xe9 0xff 0x7f
+0x66 0x66 0x48 0xe9 0xff 0x7f 0x00 0x00
 
 # CHECK: jo -32769
 0x0f 0x80 0xff 0x7f 0xff 0xff
diff --git a/llvm/test/tools/llvm-objdump/X86/disassemble-gdtls.s b/llvm/test/tools/llvm-objdump/X86/disassemble-gdtls.s
new file mode 100644 (file)
index 0000000..e913f5f
--- /dev/null
@@ -0,0 +1,19 @@
+# RUN: llvm-mc %s -filetype=obj -triple=x86_64 | llvm-objdump -d - | FileCheck %s
+
+# CHECK:      <PR48901>:
+# TODO: Should display data16 prefixes.
+# CHECK-NEXT: 0: 66 48 8d 3d 00 00 00 00       leaq    (%rip), %rdi  # 8 <PR48901+0x8>
+# CHECK-NEXT: 8: 66 66 48 e8 00 00 00 00       callq   0x10 <PR48901+0x10>
+# CHECK-EMPTY:
+
+PR48901:
+ data16
+ leaq   bar@TLSGD(%rip),%rdi
+ data16
+ data16
+ rex64
+ callq  __tls_get_addr@PLT
+
+.section .tdata,"awT",@progbits
+bar:
+.long 42