Skip to content

SIGSEGV in GC stack walk (MethodDesc::GetSig) with mixed interpreter/ReadyToRun execution on iOS (.NET 11 RC1) #135203

Closed

Description

@gentledepp

Description

On .NET 11 RC1 for iOS (CoreCLR), a Release build crashes with EXC_BAD_ACCESS (SIGSEGV) inside the GC a few seconds after launch. Reproduced on both the simulator (iossimulator-arm64) and a physical device (ios-arm64). Setting PublishReadyToRun=false avoids it.

The crash is in MethodDesc::GetSig, reached from TransitionFrame::PromoteCallerStack while the GC scans stack roots during mark_phase. The GC reads what it believes is a MethodDesc* out of a TransitionFrame and dereferences it.

The value it dereferences is not a pointer — it is executable code. The faulting address is 0xa9025bf5a90153f9; the value read from the frame is 0xa9025bf5a90153f3. Decoded as AArch64, those 8 bytes are two consecutive instructions:

a9025bf5    stp x21, x22, [sp, #32]
a90153f9    stp x25, x20, [sp, #16]

That is a function prologue. The stack walker did not read a corrupted MethodDesc — it misidentified the frame layout and read bytes out of the code stream.

The crashing thread's stack interleaves CoreCLR interpreter frames with ReadyToRun frames:

InterpExecMethod / ExecuteInterpretedMethod / InterpreterStubRetVoid   <- interpreter
<app>.r2r                                                              <- ReadyToRun
CallJittedMethodRetVoid / InvokeCalliStub

The main thread shows ~19 levels of nested interpreter↔R2R recursion at the point of the crash.

Observed matrix

Configuration PublishReadyToRun r2r framework in bundle Result
Debug, simulator true (SDK default) yes stable
Release, simulator true (SDK default) yes SIGSEGV ~3s after launch
Release, device true (SDK default) yes SIGSEGV ~7s after launch
Release, simulator false no stable (75s+)
Release, device false no stable (10 min)

I have not isolated what differs between the stable Debug build and the crashing Release build — both ship an r2r framework and both have PublishReadyToRun=true. Toggling PublishReadyToRun in Release is the only change I found that reliably flips the outcome.

PublishReadyToRun is defaulted to true by the iOS SDK for all CoreCLR builds — it is not an opt-in and not Release-specific (Xamarin.Shared.Sdk.props:302):

<!-- ReadyToRun configuration for CoreCLR -->
<PropertyGroup Condition="'$(UseMonoRuntime)' == 'false' And '$(_PlatformName)' != 'macOS' And '$(_UseNativeAot)' != 'true'">
  <PublishReadyToRun Condition="'$(PublishReadyToRun)' == ''">true</PublishReadyToRun>
  <PublishReadyToRunComposite Condition="... ">true</PublishReadyToRunComposite>
  <PublishReadyToRunContainerFormat Condition="... ">macho</PublishReadyToRunContainerFormat>

Environment

SDK 11.0.100-rc.1.26425.128
Workload set 11.0.100-rc.1.26460.1
iOS workload manifest 26.5.12194-net11-rc.1/11.0.100-rc.1
TFM net11.0-ios
RIDs affected iossimulator-arm64 and ios-arm64
Host macOS 26.6.2 (25G83), Mac mini M1
Xcode 26.6 (17F113)
Simulator iPhone 17, iOS 26.4.1
Device iPad, iOS 26.6.1

App scale: ~295 managed assemblies (Avalonia + ReactiveUI + MAUI Essentials).

Relevant Release configuration:

<MtouchLink>SdkOnly</MtouchLink>
<!-- PublishReadyToRun is NOT set in the project; the iOS SDK defaults it to true -->

Resolved: Registrar=trimmable-static, PublishReadyToRun=true, PublishReadyToRunComposite=true, PublishReadyToRunContainerFormat=macho, UseMonoRuntime=false, AOTCompiler= (empty).

The project also sets MtouchInterpreter=-all and EnableSGenConc=true, but the SDK reports both as having no effect under CoreCLR, so they should not be relevant:

warning : The property 'MtouchInterpreter' has no effect when not using the Mono runtime
          (for instance when using CoreCLR).
warning : The property 'EnableSGenConc' has no effect when not using the Mono runtime ...

Faulting stack (thread 20, simulator)

libcoreclr  MethodDesc::GetSig(unsigned char const**, unsigned int*) + 40
libcoreclr  MethodDesc::GetSignature() + 40
libcoreclr  TransitionFrame::PromoteCallerStack(void (*)(Object**, ScanContext*, unsigned int), ScanContext*) + 76
libcoreclr  GcStackCrawlCallBack(CrawlFrame*, void*) + 508
libcoreclr  Thread::MakeStackwalkerCallback(...) + 116
libcoreclr  Thread::StackWalkFramesEx(...) + 404
libcoreclr  Thread::StackWalkFrames(...) + 180
libcoreclr  ScanStackRoots(Thread*, ...) + 256
libcoreclr  GCToEEInterface::GcScanRoots(...) + 260
libcoreclr  WKS::gc_heap::mark_phase(int) + 552
libcoreclr  WKS::gc_heap::gc1() + 444
libcoreclr  WKS::gc_heap::garbage_collect(int) + 1156
libcoreclr  WKS::GCHeap::GarbageCollectGeneration(unsigned int, gc_reason) + 716
libcoreclr  WKS::gc_heap::trigger_gc_for_alloc(...) + 176
libcoreclr  WKS::gc_heap::try_allocate_more_space(...) + 692
libcoreclr  WKS::GCHeap::Alloc(gc_alloc_context*, unsigned long, unsigned int) + 124
libcoreclr  Alloc(ee_alloc_context*, unsigned long, GC_ALLOC_FLAGS) + 324
libcoreclr  AllocateSzArray(MethodTable*, int, GC_ALLOC_FLAGS) + 656
libcoreclr  RhpGcAlloc + 200
libcoreclr  RhpNewVariableSizeObject + 48
<app>.r2r   (allocation site in ReadyToRun code)
...
libcoreclr  InvokeUnmanagedCalliWithTransition(...)
libcoreclr  InterpExecMethod(...)
libcoreclr  ExecuteInterpretedMethod + 480

Register state at the fault:

x0:  0xa9025bf5a90153f3     x22: 0xa9025bf5a90153f3
far: 0xa9025bf5a90153f9     esr: 0x92000004 (Data Abort) byte read Translation fault
pc:  MethodDesc::GetSig + 40
Exception Subtype: KERN_INVALID_ADDRESS at 0xa9025bf5a90153f9
                   (possible pointer authentication failure)

On the device the app terminates identically (Got a SIGSEGV while executing native code / App terminated due to signal 11) about 7 seconds after launch. I did not pull the device crash report, so the symbolicated stack above is from the simulator.

Repro

  1. Build a reasonably large net11.0-ios CoreCLR app in Release with MtouchLink=SdkOnly, leaving PublishReadyToRun unset so the iOS SDK default (true) applies.
  2. Launch on an arm64 simulator or a device.
  3. The app starts and renders normally, then dies with SIGSEGV on the first GC that walks one of these frames — ~3s on the simulator, ~7s on device, reproducible every time.

I was not able to reduce this to a minimal project; it reproduces consistently in the full app but I do not know which code path allocates at the critical moment.

Workaround

<PublishReadyToRun>false</PublishReadyToRun>

Verified stable: 75s+ on the simulator and 10 minutes on a physical device, where the default configuration crashed within seconds every time.

The workaround is expensive. With R2R off and no Mono AOT in play (AOTCompiler= is empty), the device IPA ships no precompiled managed code at all — 295 managed assemblies plus libcoreclr.framework, no r2r framework. Since iOS prohibits JIT on device, the app then runs fully interpreted.

Notes

  • After the fault, the signal handler ran EEPolicy::LogManagedCallstackForSignal on thread 0, which itself faulted in TypeString::AppendMethodImpl — presumably on the same bad MethodDesc. Thread 0's reported stack is therefore the logging path, not its original state.

Activity

  1. added
    untriaged
    on Oct 5, 2026
  2. dotnet-policy-service commented on Oct 5, 2026

    @dotnet-policy-service
    Contributor

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

  3. dotnet-policy-service commented on Oct 5, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to 'os-ios': @vitek-karas, @kotlarmilos, @steveisok, @akoeplinger
    See info in area-owners.md if you want to be subscribed.

  4. vitek-karas commented on Oct 5, 2026

    @vitek-karas
    Member

    @BrzVlad could you please also take a look?

    @gentledepp I tried to repro it on simulator, but no luck so far (I'm running slightly different versions of mac and XCode though).
    Regardless I wanted to ask about these:

    • Can you try without setting MTouchLink - I don't think it will have effect, but it's worth a try

    So far we haven't seen this anywhere really - so any kind of repro would be very helpful.

  5. gentledepp commented on Oct 12, 2026

    @gentledepp
    Author

    Thanks for looking into this. Results:

    • MtouchLink: without it (MtouchLink=None, verified untrimmed) the app still crashes, 3 of 3 runs, same faulting address.
    • Why Debug is stable: the iOS SDK sets FilterReadyToRunAssemblies=true for all configurations except Release (Microsoft.Sdk.R2R.targets). A Release build with -p:FilterReadyToRunAssemblies=true is stable. The part that matters is ublishReadyToRunCompositeRoots=System.Private.CoreLib.dll: adding only that is also stable. Excluding individual assemblies from R2R (including the _*.TypeMap.dll assemblies from the trimmable-static registrar) does not help, in any combination.
    • When it crashes: only once the app is logged in. On a fresh install, it crashes in the last stage of the first sync, where we index content items into SQLite. That stage is a tight loop that deserializes data and runs one INSERT OR REPLACE per row through SQLitePCLRaw. After that, every launch crashes within seconds.
    • Where it reproduces: reliably in the simulator (iPhone 17, iOS 26.5, Xcode 26.6), with no code signing needed.

    We can't share the source publicly, but we have a repro package ready (~94 MB zip):

    • the prebuilt simulator .app (Release, SDK defaults)
    • crash reports
    • binlogs of 2 crashing and 2 stable builds
    • step-by-step instructions, including a test account for our test portal

    How would you like us to send it privately (e.g. email, or a file share link)?

  6. gentledepp commented on Oct 12, 2026

    @gentledepp
    Author

    Root cause narrowed down: sqlite-net per-row column setters

    The crash is in sqlite-net's per-row column setters, and the pattern is specific enough to rebuild in a small app.

    What crashes

    When the app reads inspections from SQLite, the R2R-compiled sqlite-net loop calls a delegate for every column of every row:

    fastColumnSetters[i].Invoke(obj, stmt, i);

    That's the exact call site. The return address is MoveNext +0x774, right after a blr with x1 = obj, x2 = stmt, x3 = i. The interpreter runs the delegate's target, and the crash happens in the interpreter's next call.

    How sqlite-net builds those delegates

    This is FastColumnSetter, read from the IL of our sqlite-net-pcl 1.10.0-optiq03 fork:

    1. It builds GetFastSetter<T> at runtime via MakeGenericMethod over our model type. Generic code that is only instantiated at runtime like this isn't precompiled, so it runs interpreted.
    2. It creates an open-instance delegate to the property setter:
       Delegate.CreateDelegate(typeof(Action<T, TCol>), null, prop.GetSetMethod())

    The setter itself belongs to our model class and is R2R-compiled.
    3. A closure (o, stmt, i) => setProperty((T)o, getValue(stmt, i)) calls three things:

    • SQLite3.ColumnType, a P/Invoke, which matches the InvokeUnmanagedCalliWithTransition frame in this issue
    • a value-getter Func
    • the open-instance setter delegate

    So the chain is:

    R2R loop → interpreted closure → P/Invoke and delegate calls → R2R setter
    

    The crash is somewhere on that path, most likely when the interpreter invokes the reflection-created open-instance delegate. The CoreCLR frames have no symbols, so I can't tell which of those calls it is.

    This also explains the earlier observations

    • Login: without synced data there are no rows, so the setters never run.
    • Indexing and the license check: they made no difference because the crash is triggered by row reads, in this case in InspectionSqliteStore.GetInspectionsAsync.

    I am going to create a minimal repro based on these findings!

  7. gentledepp commented on Oct 12, 2026

    @gentledepp
    Author

    Minimal repro

    We now have a minimal repro, attached: R2RSqliteRepro-135203.zip

    It's a plain dotnet new ios app plus the public sqlite-net-pcl 1.11.285, with SDK defaults except TrimMode=partial.

    Configuration Result
    Release, SDK defaults Crashes within seconds, 3 of 3 runs: Got a SIGSEGV while executing native code
    -p:PublishReadyToRun=false Stable

    Environment: iPhone 17 simulator, iOS 26.5, Xcode 26.6.

    lldb shows EXC_BAD_ACCESS at 0xa9025bf5a90153f5. This is the same bad pointer as in our app, and it is made of ARM64 instruction bytes.

    Where it crashes

    We symbolicated the composite R2R image of our app with a crossgen2 --map. The crash happens while R2R code in SQLiteCommand.ExecuteDeferredQuery<T>.MoveNext invokes sqlite-net's per-row column setter delegates (fastColumnSetters[i]).

    These delegates are built at runtime through MakeGenericMethod and wrap an open-instance delegate:

    Delegate.CreateDelegate(typeof(Action<T, TCol>), null, prop.GetSetMethod())

    Their targets run on the interpreter, which calls back into R2R code.

    Other results

    • Without linking (MtouchLink=None, verified untrimmed): our app still crashes.
    • FilterReadyToRunAssemblies=true, or only PublishReadyToRunCompositeRoots=System.Private.CoreLib.dll: stable. This is why our Debug builds never crashed: the iOS SDK sets the filter for every configuration except Release.
    • Excluding individual assemblies from R2R: doesn't help.
  8. vitek-karas commented on Oct 12, 2026

    @vitek-karas
    Member

    Thanks a lot for the simple repro - I can repro it locally.

    We will look into this some more...

  9. vitek-karas commented on Oct 13, 2026

    @vitek-karas
    Member

    I think this should be fixed in #134699 - which unfortunately didn't make RC2, so will only be in daily builds and GA. I'm trying to validate it with this specific repro still...

  10. vitek-karas commented on Oct 13, 2026

    @vitek-karas
    Member

    I was able to validate this - without #134699 the failure reproes locally, with that change it doesn't repro anymore. This should be fixed in GA.

  11. removed
    untriaged
    on Oct 13, 2026
  12. gentledepp commented on Oct 13, 2026

    @gentledepp
    Author

    AWESOME! Thank you so much!!

  13. locked and limited conversation to collaborators on Nov 12, 2026
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