Skip to content

Commit

Permalink
SPMI: Hacky workaround for coredistools unsupported instructions (#91668
Browse files Browse the repository at this point in the history
)

We currently are unable to get SPMI diffs for methods that use ldapur
instructions as our current coredistools does not support this
instruction. While we wait for coredistools to be updated (this was
blocked on some C++ lib issues) here is a hacky temporary workaround for
the problem. It rewrites ldapur* instructions into the corresponding
ldur* instruction before passing it to the near differ.
  • Loading branch information
jakobbotsch committed Sep 13, 2023
1 parent a11628c commit 3eddabc
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/coreclr/tools/superpmi/superpmi/neardiffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,45 @@ bool NearDiffer::compare(MethodContext* mc, CompileResult* cr1, CompileResult* c
orig_roDataBlock_2 = (void*)((size_t)orig_hotCodeBlock_2 + nativeSizeOfCode_2);
hotCodeSize_2 = nativeSizeOfCode_2;
}

auto rewriteUnsupportedInstrs = [](unsigned char* bytes, size_t numBytes) {
for (size_t i = 0; i < numBytes; i += 4)
{
uint32_t inst;
memcpy(&inst, &bytes[i], 4);

const uint32_t ldapurMask = 0b00111111111000000000110000000000;
const uint32_t ldapurBits = 0b00011001010000000000000000000000;
const uint32_t ldurBits = 0b00111000010000000000000000000000;

const uint32_t stlurMask = 0b00111111111000000000110000000000;
const uint32_t stlurBits = 0b00011001000000000000000000000000;
const uint32_t sturBits = 0b00111000000000000000000000000000;
if ((inst & ldapurMask) == ldapurBits)
{
inst ^= (ldapurBits ^ ldurBits);
memcpy(&bytes[i], &inst, 4);
}
else if ((inst & stlurMask) == stlurBits)
{
inst ^= (stlurBits ^ sturBits);
memcpy(&bytes[i], &inst, 4);
}
}
};

// As of 2023-09-13, our coredistools does not support stlur/ldapur
// instructions, so we rewrite them into supported stur/ldur
// instructions before passing them to the near differ. This means we
// will miss diffs when changing stlur<->stur and ldapur<->ldur,
// but this is better than the decode failure that otherwise results
// (which shows up as a zero-sized diff unconditionally).
// This code should be removed once a new coredistools is compiled that
// supports new instructions.
rewriteUnsupportedInstrs(hotCodeBlock_1, hotCodeSize_1);
rewriteUnsupportedInstrs(coldCodeBlock_1, coldCodeSize_1);
rewriteUnsupportedInstrs(hotCodeBlock_2, hotCodeSize_2);
rewriteUnsupportedInstrs(coldCodeBlock_2, coldCodeSize_2);
}

LogDebug("HCS1 %d CCS1 %d RDS1 %d xcpnt1 %d flag1 %08X, HCB %p CCB %p RDB %p ohcb %p occb %p odb %p", hotCodeSize_1,
Expand Down

0 comments on commit 3eddabc

Please sign in to comment.