fix(relinker): decode near branches with an operand-size prefix as AMD does

66 E8, 66 E9 and 66 0F 80-8F without REX.W take a 16-bit displacement on
AMD processors, the console included. Every near relative branch with that
prefix truncates its target to 16 bits, so the decoder reports no branch
target for it and stubs refuse to move it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016TFMtUC4L4wMS4eeEqaNSR
This commit is contained in:
oskarlgsandClaude Opus 5.5 committed 2026-10-17 20:58:29 +00:00
1 parent 922dc8999e
commit 206aaa56cb
7 files changed
+71 -3

No files matched your search

@@ -99,6 +99,20 @@ int main() {
require(info.HasBranchTarget == testCase.HasBranchTarget, "Wrong branch target presence for " + name);
require(!testCase.HasBranchTarget || info.BranchDisp == testCase.BranchDisp, "Wrong branch displacement for " + name);
}
for (const auto& testCase : kDecoderTruncatedBranchCases) {
const std::string name = testCase.Bytes;
auto bytes = parse(testCase.Bytes);
require(bytes.size() == testCase.Length, "Truncated branch case " + name + " does not hold its own length");
bytes.insert(bytes.end(), 15, 0x90);
const auto info = decoder.DecodeInstruction(bytes.data(), bytes.size());
require(info.Length == testCase.Length, "Wrong length for " + name);
require(info.FlowKind == testCase.FlowKind, "Wrong control flow kind for " + name);
require(info.TruncatesBranchTarget && !info.HasBranchTarget, "Branch target of " + name + " was reported without its 16-bit truncation");
}
for (const auto& testCase : kDecoderBranchCases) {
const auto bytes = parse(testCase.Bytes);
require(!decoder.DecodeInstruction(bytes.data(), bytes.size()).TruncatesBranchTarget, "Branch target of " + std::string(testCase.Bytes) + " was reported as truncated");
}
const auto threeDNow = parse("0f0f0d11223344a6");
const auto threeDNowInfo = decoder.DecodeInstruction(threeDNow.data(), threeDNow.size());
require(threeDNowInfo.HasModRm && threeDNowInfo.ModRmByte == 0x0d, "3DNow! ModRM was not reported");