Repository navigation
Description
Description
On a physical iPhone, a .NET 11 iOS app (CoreCLR, composite ReadyToRun + interpreter) is killed by the kernel during startup with EXC_BAD_ACCESS (SIGKILL) / CODESIGNING 2 Invalid Page ("Failed to fault in a page with execute permissions").
The crash happens when interpreted code triggers a class constructor. InitHelpers.InitClass (R2R) → InitClassHelper → MethodTable::RunClassInitEx → UnmanagedCallersOnlyCaller::InvokeThrowing → InitHelpers.CallClassConstructor (R2R), which calls the cctor slot. The slot leads to ThePreStub. ThePreStub ends with br x9 to the address returned by PreStubWorker, and that address is in a read-write, non-executable region. The same build running on the iOS Simulator does not crash. The device and Simulator libcoreclr builds export identical symbols.
The crash is deterministic. Two builds crashed at the same offset (569600 bytes) into a region of the same size (3712 KB, rw-/rwx, guard pages on both sides).
Reproduction Steps
- iOS app on
net11.0-ios(Microsoft.iOS.Sdk 27.2.11039, runtime 11.0.0), Release,ios-arm64, App Store / TestFlight signing (noget-task-allow, no JIT entitlement). - Composite ReadyToRun with a subset of assemblies as
PublishReadyToRunCompositeRoots(System.Private.CoreLib, Microsoft.CodeAnalysis*, several app assemblies and some BCL). The other app and package assemblies are inPublishReadyToRunExclude, so they run in the interpreter. - At startup, interpreted code (an excluded assembly) calls into the Razor compiler (
Microsoft.CodeAnalysis.Razor.Compiler, also interpreted). That causes a class constructor of an interpreted type to run (RazorProjectEngine.Create(...)→engine.Process(...)). - Launch on a physical device (seen on iPhone19,2, iOS 27.2 (24B119)).
I don't have a standalone repro project yet. I can try to reduce one if that helps.
Expected behavior
The class constructor runs in the interpreter, the same way it does on the iOS Simulator.
Actual behavior
The process is killed:
Exception Type: EXC_BAD_ACCESS (SIGKILL)
Exception Subtype: KERN_PROTECTION_FAILURE at 0x000000011ad3b100
VM Region Info: 0x11ad3b100 is in 0x11acb0000-0x11b050000; bytes after start: 569600 bytes before end: 3231487
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
Untagged 11aca4000-11acb0000 [ 48K] ---/rwx SM=NUL
---> Untagged 11acb0000-11b050000 [ 3712K] rw-/rwx SM=COW
Untagged 11b050000-11b06c000 [ 112K] ---/rwx SM=NUL
Termination Reason: CODESIGNING 2 Invalid Page
Kernel Triage: VM - (arg = 0x0) Failed to fault in a page with execute permissions
Thread 0 Crashed:
0 ??? 0x000000011ad3b100
1 libcoreclr void UnmanagedCallersOnlyCaller::InvokeThrowing<unsigned long, MethodTable*>(unsigned long, MethodTable*) + 172
2 libcoreclr MethodTable::RunClassInitEx(Object**) + 420
3 libcoreclr MethodTable::DoRunClassInitThrowing() + 412
4 libcoreclr InitClassHelper + 104
5 App.r2r S_P_CoreLib_System_Runtime_CompilerServices_InitHelpers__InitClassSlow + 80
6 App.r2r S_P_CoreLib_System_Runtime_CompilerServices_InitHelpers__InitClass + 36
7 libcoreclr InterpExecMethod(...) + 8872
8 libcoreclr ExecuteInterpretedMethod + 480
9 libcoreclr InterpreterStubRetI8 + 20
10 libcoreclr CallJittedMethodRetI8 + 36
11 libcoreclr InvokeCalliStub(...) + 168
12 libcoreclr InterpExecMethod(...) + 18644
13 libcoreclr ExecuteInterpretedMethod + 480
14 libcoreclr InterpreterStubRetI8 + 20
15 App.r2r S_P_CoreLib_System_Lazy_1<System___Canon>__ViaFactory + 40
...
Thread 0 crashed with ARM Thread State (64-bit):
x9: 0x000000011ad3b100 x19: 0x0000000164960048 x20: 0x0000000000000000
lr: 0x000000010f7734ec pc: 0x000000011ad3b100
esr: 0x8200000f (Instruction Abort) Permission fault
The call path, from the registers and disassembly:
lris inInitHelpers.CallClassConstructor(composite R2R), right afterblr x19.x20(the instantiating arg) is 0.x19, the cctor entry, is not in any loaded image. The code it reached returned without a call, solris unchanged, and the faulting branch is throughx9.ThePreStubon ios-arm64 ends withbl PreStubWorker; mov x9, x0; ...; br x9. TheStubPrecodeandFixupPrecodetemplates branch throughx10andx11, notx9. So the bad target is the valuePreStubWorkerreturned for the interpreted class constructor.- That value points into a
rw-region with max protectionrwx. On the device it can't be made executable. On the Simulator it can, which would explain why the Simulator works.
This may be related to #131903 (StubLinker stub memory moved to the JIT code allocator). I haven't been able to confirm that.
Regression?
This is the first .NET 11 build of the app on a device. The same app on .NET 10 (Mono, MtouchInterpreter) runs on the same device.
Known Workarounds
None found so far. DOTNET_BackpatchEntryPointSlots=0, set through the bundler environment before runtime start, crashes the same way at the same offset. A build with every assembly in the ReadyToRun composite is being tested and I'll report the result.
Configuration
- .NET SDK 11.0.100, runtime 11.0.0 (
microsoft.netcore.app.runtime.ios-arm6411.0.0) - Microsoft.iOS.Sdk.net11.0_27.2 27.2.11039
- Xcode 27.2, macOS 27.2 (Apple silicon build host)
- Device: iPhone19,2, iOS 27.2 (24B119), TestFlight build
- Composite ReadyToRun (
PublishReadyToRunCompositeRoots+PublishReadyToRunExclude), interpreter for the rest - Not reproducible on the iOS Simulator (iossimulator-arm64), in either Debug or Release with the same roots
Other information
On the Simulator, an lldb breakpoint on InitHelpers.CallClassConstructor during the same startup recorded 1734 cctor calls. Every target was either R2R code or a FixupPrecode in an r-x page; none was in a writable region.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
dotnet-policy-service commentedon Nov 18, 2026
Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.
hovik-aghajanyan commentedon Nov 18, 2026
More findings. (Edited: an earlier version of this comment said some cctor precodes target interpreter bytecode on the Simulator. That was my mistake: I read the StubPrecode data at the FixupPrecode offset. The corrected results are below.)
The cctor slot holds a normal FixupPrecode. In both device crashes,
x19(the valueCallClassConstructorbranches to) is on a 24-byte boundary inside its 16 KB page:0x164960048(slot 3) and0x16674db30(slot 290). The fault address is not on a slot boundary (0x...3100). So the slot is an ordinary template-mappedFixupPrecode. The bad address is the valuePreStubWorkerreturns, whichThePreStubbranches to withbr x9.The Simulator never reaches that state. I used the same Release configuration and the same composite roots as the device build. During startup, an lldb script recorded the
x0argument of everyInitHelpers.CallClassConstructorcall. After startup it decoded each precode,ldr x11for Fixup andldr x10for Stub, and read its target field:FixupPrecode, target is still its own fixup pathStubPrecode, target is inlibcoreclrNo target points outside executable code. I also hooked
MethodDesc::SetCodeEntryPoint,SetNativeCodeInterlockedandSetStableEntryPointInterlocked(about 1,900 calls each during startup). None was passed an address whose first word is not an instruction. On the Simulator,PreStubWorkernever produces an entry point like the one seen on the device, so this does not reproduce there.Correction to the original report. I have no evidence for #131903. As far as I can tell, the old executable
LoaderHeapand the new code-heap path commit pages the same way throughExecutableAllocator::Commit(PAGE_READWRITEwithoutFEATURE_DYNAMIC_CODE_COMPILED). Nothing shows that the target is a StubLinker stub. Please disregard that pointer.What remains: on the device,
PreStubWorkerreturns an address in a read-write region of 3712 KB (max protectionrwx) for an interpreted class constructor that is reached from R2R code. The address is the same every run. I can't attach a debugger to the device build right now, but I can run any Simulator experiment that would help.Respect AllowR2RForImage in Unix LoadedImageLayout
hovik-aghajanyan commentedon Nov 19, 2026
I found the root cause by debugging a development build on the device (iPhone19,2, iOS 27.2). It is not the interpreter: the class constructor's own ReadyToRun code is run from an image the runtime mapped itself.
What happens.
Microsoft.CodeAnalysis.Razor.Compiler.dllships with its own ReadyToRun code for Apple arm64 (machine0xEC20). The app leaves it out of the composite (PublishReadyToRunExclude), so the file keeps that code. At the crash:MethodDesc::GetName()of the cctor slot's MethodDesc returns.cctor, andGetNativeCode()returns the faulting PC.stp x29, x30, [sp, #-0x30]!…), not data..text:.textis 3,786,752 bytes at RVA0x10200, which rounds up to the 3712 KBrw-region in the crash report. The fault offset 569600 is RVA0x9B100, and the 32 bytes at the faulting PC are identical to the bytes at that RVA in the DLL.Why the runtime accepts that code.
AllowR2RForImage()insrc/coreclr/vm/peimagelayout.cppreturnsfalseon iOS, tvOS and Mac Catalyst, andLoadConverted/ConvertedImageLayoutrespect that. A file that isn't in a bundle goes throughLoadedImageLayouton Unix, though. There,PAL_LOADLoadPEFilemaps the file, and the constructor relocates it and callsSetRelocated()whenever it has a ReadyToRun header, without askingAllowR2RForImage().ReadyToRunInfo::Initializethen sees a relocated image and uses its native code. On a device those pages are not executable, so the first call into the image is aCODESIGNING Invalid Pagekill. I assume the Simulator can execute them, which would explain why it works there, but I haven't checked that.Confirmation. The same build with
DOTNET_ReadyToRunExcludeListset to the 129 assemblies in the app that carry their own ReadyToRun code (Razor compiler, ASP.NET Core andMicrosoft.Extensions.*from the shared framework) starts on the device and reaches its main screen.main. As far as I can tell,mainisn't affected: #135902 removed the UnixLoadedImageLayoutpath, and Unix now always goes throughConvertedImageLayout, which only relocates whenAllowR2RForImage()allows it. So this affectsrelease/11.0(11.0.0). I opened a PR againstrelease/11.0that applies the sameAllowR2RForImage()check in the UnixLoadedImageLayoutconstructor: #137886Workaround until then: set
DOTNET_ReadyToRunExcludeListto the assemblies that have their own (non-component) ReadyToRun code.I've retitled the issue to match.
[-][iOS][CoreCLR] App killed at launch on device (CODESIGNING "Invalid Page") when R2R code runs an interpreted class constructor through ThePreStub[/-][+][iOS][CoreCLR] 11.0: app killed on device when an assembly with its own ReadyToRun code is loaded through the Unix LoadedImageLayout[/+]jkotas commentedon Nov 21, 2026
Where did you get the Microsoft.CodeAnalysis.Razor.Compiler.dll binary from?
We do not really support constructing apps by manually copying binaries from different places.
hovik-aghajanyan commentedon Nov 21, 2026
From the .NET SDK installed on the build Mac. The app is a C# IDE that compiles and runs Razor and ASP.NET Core code on the device. I couldn't find a package with these binaries, so the project references them by path:
Microsoft.CodeAnalysis.Razor.Compiler.dllandMicrosoft.AspNetCore.Razor.Utilities.Shared.dllcome fromsdk/11.0.100/Sdks/Microsoft.NET.Sdk.Razor/source-generators/.Microsoft.Extensions.*ones that ship with them, come fromshared/Microsoft.AspNetCore.App/11.0.0/. An iOS app can't take aFrameworkReferencetoMicrosoft.AspNetCore.App.These are the osx-arm64 builds. They're ReadyToRun-compiled for machine
0xEC20, the same value ios-arm64 uses, so the runtime accepts their code.I understand this isn't a supported way to build an app, and I'm not asking you to support it. On our side I'll keep the
DOTNET_ReadyToRunExcludeListworkaround. If there's a supported source for these assemblies that works for an iOS app, please point me to it and I'll switch.About the PR: on iOS the runtime already chooses not to use an image's own ReadyToRun code (
AllowR2RForImage()).ConvertedImageLayoutandmainfollow that choice, and only the UnixLoadedImageLayoutpath inrelease/11.0skips it. When an assembly like this ends up in an app, the result is aCODESIGNINGkill with no managed stack instead of the assembly running as IL. I think the check is worth having for that reason, but if you'd rather not service it, feel free to close the PR.