Skip to content

[X86] Ignore REX prefixes not immediately before opcode #117299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,14 @@ static int readPrefixes(struct InternalInstruction *insn) {
break;
}

if (isREX(insn, byte)) {
insn->rexPrefix = byte;
isPrefix = true;
LLVM_DEBUG(dbgs() << format("Found REX prefix 0x%hhx", byte));
} else if (isPrefix) {
insn->rexPrefix = 0;
}

if (isPrefix)
LLVM_DEBUG(dbgs() << format("Found prefix 0x%hhx", byte));
}
Expand Down Expand Up @@ -506,11 +514,6 @@ static int readPrefixes(struct InternalInstruction *insn) {
LLVM_DEBUG(dbgs() << format("Found REX2 prefix 0x%hhx 0x%hhx",
insn->rex2ExtensionPrefix[0],
insn->rex2ExtensionPrefix[1]));
} else if (isREX(insn, byte)) {
if (peek(insn, nextByte))
return -1;
insn->rexPrefix = byte;
LLVM_DEBUG(dbgs() << format("Found REX prefix 0x%hhx", byte));
} else
--insn->readerCursor;

Expand Down
6 changes: 6 additions & 0 deletions llvm/test/MC/Disassembler/X86/x86-64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -770,3 +770,9 @@

# CHECK: prefetchit1 (%rip)
0x0f,0x18,0x35,0x00,0x00,0x00,0x00

# Check that we correctly ignore a REX prefix that is not immediately before
# the opcode. REX prefixes not immediately preceding the Opcode are ignored
# according to Section 2.2.1 of the Intel 64 Architecture Manual.
# CHECK: orw $25659, %ax
0x66 0x4c 0x64 0x0d 0x3b 0x64
Loading