Repository navigation
Description
Below is a summary by claude of several hours of trying to analyse what appears to be a codegen bug on .NET 11 iOS that surfaced when I switched to CoreCLR from Mono on .NET 11. I am completely out of my depth here, so I have no clue whether the model's hypotheses make sense, and therefore whether there's even any struct corruption, but the investigation steps and the issue as observed by the user (me) are described accurately. In short, under some circumstances locals contain garbage data whose origin I haven't been able to trace back to application code, and Mono iOS and CoreCLR/Mono Android run fine. Sadly, either through my own inexperience or the fact that lldb/xcode won't play ball, I haven't been able to get xcode to stop on a breakpoint at the correct address to provide more insight.
I can share a full xcarchive with the third manifestation (see blow) via a private channel.
Description
A production F# iOS app (CoreCLR, composite ReadyToRun via crossgen2 + CoreCLR interpreter for
non-compiled methods) deterministically corrupts a small struct on specific screens.
iOS CoreCLR Release is the only configuration that manifests the defect. The exact same
cross-platform source (all logic shared; only the per-platform host shell differs), driven through the
exact same sequence of user steps, is correct in Release builds on:
- Android device — CoreCLR and Android device — Mono
- iOS — Mono (
UseMonoRuntime=true, .NET 11 previews up to 5), on the same physical device
Since preview 6 removes Mono support for iOS entirely, CoreCLR is now the only iOS runtime, and this defect currently has no workaround.
To be clear about the failure mode: the underlying defect is silent data corruption — struct fields
(an array reference, a uint16 count, an int key) containing garbage values. The exceptions quoted
below are downstream artifacts only: they are thrown on the UI thread at whatever point the garbage
first happens to trip an array-bounds or null check inside otherwise-correct code. Garbage that does not
trip such a check would surface as silently wrong behavior instead of a crash, so the exceptions
understate the problem — they are where the corruption becomes visible, not where it happens.
We have not been able to minimize it — a standalone repro exercising the same types/patterns on-device
is clean — and the evidence suggests the defect depends on whole-composite context. We are filing with a
full analysis, binaries, and an offer to run any diagnostics you need on the reproducing environment.
Environment
- .NET SDK
11.0.100-preview.6.26359.118;Microsoft.iOS.Sdk.net11.0_26.5(26.5.11720-net11-p6) net11.0-ios,RuntimeIdentifier=ios-arm64, CoreCLR, composite R2R (~34 MB Mach-O),TrimMode=full- Physical device, iOS 17+; Windows + Pair-to-Mac build
- Also reproduced on earlier .NET 11 previews (CoreCLR flavor). Cannot re-test on preview 5: CoreCLR
apps abort at startup there ([net11.0] CoreCLR-flavor iOS apps abort in xamarin_vm_initialize ("Failed to initialize the VM") on iPhone 17 / iOS 26.0 with Microsoft.iOS.Sdk.net11.0_26.5 26.5.11527-net11-p5 macios#25542, suspected locally on a clean bundle with
26.5.11546-net11-p5) - Configuration matrix (same shared source, same repro steps, Release unless noted): manifests
only on iOS CoreCLR. Clean: Android CoreCLR, Android Mono, iOS Mono
(previews ≤ 5, same physical device), iOS CoreCLR Debug.
Symptom: struct fields containing garbage (exceptions below are downstream)
The corrupted type is Fabulous.StackAllocatedCollections.MutStackArray1.T<Widget> — an F# struct DU
Empty | One of 'v | Many of struct(uint16 * 'v[]) (observed layout: tag @ +0, Many array ref @
+0x28, uint16 count @ +0x30; Widget is a 0x20-byte struct: three array refs + int Key).
The corruption has surfaced as three different downstream exceptions across builds — which exception,
and where, depends only on which check the garbage data trips first. Each is deterministic per
build (same failure, same screen, every run and every no-source-change rebuild); the failure point
moves only when source changes:
System.ArgumentException: Arg_LongerThanSrcArrayinArray.Copy— the slice'suint16count once read
as 23512 (0x5BD8) where a single-digit value was expected (pointer-shaped low 16 bits).IndexOutOfRangeException— aWidget.Key(intfield) is garbage when used as a store index
(WidgetDefinitionStore.get widget.Key), observed arriving at an AOT method invoked from the
interpreter (mixed-mode backtrace available).NullReferenceExceptioninaddMut— aMany-tagged value whose array slot is null/garbage,
already corrupt on entry to the (AOT) callee chain.
What we established
- IL is correct (verified via decompilation): count read via
ldfld Item1+conv.i4,int32
passed toArray.Copy. Nothing at IL level can produce the observed values ⇒ defect is below IL. - Static arm64 disassembly of the composite (via dSYM symbols):
combineMut<Widget>,
combineMut<__Canon>, and every inspected upstream producer read/write these fields at consistent
offsets/widths (ldrh/strhat +0x30 etc.). No wrong-offset/wrong-width instruction found. If
this is a codegen defect it looks like register-allocation/data-flow, not field layout. - Data flow at the visible failure points: in manifestation 1 the garbage count was already present
in the by-value argument on entry (held in a callee-saved register, no intervening call). In
manifestation 3 the corrupt struct arrived via a byref that the intermediate frame provably never
wrote. ⇒ the corruption happens upstream of every observed failure point, somewhere in
AOT-compiled F# builder code — the throwing methods are victims, not causes. - Screen-specific: most screens exercising identical code paths are fine.
- Determinism argues against simple timing/GC causes; additionally forcing aggressive GC
(System.GC.ConserveMemory=9, concurrent GC off) changed nothing, and a GC-stressed standalone repro
is clean. (GC not conclusively excluded — decoding the composite's GC info was beyond our tooling;
r2rdumpagainst a Mach-O composite is presumably yours to run.) - Any source change to the affected library moves/masks the failure (adding logging,
min-clamps,
by-value→inrefsignature changes) — classic Heisenbug via codegen perturbation, consistent with a
per-compilation defect sensitive to input perturbation. - Mixed-mode note: device backtraces show mixed AOT + interpreter execution
(InterpExecMethod/CallJittedMethodRetI8frames); manifestation 2's garbage struct arrived at an
AOT method called from the interpreter. We could not determine whether the interp↔AOT boundary is
causal or incidental.
What we could NOT do (and why)
- Minimize: a standalone device app driving
combineMut<Widget>/combineMut<StructElem>through
Many+Many merges, heap round-trips, CE builders, recursion, and GC stress passes everywhere. The
trigger appears to need the full app's composite (co-compiled method set / whole-program context). - Force interpretation to bisect:
UseInterpreter/MtouchInterpreterdo not affect crossgen2
composite generation on iOS CoreCLR (verified via symbol diffs), and the runtime-side knobs
(DOTNET_ReadyToRun=0,DOTNET_ReadyToRunExcludeList=<assembly>) crash this app at startup in an
F# closure-class.cctorbefore any UI (a separate problem, not analyzed further here). Whole-app or
per-assembly interpretation therefore could not be tested at all. - On-device lldb: breakpoints on interpreted code don't fire; and when the corrupting fault occurs
with the debugger attached, the Xcode/debugserver session wedges with no visible stop (plausibly the
CoreCLR Mach-exception NRE handling vs debugserver interaction on iOS 17 CoreDevice). Live register
harvest was not achievable.
Artifacts available
- Composite Mach-O + matching dSYM (UUID-verified), pristine crashing build — can share privately.
Fabulous.dll(IL assembly), fork of github.com/fabulous-dev/Fabulous.- Full command log of the analysis (llvm-nm/objdump/dwarfdump invocations, method addresses,
disassembly excerpts, observed field layouts, negative results) — available on request
Activity
dotnet-policy-service commentedon Jul 18, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
JulieLeeMSFT commentedon Jul 22, 2026
@jtschuster, PTAL.
CC @vitek-karas.
dotnet-policy-service commentedon Jul 23, 2026
Tagging subscribers to 'os-ios': @vitek-karas, @kotlarmilos, @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.
dotnet-policy-service commentedon Jul 23, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @BrzVlad, @janvorli
See info in area-owners.md if you want to be subscribed.
jtschuster commentedon Jul 23, 2026
If the disassembly looks correct, this seems like an issue with the interpreter rather than crossgen2.
BrzVlad commentedon Jul 24, 2026
Not sure what could be happening here just from this report. You are mentioning that the crash is deterministic. Could you share a private repro with us, even if it is the actual app ?
kerams commentedon Jul 24, 2026
I can invite you to testflight and let you run a broken build, or tell me where to send the xcarchive (with a dev signature only).
BrzVlad commentedon Jul 24, 2026
You can reach me at
[email protected]. Ideally I would be able to rebuild the app from source, so that I can make it use custom runtime bits that help debugging. I could try with anxcarchivebut it is hard to say how far this will get us, especially since you mentioned the crash is not quite deterministic.kerams commentedon Jul 27, 2026
@BrzVlad, I've sent you the source code zip. The archive password is veryveryverySTRONGpassword
BrzVlad commentedon Jul 28, 2026
@kerams Thanks!! I can repro a exception handling related crash at startup
kerams commentedon Jul 28, 2026
Excellent. Glad it's not just me seeing things or my device acting up. As described above, the uncaught index out of bounds exception on the UI thread is the result of getting unexpected values, not a problem in and of itself. Unless you have discovered something else entirely.
BrzVlad commentedon Aug 5, 2026
@kerams Thanks again for the repro which helped debug this. The fix will be included in .Net11 RC1
kerams commentedon Aug 5, 2026
Appreciate it.
interp: don't alias a call's return buffer with its own arguments (do…