- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.2k
[clr-ios] Use IL unboxing stubs when FEATURE_JIT isn't available #121115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clr-ios] Use IL unboxing stubs when FEATURE_JIT isn't available #121115
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR addresses a critical runtime issue on iOS and other Apple mobile platforms where dynamic code generation is prohibited due to W^X (write XOR execute) memory protection and code-signing restrictions. The change prevents the runtime from attempting to emit native ARM64 machine code at execution time for unboxing and instantiating stubs.
Key Changes:
- Renamed FEATURE_PORTABLE_SHUFFLE_THUNKStoFEATURE_SHUFFLE_THUNKSand made it conditional onFEATURE_JITavailability
- Extended ARM64 platforms to use IL-based stubs instead of runtime code generation when JIT is unavailable
- Updated conditional compilation directives across multiple files to respect the new feature flag semantics
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description | 
|---|---|
| src/coreclr/inc/switches.h | Modified feature flag definition to only enable shuffle thunks when JIT is available | 
| src/coreclr/vm/prestub.cpp | Updated conditional compilation to use renamed feature flag for stub selection logic | 
| src/coreclr/vm/i386/stublinkerx86.h | Changed guard condition for EmitUnboxMethodStub declaration from TARGET_X86 to feature-based check | 
| src/coreclr/vm/i386/stublinkerx86.cpp | Updated conditional compilation for EmitUnboxMethodStub implementation | 
| src/coreclr/vm/comdelegate.cpp | Reorganized shuffle array generation logic to use feature flag instead of platform-specific checks | 
| src/coreclr/vm/arm64/stubs.cpp | Added ARM64 implementation of EmitUnboxMethodStub for non-JIT scenarios | 
| src/coreclr/vm/arm64/cgencpu.h | Added EmitUnboxMethodStub method declaration guarded by feature flag | 
| Tagging subscribers to this area: @BrzVlad, @janvorli, @kg | 
| @kotlarmilos Could you please check whether it is still fixing the problem that it was meant to fix? | 
| Thanks Jan, this was educational :) I confirm it fixes dynamic code generation for MakeUnboxingStubWorker and MakeInstantiatingStubWorker. | 
| /ba-g infrastructure timeouts | 
Description
This change prevents the runtime from emitting native machine code at execution time through StubLinkerCPU on platforms where dynamic code generation is not allowed due to W^X and code-signing restrictions. Currently, unboxing and generic instantiating stubs still generate arm64 code via CPUSTUBLINKER that works as a lightweight JIT, because FEATURE_PORTABLE_SHUFFLE_THUNKS is enabled on all non-x86 targets.
Changes
This PR renames FEATURE_PORTABLE_SHUFFLE_THUNKS to FEATURE_SHUFFLE_THUNKS and only enables it when FEATURE_JIT is available. This instructs Apple mobile to use IL-based unboxing and instantiating stubs instead of emitting code at runtime, avoiding invalid memory execution.