Make CoreCLR + crossgen2 ioslike via --dynamiccodecompiled false#124168
Make CoreCLR + crossgen2 ioslike via --dynamiccodecompiled false#124168BrzVlad merged 5 commits intodotnet:mainfrom
Conversation
|
Tagging subscribers to this area: @BrzVlad, @janvorli, @kg |
There was a problem hiding this comment.
Pull request overview
Adds a new build-time switch (--clrnodynamiccodegen) to configure CoreCLR + crossgen2 into an “iOS-like” mode where dynamic executable code generation is disabled (JIT off, interpreter on), primarily for desktop perf/debug investigations without deploying to devices.
Changes:
- Introduces
FeatureNoDynamicCodeGen/FEATURE_NO_DYNAMIC_CODEGENplumbing across MSBuild, CMake, CoreCLR, and crossgen2. - Updates runtime feature flags/config defaults and executable memory allocation behaviors to match no-dynamic-codegen constraints.
- Adds CLI surface area in
eng/build.shandeng/build.ps1to enable the configuration.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeFeature.NonNativeAot.cs | Makes RuntimeFeature.IsDynamicCodeCompiled return false under FEATURE_NO_DYNAMIC_CODEGEN. |
| src/coreclr/vm/peimagelayout.cpp | Adjusts use of MEM_RESERVE_EXECUTABLE for image loading allocations under the new feature. |
| src/coreclr/utilcode/executableallocator.cpp | Alters executable allocator commit/reserve behavior to avoid executable allocations under the new feature. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/ILCompiler.ReadyToRun.csproj | Defines FEATURE_NO_DYNAMIC_CODEGEN constant for crossgen2 build when enabled. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCompilerContext.cs | Forces TargetAllowsRuntimeCodeGeneration to false under the new feature. |
| src/coreclr/runtime.proj | Plumbs FeatureNoDynamicCodeGen to native build via -DFEATURE_NO_DYNAMIC_CODEGEN=1. |
| src/coreclr/inc/clrconfigvalues.h | Aligns config defaults (e.g., cached interface dispatch, write barrier copy) with no-dynamic-codegen behavior. |
| src/coreclr/clrfeatures.cmake | Disables JIT-related features and enables embedded-style behaviors when FEATURE_NO_DYNAMIC_CODEGEN is set. |
| src/coreclr/clrdefinitions.cmake | Adds compile definition emission for FEATURE_NO_DYNAMIC_CODEGEN. |
| src/coreclr/clr.featuredefines.props | Adds managed FEATURE_NO_DYNAMIC_CODEGEN define constant when FeatureNoDynamicCodeGen=true. |
| eng/build.sh | Adds --clrnodynamiccodegen switch to set FeatureInterpreter=true and FeatureNoDynamicCodeGen=true. |
| eng/build.ps1 | Adds -clrnodynamiccodegen switch equivalent for Windows builds. |
Comments suppressed due to low confidence (1)
src/coreclr/vm/peimagelayout.cpp:841
- On Unix (including macOS),
LoadImageByCopyingPartsalways allocates RW memory and later flips executable sections toPAGE_EXECUTE_*. The comment statesMEM_RESERVE_EXECUTABLEis required on macOS for this pattern; however, the new!defined(FEATURE_NO_DYNAMIC_CODEGEN)guard disablesMEM_RESERVE_EXECUTABLEwhen the new flag is used. This can causeClrVirtualProtectto fail when marking R2R sections executable on macOS, making the new--clrnodynamiccodegenmode unusable there. Consider leavingMEM_RESERVE_EXECUTABLEenabled on macOS (or reworking the copy/protect flow to stay compatible with hardened runtime/W^X constraints).
#if defined(HOST_UNIX) && !defined(TARGET_IOS) && !defined(TARGET_TVOS) && !defined(TARGET_MACCATALYST) && !defined(FEATURE_NO_DYNAMIC_CODEGEN)
// Tell PAL to use the executable memory allocator to satisfy this request for virtual memory.
// This is required on MacOS and otherwise will allow us to place native R2R code close to the
// coreclr library and thus improve performance by avoiding jump stubs in managed code.
allocationType |= MEM_RESERVE_EXECUTABLE;
...es/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeFeature.NonNativeAot.cs
Outdated
Show resolved
Hide resolved
🤖 Copilot Code Review — PR #124168Holistic AssessmentMotivation: This PR enables building CoreCLR with iOS-like configuration on desktop platforms for testing and development purposes. This is a valid and useful capability for testing interpreter/no-JIT scenarios without needing actual iOS hardware or simulator. Approach: Using a compile-time Net positive/negative: Net positive - adds testing capability without affecting default builds. Detailed Findings
|
cdbd60d to
d12f405
Compare
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCompilerContext.cs
Show resolved
Hide resolved
…ED being defined FEATURE_JIT uses are removed and FEATURE_DYNAMIC_CODE_COMPILED is used instead FEATURE_DYNAMIC_CODE_COMPILED will also set knobs that we expect to use on all platforms where jit-ing is not allowed. If `--dynamiccodecompiled` value is not passed to the build, then it will be set to the default value based on the target. The build will always end up receiving the final property value in `FeatureDynamicCodeCompiled`.
150a3e9 to
557ba32
Compare
ad0b951 to
b7b5d6a
Compare
iOS build will use crossgen2 built on desktop, which will always have `FEATURE_DYNAMIC_CODE_COMPILED` defined. We still need to resolve this property by checking the actual target platform. If we build the runtime without `FEATURE_DYNAMIC_CODE_COMPILED` then we can hardcode the behavior in crossgen2, as always false.
b7b5d6a to
d57b83d
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 26 out of 26 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCompilerContext.cs:113
- There's an undefined variable
archand an incorrect enum value. The code should useTarget.Architectureinstead ofarch, andTargetArchitecture.Wasm32instead ofTargetArchitecture.Wasm(since onlyWasm32exists in the TargetArchitecture enum).
if (Target.Architecture is TargetArchitecture.Wasm32)
On desktop, for example, this enables building the runtime with
./build.sh -subset clr -c Release -dynamiccodecompiled false.This configures the runtime to behave very similar to what would run on iOS, where we are not allowed to generate dynamic executable code. This configuration mainly disables jit, enables interpreter, enables cached interface dispatch, sets
IsDynamicCodeCompiledto false, enables cached interface dispatch support incrossgen2compiled images.This option is meant to be used for convenience, when doing perf testing or bug investigation, without having to build/deploy for actual devices.