Skip to content

NativeAOT'd il2cpp.exe random crashing on Windows x64. #121632

Closed

Description

@mrvoorhe

Description

While looking for a different instability, someone internally found that we are occasionally seeing the nativeaot'd il2cpp executable crash on Windows x64. The crash seems rare. We don't have reproduction steps yet. We will spend some time trying to reproduce. If we get more information I'll update the issue.

The info we do have is a crash dump. Here is some info from the dump.

il2cpp.exe!RhpInterfaceDispatch4() Line 68
	at D:\a\_work\1\s\src\coreclr\nativeaot\Runtime\amd64\StubDispatch.asm(68)
il2cpp.exe!Unity_IL2CPP_DataModel_Unity_IL2CPP_DataModel_CustomAttributeProviderExtensions__HasAttribute() Line 7
	at C:\build\output\unity\il2cpp\Unity.IL2CPP.DataModel\CustomAttributeProviderExtensions.cs(7)
il2cpp.exe!Unity_IL2CPP_Unity_IL2CPP_AssemblyConversion_PrimaryCollection_Steps_Global_AnalyticsCollection__ProcessItem() Line 37
	at C:\build\output\unity\il2cpp\Unity.IL2CPP\AssemblyConversion\PrimaryCollection\Steps.Global\AnalyticsCollection.cs(37)
il2cpp.exe!Unity_IL2CPP_Unity_IL2CPP_AssemblyConversion_Steps_Base_ScheduledItemsStepFunc_5<System___Canon__System___Canon__System___Canon__System___Canon__System___Canon>__WorkerWrapper() Line 45
	at C:\build\output\unity\il2cpp\Unity.IL2CPP\AssemblyConversion\Steps.Base\ScheduledItemsStepFunc.cs(45)
il2cpp.exe!Unity_IL2CPP_Unity_IL2CPP_Contexts_Scheduling_PhaseWorkScheduler_1_ContinueWithResultsWorkItem_4<System___Canon__System___Canon__System___Canon__System___Canon__System___Canon>__InvokeWorker() Line 620
	at C:\build\output\unity\il2cpp\Unity.IL2CPP\Contexts.Scheduling\PhaseWorkScheduler.cs(620)
il2cpp.exe!Unity_IL2CPP_Unity_IL2CPP_Contexts_Scheduling_PhaseWorkScheduler_1_BaseContinueWorkItem_2<System___Canon__System___Canon__System___Canon>__Invoke() Line 534
	at C:\build\output\unity\il2cpp\Unity.IL2CPP\Contexts.Scheduling\PhaseWorkScheduler.cs(534)
il2cpp.exe!Unity_IL2CPP_Unity_IL2CPP_Contexts_Scheduling_PhaseWorkScheduler_1<System___Canon>__WorkerLoop() Line 338
	at C:\build\output\unity\il2cpp\Unity.IL2CPP\Contexts.Scheduling\PhaseWorkScheduler.cs(338)
il2cpp.exe!S_P_CoreLib_System_Threading_Thread__StartThread() Line 447
	at /_/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.cs(447)
il2cpp.exe!S_P_CoreLib_System_Threading_Thread__ThreadEntryPoint() Line 225
	at /_/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.Windows.cs(225)
kernel32.dll!BaseThreadInitThunk()
ntdll.dll!RtlUserThreadStart()

The code it's crashing during is pretty unremarkable

public static class CustomAttributeProviderExtensions
{
    public static bool HasAttribute(this ICustomAttributeProvider customAttributeProvider, string @namespace, string name)
    {
        for (int i = 0; i < customAttributeProvider.CustomAttributes.Count; i++)
        {
            if (customAttributeProvider.CustomAttributes[i].AttributeType.Name == name &&
                customAttributeProvider.CustomAttributes[i].AttributeType.Namespace == @namespace)
                return true;
        }

        return false;
    }
}

Looking at the assembly we see that

DEFINE_INTERFACE_DISPATCH_STUB 4
00007FF627326BE0  mov         r11,qword ptr [r10+8]  
00007FF627326BE4  mov         rax,qword ptr [rcx]  
00007FF627326BE7  cmp         rax,qword ptr [r11+20h]  
00007FF627326BEB  jne         Attempt1 (07FF627326BF1h)  
00007FF627326BED  jmp         qword ptr [r11+28h]  
00007FF627326BF1  cmp         rax,qword ptr [r11+30h]  
00007FF627326BF5  jne         Attempt1+0Ah (07FF627326BFBh)  
00007FF627326BF7  jmp         qword ptr [r11+38h]  
00007FF627326BFB  cmp         rax,qword ptr [r11+40h]  
00007FF627326BFF  jne         Attempt1+14h (07FF627326C05h)  
00007FF627326C01  jmp         qword ptr [r11+48h]  
00007FF627326C05  cmp         rax,qword ptr [r11+50h]                         <---- crashes here
00007FF627326C09  jne         Attempt1+1Eh (07FF627326C0Fh)  
00007FF627326C0B  jmp         qword ptr [r11+58h]  
00007FF627326C0F  jmp         RhpInterfaceDispatchSlow (07FF627327380h)  
00007FF627326C14  nop         word ptr [rax+rax]  

