Repository navigation
[release/11.0] Respect AllowR2RForImage in Unix LoadedImageLayout - #137886
Open
hovik-aghajanyan wants to merge 1 commit into
Open
hovik-aghajanyan wants to merge 1 commit into
hovik-aghajanyan wants to merge 1 commit into
Conversation
AllowR2RForImage returns false on iOS, tvOS and Mac Catalyst, but the Unix LoadedImageLayout constructor relocated every image with a ReadyToRun header and marked it relocated without checking it. ReadyToRunInfo::Initialize then used the native code of an assembly that ships its own ReadyToRun code, running it from pages the runtime mapped itself. On an iOS device those pages are not executable, so the app is killed (CODESIGNING Invalid Page) on the first call into such an assembly. Relocate only when AllowR2RForImage allows it, so those images stay IL-only on these platforms. main already behaves this way since the Unix LoadedImageLayout path was removed. Fix dotnet#137837
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/crossgen-contrib |
This was referenced Nov 19, 2026
hovik-aghajanyan
marked this pull request as ready for review
November 19, 2026 10:21
BrzVlad
reviewed
Nov 20, 2026
| // AllowR2RForImage is false on iOS, tvOS and Mac Catalyst, where native code in an image mapped here can't | ||
| // run (on an iOS device its pages are not executable). Leave the image unrelocated there, so that | ||
| // ReadyToRunInfo::Initialize ignores its native code. Component assemblies of a composite image are not affected. | ||
| if (AllowR2RForImage(pOwner)) |
Member
There was a problem hiding this comment.
I believe it makes more sense to move this check next to HasReadyToRunHeader above
Member
|
We shouldn't be including assemblies with r2r code on iOS, so a full fix, that might also result in some size gains, would be to trim this code out as part of the build. Seems like this was behaving the same on mono, so it should be fine to leave this improvement to .net12. @jkoritzinsky Could you review this as well. Does it make sense to backport it like this to 11 directly ? |
Member
We should understand where the offending assembly came from first - #137837 (comment) |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes Issue #137837
main PR: none needed. #135902 removed the Unix
LoadedImageLayoutpath onmain, so there every image goes throughConvertedImageLayout, which already checksAllowR2RForImage().Description
On iOS, tvOS and Mac Catalyst,
AllowR2RForImage()returnsfalse, so the runtime should not use ReadyToRun code from an image it maps itself. The UnixLoadedImageLayoutconstructor, used for assemblies that are plain files, doesn't check it: it relocates any image with a ReadyToRun header and callsSetRelocated().ReadyToRunInfo::Initializethen accepts the image and runs its native code from pages the runtime mapped itself.On an iOS device those pages are not executable. The first call into such an assembly kills the app with
EXC_BAD_ACCESS (SIGKILL)/CODESIGNING Invalid Page. In #137837 the assembly isMicrosoft.CodeAnalysis.Razor.Compiler.dll(ReadyToRun for Apple arm64). The ASP.NET Core andMicrosoft.Extensions.*assemblies from the shared framework carry ReadyToRun code too.This change relocates the image only when
AllowR2RForImage()allows it. On those platforms the image stays unrelocated, soReadyToRunInfo::Initializeignores its native code ("module not loaded for execution") and the methods run in the interpreter. That matches whatmaindoes after #135902. Component assemblies of a composite image don't depend on the relocated flag, so they keep using the composite.Customer Impact
An iOS app on .NET 11 with CoreCLR is killed on a physical device as soon as it calls into an assembly that already ships its own ReadyToRun code and isn't compiled into the app's composite. In #137837 that is
Microsoft.CodeAnalysis.Razor.Compiler.dll, and the app also carries ASP.NET Core andMicrosoft.Extensions.*assemblies with their own ReadyToRun code. I haven't checked whether a default SDK build ends up in this state. The Simulator doesn't show the problem, so it's found only on a device or TestFlight.The workaround is to list each such assembly in
DOTNET_ReadyToRunExcludeList.Regression
Not in the usual sense: CoreCLR on iOS is new in .NET 11. The same app on .NET 10 (Mono) runs on the device.
Testing
GetNativeCode()of the class constructor's MethodDesc is the faulting PC. That address is insideMicrosoft.CodeAnalysis.Razor.Compiler.dll's.text, mapped read-write, and the bytes there match the DLL.DOTNET_ReadyToRunExcludeListset to the 129 assemblies with their own ReadyToRun code starts on the device and reaches its main screen. The exclude list and this change take different routes, but both makeReadyToRunInfo::Initializeignore those images' native code.Risk
Low. The change only affects targets where
AllowR2RForImage()returnsfalse(iOS, tvOS, Mac Catalyst). Everywhere elseAllowR2RForImage()istruefor files, which is the only case that reaches this constructor, so behavior is unchanged.On iOS and tvOS devices, those assemblies now run in the interpreter instead of crashing. On the Simulator and on Mac Catalyst, if their own ReadyToRun code ran before, it no longer does, so they may start more slowly there. That is also how
mainbehaves since #135902. Composite ReadyToRun code isn't affected.