[llvm-branch-commits] [llvm] b15f3fc - [X86] Fix disassembly of x86-64 GDTLS code sequence

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Feb 3 14:17:18 PST 2021


Author: Andrew Ng
Date: 2021-02-03T14:16:46-08:00
New Revision: b15f3fc5c71dc8a9db7e931e2922a065293e4a64

URL: https://github.com/llvm/llvm-project/commit/b15f3fc5c71dc8a9db7e931e2922a065293e4a64
DIFF: https://github.com/llvm/llvm-project/commit/b15f3fc5c71dc8a9db7e931e2922a065293e4a64.diff

LOG: [X86] Fix disassembly of x86-64 GDTLS code sequence

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

(cherry picked from commit 94fedd266125a5425aa33e11332bf414f0b6dc35)

Added: 
    llvm/test/tools/llvm-objdump/X86/disassemble-gdtls.s

Modified: 
    llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp
    llvm/test/MC/Disassembler/X86/x86-64.txt

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp b/llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp
index 05e482a6b66e..4e6d8e8e1a54 100644
--- a/llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp
+++ b/llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp
@@ -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);

diff  --git a/llvm/test/MC/Disassembler/X86/x86-64.txt b/llvm/test/MC/Disassembler/X86/x86-64.txt
index d91ef2500d99..5e56d4c796e6 100644
--- a/llvm/test/MC/Disassembler/X86/x86-64.txt
+++ b/llvm/test/MC/Disassembler/X86/x86-64.txt
@@ -329,8 +329,10 @@
 # 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
@@ -338,8 +340,10 @@
 # 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
index 000000000000..e913f5f6a345
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/X86/disassemble-gdtls.s
@@ -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 at TLSGD(%rip),%rdi
+ data16
+ data16
+ rex64
+ callq  __tls_get_addr at PLT
+
+.section .tdata,"awT", at progbits
+bar:
+.long 42


        


More information about the llvm-branch-commits mailing list