Note the previous probe locations are accessible. This one seems to be on a new page which is not accessible.

-		(void**)(r11+48h)	0x000002cd88540ff8 {0x0000000000000000}	void * *
			0x0000000000000000	void *
-		(void**)(r11+50h)	0x000002cd88541000 {???}	void * *
			<Unable to read memory>	void *

This code seems to be where the crash happens : https://github.com/Unity-Technologies/runtime/blob/unity-main/src/coreclr/nativeaot/Runtime/amd64/StubDispatch.asm#L68

As a side note, we've had reports of the nativeaot'd il2cpp executable crashing on macOS arm64. This led to us recently switching back to using the coreclr il2cpp executable. You can see reports of this issue by Unity users
https://discussions.unity.com/t/6000-2-cant-build-with-unsafe-il2cpp-via-cli/1686652/17
https://discussions.unity.com/t/ci-compilations-throw-exit-code-139-only-macosx-builds/1683807

We've had 1 report of it internally. We've haven't collected any information from the macOS arm64 crash. Whether or not the macOS arm64 crash and the windows x64 crash are related I don't know. I thought I'd mention the macOS arm64 crash just in case.

Reproduction Steps

We don't have repro steps.

Expected behavior

il2cpp.exe doesn't crash

Actual behavior

il2cpp.exe crashes

Regression?

We don't know. It is suspicious that we just spotted the issue. We've been using the nativeaot'd il2cpp.exe on windows x64 since .NET 7. We are now on .NET8, we've used a few different versions of .NET8. Then again, this crash seems to be fairly rare so maybe we just haven't noticed.

Known Workarounds

No response

Configuration

Windows x64. The crash happened on a Windows 10 machine on our CI. We haven't tried to reproduce on windows 11.

We used the 8.0.204 .NET SDK to build the nativeaot'd il2cpp.exe. il2cpp.exe is targeting net8.

Other information

No response

