This is an archive of the discontinued LLVM Phabricator instance.

[llvm-mc] Fix bad sign extension on callw immediate
ClosedPublic

Authored by m4b on May 5 2015, 10:32 PM.

Details

Summary

An instruction sequence like 0x66 0xe8 0x59 0xcf was incorrectly disassembled due to a missing TYPE_REL16 in the translateImmediate type switch, and resulted in a signed short relative immediate in callw, like 0xcf59, to disassemble to 53081 instead of -12455.

Diff Detail

Repository
rL LLVM

Event Timeline

m4b updated this revision to Diff 25009.May 5 2015, 10:32 PM
m4b retitled this revision from to [llvm-mc] Fix bad sign extension on callw immediate.
m4b updated this object.
m4b edited the test plan for this revision. (Show Details)
m4b added a reviewer: dougk.
m4b set the repository for this revision to rL LLVM.
m4b added a subscriber: Unknown Object (MLST).
dougk accepted this revision.May 7 2015, 9:05 AM
dougk edited edge metadata.

add test please, perhaps next to the 'callw' test in test/MC/Disassembler/X86/x86-16.txt

This revision is now accepted and ready to land.May 7 2015, 9:05 AM
m4b added a comment.EditedMay 7 2015, 12:47 PM

I added the unit tests as a separate commit; I was unsure what the protocol is in this case. Just in case, I've added the same diff in this comment.

diff --git a/test/MC/Disassembler/X86/x86-32.txt b/test/MC/Disassembler/X86/x86-32.txt
index 830b830..aaf9e5b 100644
--- a/test/MC/Disassembler/X86/x86-32.txt
+++ b/test/MC/Disassembler/X86/x86-32.txt
@@ -54,6 +54,12 @@
 # CHECK: calll -1234
 0xe8 0x2e 0xfb 0xff 0xff
 
+# CHECK: callw -1
+0x66 0xe8 0xff 0xff
+
+# CHECK: callw 32767
+0x66 0xe8 0xff 0x7f
+
 # CHECK: lfence
 0x0f 0xae 0xe8
 
diff --git a/test/MC/Disassembler/X86/x86-64.txt b/test/MC/Disassembler/X86/x86-64.txt
index f000d15..3088619 100644
--- a/test/MC/Disassembler/X86/x86-64.txt
+++ b/test/MC/Disassembler/X86/x86-64.txt
@@ -301,3 +301,9 @@
 
 # CHECK: movq %rax, 1515870810
 0x67, 0x48 0xa3 0x5a 0x5a 0x5a 0x5a
+
+# CHECK: callq -32769
+0xe8 0xff 0x7f 0xff 0xff
+
+# CHECK: callq 32767
+0xe8 0xff 0x7f 0x00 0x00
m4b updated this revision to Diff 25251.May 7 2015, 3:15 PM
m4b edited edge metadata.

added unit tests for 16, 32, and 64 bit CALL disassembly.

m4b updated this revision to Diff 25336.May 8 2015, 8:46 AM

[llvm-mc] final commit with unit tests and callw fix for 32-bit mode

*ping* This patch has been sitting for over a month. I don't have push rights; someone else needs to land it.

Sorry, didn't know you didn't have commit. I'll do this.

This revision was automatically updated to reflect the committed changes.