Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -1073,9 +1073,9 @@ public static bool MethodILIsStripped(string msilFilePath, string declaringType,
if (!TryGetMethodIL(msilFilePath, declaringType, methodName, out byte[] il, out diagnostic))
return false;

bool stripped = il.AsSpan().SequenceEqual((ReadOnlySpan<byte>)[0x14, 0x7A]);
bool stripped = il.AsSpan().SequenceEqual((ReadOnlySpan<byte>)[0xFE, 0x24]);
diagnostic = stripped
? $"IL of '{declaringType}.{methodName}' is stripped (ldnull; throw)."
? $"IL of '{declaringType}.{methodName}' is stripped (invalid opcode 0xFE 0x24)."
: $"Expected IL of '{declaringType}.{methodName}' to be stripped, but it is present ({il.Length} bytes: {BitConverter.ToString(il)}).";
return stripped;
}
Expand All @@ -1088,10 +1088,10 @@ public static bool MethodILIsPresent(string msilFilePath, string declaringType,
if (!TryGetMethodIL(msilFilePath, declaringType, methodName, out byte[] il, out diagnostic))
return false;

bool present = !il.AsSpan().SequenceEqual((ReadOnlySpan<byte>)[0x14, 0x7A]);
bool present = !il.AsSpan().SequenceEqual((ReadOnlySpan<byte>)[0xFE, 0x24]);
diagnostic = present
? $"IL of '{declaringType}.{methodName}' is present ({il.Length} bytes)."
: $"Expected IL of '{declaringType}.{methodName}' to be present, but it was stripped (ldnull; throw).";
: $"Expected IL of '{declaringType}.{methodName}' to be present, but it was stripped (invalid opcode 0xFE 0x24).";
return present;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ namespace ILCompiler.DependencyAnalysis.ReadyToRun
{
public class CopiedMethodILNode : ObjectNode, ISymbolDefinitionNode
{
// Throws NullReferenceException if the stripped body is encountered.
// Tiny header (0x0A: 2 bytes code size) + ldnull (0x14) + throw (0x7A).
private static readonly byte[] s_minimalILBody = [0x0A, 0x14, 0x7A];
// Sentinel body for stripped IL methods: tiny header (0x0A) + invalid opcode 0xFE 0x24.
// Invalid IL so it can never collide with a real method body.
private static readonly byte[] s_minimalILBody = [0x0A, 0xFE, 0x24];
Comment thread
kotlarmilos marked this conversation as resolved.
Comment thread
kotlarmilos marked this conversation as resolved.

EcmaMethod _method;

Expand Down
11 changes: 11 additions & 0 deletions src/coreclr/vm/prestub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,17 @@ namespace
if (status == COR_ILMETHOD_DECODER::FORMAT_ERROR)
COMPlusThrowHR(COR_E_BADIMAGEFORMAT, BFA_BAD_IL);

Module* pModule = pMD->GetModule();
if (pModule->IsReadyToRun()
&& pModule->GetReadyToRunInfo()->HasStrippedILBodies()
&& pHeader->GetCodeSize() == 2
&& pHeader->Code[0] == 0xFE
&& pHeader->Code[1] == 0x24)
{
EEPOLICY_HANDLE_FATAL_ERROR_WITH_MESSAGE(COR_E_EXECUTIONENGINE,
W("A method body required at runtime was stripped from the ReadyToRun image."));
}

return pHeader;
}

Expand Down