Activity

  1. added
    untriaged
    on Nov 14, 2025
  2. added
    needs-area-label
    on Nov 14, 2025
  3. added
    tenet-reliability
    and removed
    needs-area-label
    on Nov 14, 2025
  4. dotnet-policy-service commented on Nov 14, 2025

    @dotnet-policy-service
    Contributor

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

  5. jkotas commented on Nov 14, 2025

    @jkotas
    Member
  6. joncham commented on Nov 14, 2025

    @joncham
    Contributor

    I looked at two more crashes. Both manifest the same behavior of trying to read a memory address on a page boundary (0x1000 aligned) in the middle of the dispatch stub logic.

  7. davidwrighton commented on Nov 14, 2025

    @davidwrighton
    Member

    This appears to be some form of memory corruption. Notably, the allocator for these structures in NativeAOT is umm... not good and now having looked at it merits replacement with just about any other allocator, but one of its more interesting properties is that it should never allocate any memory which crosses a page boundary. Given that this fault is at a page crossing, something clearly has gone wrong. What is the value in the dump at r10+8, and r10? Also, what are the values at r11? (i.e. is there an obvious race condition to look at here)

    So, I'd like to see the addresses from 0x2CD88540FB0 to 0x2CD88540FF0, and the data for the pointer in r10 and r10+8.

  8. joncham commented on Nov 14, 2025

    @joncham
    Contributor
    0x000002CD88540FB0  a0 63 e0 27 f6 7f 00 00   cà'ö...
    0x000002CD88540FB8  00 00 00 00 00 00 00 00  ........
    0x000002CD88540FC0  70 0f 54 88 cd 02 00 00  p.TˆÍ...
    0x000002CD88540FC8  02 00 00 00 00 00 00 00  ........
    0x000002CD88540FD0  d8 6c e0 27 f6 7f 00 00  Ølà'ö...
    0x000002CD88540FD8  c0 72 69 27 f6 7f 00 00  Àri'ö...
    0x000002CD88540FE0  d8 6c e0 27 f6 7f 00 00  Ølà'ö...
    0x000002CD88540FE8  c0 72 69 27 f6 7f 00 00  Àri'ö...
    0x000002CD88540FF0  00 00 00 00 00 00 00 00  ........
    0x000002CD88540FF8  00 00 00 00 00 00 00 00  ........
    0x000002CD88541000  ?? ?? ?? ?? ?? ?? ?? ??  ........
    
    *(void**)r10
    0x00007ff627326be0 {il2cpp.exe!RhpInterfaceDispatch4(void)}
    *(void**)(r10+8)
    0x000002cd88550120
    *(void**)(r11)
    0x00007ff627e063a0 {il2cpp.exe!const Unity_IL2CPP_DataModel_Unity_IL2CPP_DataModel_ICustomAttributeProvider::`vftable'}
    
  9. mrvoorhe commented on Nov 17, 2025

    @mrvoorhe
    ContributorAuthor

    We ran il2cpp in a loop all weekend on a developers Windows 11 x64 machine. We saw a crash ~1 in every 5000 runs. All crashes match the same pattern, access violation on a new page. It occurs in multiple places.

  10. jkotas commented on Nov 17, 2025

    @jkotas
    Member

    It occurs in multiple places.

    Does it always occur in one of the RhpInterfaceDispatch methods, or does it occur in different methods?

  11. joncham commented on Nov 17, 2025

    @joncham
    Contributor

    It occurs in multiple places.

    Does it always occur in one of the RhpInterfaceDispatch methods, or does it occur in different methods?

    Always in RhpInterfaceDispatch*. Always at a page aligned memory address.

  12. 8 remaining items

  13. jkotas commented on Nov 18, 2025

    @jkotas
    Member

    Yes. This bug is ~15 years old. It can happen in all versions of NativeAOT and all versions of .NET Native for UWP.

  14. jkotas commented on Nov 18, 2025

    @jkotas
    Member

    In each helper routine, detect if the cache pointer is both a cache pointer (the lower 2 bits are 0, and the cache size is the right size.

    The implementation checks that the value is not smaller than 4k. Do we need to worry about that? I am not able to tell.

    if (((value & IDC_CachePointerMask) != 0) || (value < IDC_MaxVTableOffsetPlusOne))

    Otherwise, (1) seems to be the best servicing-grade fix.

    ldapr

    This won't work. ldapr is armv8.3-a+. Our baseline is armv8-a.

    thoughts?

    Directionally (not as the servicing fix), we may want to lean more into a static helper that computes the target followed by an indirect call. We have WIP implementation of that in #112406 for other reasons. Also, I expect that it is what we are going to use for wasm since the low-level tricks won't work there.

  15. MichalStrehovsky commented on Nov 18, 2025

    @MichalStrehovsky
    Member

    I don't have better ideas - I agree with what Jan wrote, (1) seems like the best with respect to servicing. My hope with #112406 is/was that the static helper that computes the target would have better performance (due to it being more friendly to branch predictor than "jump into a helper that is used by every interface dispatch with the same cache size in the program").

    Also cc @jakobbotsch

  16. jkotas commented on Nov 18, 2025

    @jkotas
    Member

    the static helper that computes the target would have better performance (due to it being more friendly to branch predictor)

    We can further tune the scheme to be friendlier to branch predictor. We may want to get some inspiration from Objective-C dispatch scheme. They use static helper and I believe that they have near zero mis-predicted branches in steady state (the only branch that needs predicting is the indirect call itself).

  17. mrvoorhe commented on Nov 19, 2025

    @mrvoorhe
    ContributorAuthor

    I spent some time trying to come up with a test we can run on CI to flush this bug out. I thought I'd share my findings in case it helps pin down a way to reproduce.

    I was trying to reproduce on macOS arm64, Linux, and Windows 10. Our CI machines are not as hefty as our developer machines. The linux and windows machines report either 4 or 8 cores from Environment.ProcessorCount. I can't remember off hand, I don't think the exact number matters, the point being it's way less than 24 @joncham had when he reproduced locally.

    First I tried running two instance of il2cpp in parallel, running in a loop. Each il2cpp process will use Environment.ProcessorCount threads. Not much luck. I ran for roughly 50hrs evenly split across the 3 platforms and there were no crashes.

    Next I tried running a single instance of il2cpp in a loop, but this time I had the il2cpp process use Environment.ProcessorCount * 4 threads. In roughly 50hrs Linux crashed once and Windows crashed once.

    Maybe it was a fluke or maybe the second approach does have better odds of reproducing. Just thought I'd share.

  18. added this to the 11.0.0 milestone on Jan 5, 2026
  19. removed
    untriaged
    on Jan 5, 2026
  20. MichalStrehovsky commented on Jan 7, 2026

    @MichalStrehovsky
    Member

    Now that #122639 is getting close to merge - do we want to consider changing interface dispatch to use the new resolve helper everywhere to address this issue?

    We might need to replace the cache with a hashtable (depending on measurements). If we use a hashtable, we already have one that we use for generic virtual methods. We might need a reader for it written in assembly so that we have good control over registers in the fast (cached) path.

  21. MichalStrehovsky commented on Apr 2, 2026

    @MichalStrehovsky
    Member

    The implementation checks that the value is not smaller than 4k. Do we need to worry about that? I am not able to tell.

    I don't think we need to worry about it in RhpInterfaceDispatch* because we never go from initial to vtable to cache (it's only initial to cache), but it looks like RhpVTableOffsetDispatch is probably vulnerable to the same race since the mechanism looks the same (we update the pointer to call and update the data in the cell hoping the called method will see the new data, but I assume there's a theoretical chance we call the RhpVTableOffsetDispatch and the cell contents is still the old one). It would be the same kind of race as calling RhpInterfaceDispatch* and not seeing a cache yet (seeing the initial state instead). If we have to protect from that ("detect if the cache pointer is both a cache pointer (the lower 2 bits are 0, and the cache size is the right size" above), we need to protect from it in RhpVTableOffsetDispatch too.

  22. locked and limited conversation to collaborators on May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-NativeAOT-coreclrtenet-reliability

Type

No type

Projects

  • Status
    No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions