Skip to content

Crossgen2 failed with exitcode - -1073741819 #126292

Closed

Description

@MichalStrehovsky

This might be related to #124181 or #124976 or #122845. We've been seeing various corruptions in crossgen2 and ILC, both when native AOT compiled and when not native AOT compiled.

The special thing about "Crossgen2 failed with exitcode - -1073741819" is that this is a crash inside Helix.

AND WE GET A DUMP!!!:

0:006> k
 # Child-SP          RetAddr               Call Site
00 00000061`84c7f220 00007ff7`b68b6fb8     crossgen2!SVR::GCHeap::Promote+0xb [D:\a\_work\1\s\src\runtime\src\coreclr\gc\gc.cpp @ 49915] 
01 00000061`84c7f280 00007ff7`b68b5bea     crossgen2!TGcInfoDecoder<AMD64GcInfoEncoding>::EnumerateLiveSlots+0x1238 [D:\a\_work\1\s\src\runtime\src\coreclr\vm\gcinfodecoder.cpp @ 1070] 
02 00000061`84c7f700 00007ff7`b68bc966     crossgen2!CoffNativeCodeManager::EnumGcRefs+0x14a [D:\a\_work\1\s\src\runtime\src\coreclr\nativeaot\Runtime\windows\CoffNativeCodeManager.cpp @ 500] 
03 00000061`84c7f7d0 00007ff7`b68af1bf     crossgen2!EnumGcRefs+0x66 [D:\a\_work\1\s\src\runtime\src\coreclr\nativeaot\Runtime\GcEnum.cpp @ 153] 
04 00000061`84c7f840 00007ff7`b68af02d     crossgen2!Thread::GcScanRootsWorker+0x16f [D:\a\_work\1\s\src\runtime\src\coreclr\nativeaot\Runtime\thread.cpp @ 542] 
05 00000061`84c7f900 00007ff7`b68bb4d8     crossgen2!Thread::GcScanRoots+0x8d [D:\a\_work\1\s\src\runtime\src\coreclr\nativeaot\Runtime\thread.cpp @ 425] 
06 00000061`84c7fb70 00007ff7`b6918e2c     crossgen2!GCToEEInterface::GcScanRoots+0x148 [D:\a\_work\1\s\src\runtime\src\coreclr\nativeaot\Runtime\gcenv.ee.cpp @ 125] 
07 00000061`84c7fbd0 00007ff7`b690fb91     crossgen2!SVR::gc_heap::mark_phase+0x4dc [D:\a\_work\1\s\src\runtime\src\coreclr\gc\gc.cpp @ 30096] 
08 00000061`84c7fce0 00007ff7`b690fa19     crossgen2!SVR::gc_heap::gc1+0x111 [D:\a\_work\1\s\src\runtime\src\coreclr\gc\gc.cpp @ 22563] 
09 00000061`84c7fd60 00007ff7`b6911111     crossgen2!SVR::gc_heap::garbage_collect+0xc59 [D:\a\_work\1\s\src\runtime\src\coreclr\gc\gc.cpp @ 24733] 
0a 00000061`84c7fe50 00007ff7`b691143e     crossgen2!SVR::gc_heap::gc_thread_function+0x421 [D:\a\_work\1\s\src\runtime\src\coreclr\gc\gc.cpp @ 7329] 
0b 00000061`84c7fed0 00007ff7`b68bae83     crossgen2!SVR::gc_heap::gc_thread_stub+0x7e [D:\a\_work\1\s\src\runtime\src\coreclr\gc\gc.cpp @ 37846] 
0c 00000061`84c7ff10 00007ffc`cd0b84d4     crossgen2!<lambda_cfddccf0842510998c037a6768ae02c9>::operator()+0x63 [D:\a\_work\1\s\src\runtime\src\coreclr\nativeaot\Runtime\gcenv.ee.cpp @ 592] 

Build Information

Build: https://dev.azure.com/dnceng-public/cbb18261-c48f-4abb-8651-8cdcb5474649/_build/results?buildId=1357249
Build error leg or test failing: jit64_5.WorkItemExecution
Pull request: #126170

Error Message

Fill the error message using step by step known issues guidance.

{
  "ErrorMessage": "Crossgen2 failed with exitcode - -1073741819",
  "ErrorPattern": "",
  "BuildRetry": false,
  "ExcludeConsoleLog": false
}

Known issue validation

Build: 🔎 https://dev.azure.com/dnceng-public/public/_build/results?buildId=1357249
Error message validated: [Crossgen2 failed with exitcode - -1073741819]
Result validation: ✅ Known issue matched with the provided build.
Validation performed at: 3/30/2026 6:18:08 AM UTC

Report

Build Definition Test Pull Request
1357249 dotnet/runtime jit64_5.WorkItemExecution #126170

Summary

24-Hour Hit Count 7-Day Hit Count 1-Month Count
1 1 1

Activity

  1. added
    blocking-clean-ci
    Known Build Error
    on Mar 30, 2026
  2. added
    untriaged
    on Mar 30, 2026
  3. MichalStrehovsky commented on Mar 30, 2026

    @MichalStrehovsky
    MemberAuthor

    Regdisplay.IP is pointing to the instruction after RhpResolveInterfaceMethodFast and we have been seeing these crashes since around late January so it would be a big coincidence if this wasn't from #122639.

    crossgen2!ILCompiler_ReadyToRun_ILCompiler_ReadyToRun_ReadyToRunTypeMapManager__AttachToDependencyGraph
    
    ...
    00007ff7`b63edc27 488bca         mov     rcx, rdx
    00007ff7`b63edc2a e801494c00     call    crossgen2!RhpResolveInterfaceMethodFast (7ff7b68b2530)
    00007ff7`b63edc2f 488bca         mov     rcx, rdx
    ...
    

    @jakobbotsch could you double check the GC information is correct? The dump can be pulled down with

    runfo get-helix-payload -j e1e18da6-c196-40c1-920e-e84e84709a9f -w jit64_5 -o c:\hell\e1e18da6-c196-40c1-920e-e84e84709a9f\jit64_5\
    

    But also this might be all moot if we can merge #123252.

  4. mangod9 commented on Mar 30, 2026

    @mangod9
    Member

    some analysis for diag mcp analysis of the dump:

     Dump Analysis: NULL ppObject in GCHeap::Promote — NativeAOT REGDISPLAY volatile register gap
    
    Analyzed the crossgen2 crash dump (crossgen2.exe.4676.dmp) using CDB disassembly. Here's the root cause chain:
    
    Crash: GCHeap::Promote+0xb dereferences rcx=NULL (mov rbx, [rcx])
    
    Call chain:
    
     GCHeap::Promote(ppObject=NULL)
       ← tail-jump from callback (crossgen2+0x54c980)
         ← GcInfoDecoder::EnumerateLiveSlots (gcinfodecoder.cpp:1070)
           ← CoffNativeCodeManager::EnumGcRefs (CoffNativeCodeManager.cpp:500)
             ← Thread::GcScanRootsWorker
    
    Root cause: Thread 0 entered preemptive mode voluntarily (NtWaitForSingleObject). The PInvokeTransitionFrame only
    saves callee-saved registers, so volatile register pointers (pRDX, pR8–pR11) are NULL in the REGDISPLAY. However, 
    CoffNativeCodeManager::EnumGcRefs passes isActiveStackFrame=true as reportScratchSlots to EnumerateLiveSlots. This
    bypasses the callee-saved-only filter, causing ReportRegisterToGC → GetRegisterSlot to return NULL for a volatile
    register slot that the GC info marks as live. The NULL pObjRef is passed directly to the Promote callback with no
    guard.
    
    Evidence from dump:
    
     - REGDISPLAY at 0x6184c7f940: indices 2(RDX), 7-10(R8-R11) are NULL; callee-saved regs have valid save locations
     - reportScratchSlots flag at [rsp+40h] = 0x01 (TRUE)
     - Crash on tracked slot index 3 of 8 total slots — the first volatile register slot encountered
     - Thread 0 stack: NtWaitForSingleObject → runtime → dispatch thunk (0x54f050, saves RCX/RDX/R8/R9 to shadow 
    space) → managed method (crossgen2+0x7dc2f)
    
    Code gap in gcinfodecoder.cpp ReportRegisterToGC: There's a NULL check for pObjRef on Unix CoreCLR (#if
    defined(TARGET_UNIX) && !defined(FEATURE_NATIVEAOT)) that falls back to GetCapturedRegister + pinning, but no
    equivalent guard for NativeAOT or Windows. For CoreCLR Windows this is generally safe because 
    pCurrentContextPointers is initialized from CONTEXT for the active frame. For NativeAOT, volatile register save
    pointers can legitimately be NULL.
    
    Regarding non-NativeAOT repros: This specific NULL ppObject path appears NativeAOT-specific — CoreCLR's stack
    walker initializes volatile register pointers from the thread CONTEXT for the active frame. The non-NativeAOT
    crossgen2/ILC crashes likely have a different root cause (heap corruption, JIT GC info encoding, etc.).
    
    Possible fixes:
    
     1. Add a NULL guard in ReportRegisterToGC for FEATURE_NATIVEAOT (skip reporting if save pointer is NULL)
     2. Don't set isActiveStackFrame=true when volatile registers weren't captured (voluntary preemptive transition)
     3. Have the NativeAOT stack walker recover volatile register values from the dispatch thunk's shadow space saves
    
  5. mangod9 commented on Mar 30, 2026

    @mangod9
    Member

    Here is the updated analysis:

    The crash requires five independent conditions to align simultaneously:
    
     1. Interface dispatch cache miss — Most calls hit the inline cache and never touch the universal transition 
    thunk. Only misses take the slow RhpUniversalTransition path.
     2. GC fires at exactly that moment — Server GC must suspend and scan the thread while it's inside (or past) the 
    thunk.
     3. Thread is hijacked, not OS-suspended — If the GC uses SuspendThread → full NATIVE_CONTEXT → all register 
    pointers valid → no bug. Only the hijack path (PTFF_THREAD_HIJACK) leaves volatile register pointers NULL.
     4. Managed frame has live GC refs in volatile registers — If volatiles hold primitives or are dead at that IP, no
     crash.
     5. The specific volatile register wasn't saved by the hijack — PTFF_SAVE_* flags are selective; only registers 
    needed at the hijack point are saved.
    
    Most of the time, condition 1 or 3 fails. But when all five align → NULL dereference in Promote.
    
    The Silent Corruption Risk
    
    This is arguably worse than the crash. Even when it doesn't crash, if the GC relocates an object referenced by a
    volatile register that the thunk saved but the stack walker didn't report → the thunk restores the stale pointer →
    managed code uses a dangling reference → delayed heap corruption. This could explain the "various corruptions in
    crossgen2 and ILC" mentioned in the issue.
    
    The Correct Fix
    
    Not the NULL guard in PR #126328 (that silently skips live refs → corruption). The fix belongs in 
    UnwindUniversalTransitionThunk() in StackFrameIterator.cpp:
    
     // After UnwindNonVolatileRegisters (which is a no-op on AMD64):
     m_RegDisplay.pRcx = &stackFrame->m_intArgRegs[0];
     m_RegDisplay.pRdx = &stackFrame->m_intArgRegs[1];
     m_RegDisplay.pR8  = &stackFrame->m_intArgRegs[2];
     m_RegDisplay.pR9  = &stackFrame->m_intArgRegs[3];
    
    The thunk already saves these registers at ChildSP+0x80..0x98. The stack walker just doesn't tell the REGDISPLAY
    about them. This fix lets the GC precisely track and update object refs through the thunk — no crash, no silent
    corruption.
    
    CoreCLR is not affected — it doesn't use the universal transition thunk. The non-NativeAOT crashes in the issue
    have different root causes.
    
  6. removed
    untriaged
    on Mar 31, 2026
  7. locked and limited conversation to collaborators on May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Known Build Errorarea-ReadyToRunblocking-clean-ci

Type

No type

Projects

  • Status
    No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions