Repository navigation
Description
TL;DR:
GetILToNativeMapping2ignores the requested ReJIT version and uses the method's default version instead. A profiler gets the wrong map, orE_INVALIDARGif the default version was never compiled. The proposed fix stores the looked-up version and returnsE_INVALIDARGfor a ReJIT ID that matches no version.
Description
ProfToEEInterfaceImpl::GetILToNativeMapping2 looks up the IL code version for reJitId but discards the result (proftoeeinterfaceimpl.cpp#L4919-L4921):
ILCodeVersion ilCodeVersion = NULL;
{
pCodeVersionManager->GetILCodeVersion(pMD, reJitId);
NativeCodeVersionCollection nativeCodeVersions = ilCodeVersion.GetNativeCodeVersions(pMD);ilCodeVersion stays null. For a null IL version filter, the native code version iterator yields the method's default native code version first (codeversion.cpp#L494-L501). GetILToNativeMapping2 takes that first result and stops (proftoeeinterfaceimpl.cpp#L4923-L4930). GetNativeCodeStartAddresses, also in proftoeeinterfaceimpl.cpp, assigns the result as intended (proftoeeinterfaceimpl.cpp#L6437):
ilCodeVersion = pCodeVersionManager->GetILCodeVersion(pMD, reJitId);reJitId 0 still works, because the default version is the right answer for it. Any other reJitId is affected.
Reproduction Steps
I tested two independent cases on Microsoft.NETCore.App 10.0.13, linux-x64, with a test profiler:
- A method whose default version is compiled is then ReJIT'd (
ReJITCompilationFinishedreports reJitId 2). In my run the ReJIT came from a debugger callingICorDebugFunction5::DisableOptimizations.GetILToNativeMapping2(functionId, 2)returned the same map asGetILToNativeMapping(functionId).GetNativeCodeStartAddresses(functionId, 2)returned one start address. Passing that address toGetILToNativeMapping3returned the ReJIT version's map, which differed from the map returned byGetILToNativeMapping2. - A method is ReJIT'd with
RequestReJITbefore its first call, so its default version is never compiled.GetNativeCodeStartAddresses(functionId, 2)returned one start address, andGetILToNativeMapping3on it worked.GetILToNativeMapping2(functionId, 2)returnedE_INVALIDARG(0x80070057).
I can share a standalone profiler and app on request.
Expected behavior
As the documentation says, GetILToNativeMapping2 returns the map "for the code contained in the JIT-recompiled version of the specified function": for a nonzero reJitId, the map of that ReJIT version's code. For a reJitId that matches no ReJIT version of the function, it should return E_INVALIDARG.
Actual behavior
It returns the map of the default version's code, or E_INVALIDARG if the default version has no code.
Regression?
Not a recent regression. The same dropped assignment is on release/8.0, release/9.0, release/10.0 and main.
Known Workarounds
Call GetNativeCodeStartAddresses(functionId, reJitId) and pass a returned address to GetILToNativeMapping3.
Other information
The proposed fix stores the result, and looks for native code only when an IL version was found:
ILCodeVersion ilCodeVersion = pCodeVersionManager->GetILCodeVersion(pMD, reJitId);
if (!ilCodeVersion.IsNull())
{
// the existing loop over ilCodeVersion.GetNativeCodeVersions(pMD)
}The assignment alone is not enough. A reJitId that matches no IL version would still leave ilCodeVersion null, and the method would still fall back to the default version. With the check, pCodeStart stays null, and GetILToNativeMapping3 returns E_INVALIDARG for a null start address (proftoeeinterfaceimpl.cpp#L6518-L6521). An unknown reJitId then returns E_INVALIDARG even when the default version has compiled code.
Note
This report was prepared with AI assistance (Anthropic Claude and OpenAI Codex) under my direction. AI agents ran the repro and read the sources on my machine. I reviewed the text before posting.
Activity
dotnet-policy-service commentedon Oct 29, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
dotnet-policy-service commentedon Oct 30, 2026
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.
Fix GetILToNativeMapping2 ignoring its reJitId (dotnet#136678)