Skip to content

ICorProfilerInfo4::GetILToNativeMapping2 ignores its reJitId argument #136669

Closed

Description

@pcshrosbree

TL;DR: GetILToNativeMapping2 ignores the requested ReJIT version and uses the method's default version instead. A profiler gets the wrong map, or E_INVALIDARG if the default version was never compiled. The proposed fix stores the looked-up version and returns E_INVALIDARG for 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:

  1. A method whose default version is compiled is then ReJIT'd (ReJITCompilationFinished reports reJitId 2). In my run the ReJIT came from a debugger calling ICorDebugFunction5::DisableOptimizations. GetILToNativeMapping2(functionId, 2) returned the same map as GetILToNativeMapping(functionId). GetNativeCodeStartAddresses(functionId, 2) returned one start address. Passing that address to GetILToNativeMapping3 returned the ReJIT version's map, which differed from the map returned by GetILToNativeMapping2.
  2. A method is ReJIT'd with RequestReJIT before its first call, so its default version is never compiled. GetNativeCodeStartAddresses(functionId, 2) returned one start address, and GetILToNativeMapping3 on it worked. GetILToNativeMapping2(functionId, 2) returned E_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

  1. added
    untriaged
    on Oct 29, 2026
  2. added
    area-CodeGen-coreclr
    on Oct 29, 2026
  3. dotnet-policy-service commented on Oct 29, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
    See info in area-owners.md if you want to be subscribed.

  4. added and removed
    area-CodeGen-coreclr
    on Oct 30, 2026
  5. dotnet-policy-service commented on Oct 30, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
    See info in area-owners.md if you want to be subscribed.

  6. removed
    untriaged
    on Nov 6, 2026
  7. added a commit that references this issue on Nov 6, 2026
    c3da97e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions