Skip to content

Add basic handling of OptimizationPreference for crossgen2 on mobile r2r#130300

Open
BrzVlad wants to merge 2 commits into
dotnet:mainfrom
BrzVlad:feature-mobile-r2r-opt
Open

Add basic handling of OptimizationPreference for crossgen2 on mobile r2r#130300
BrzVlad wants to merge 2 commits into
dotnet:mainfrom
BrzVlad:feature-mobile-r2r-opt

Conversation

@BrzVlad

@BrzVlad BrzVlad commented Jul 7, 2026

Copy link
Copy Markdown
Member

This also makes the r2r use the size opt (--Os) as a default on mobile.
Refactor repeated rid check by using _IsIOSLikeRid like we do in the sdk.
Disable the strip flags on debug builds, to match the sdk.
Enable --strip-debug-info and --strip-inlining-info on android release as well. --strip-il-bodies is not enabled because IL should still be needed for tiered jit.

Copilot AI review requested due to automatic review settings July 7, 2026 14:12
@github-actions github-actions Bot added the area-crossgen2-coreclr only use for closed issues label Jul 7, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 updates the Crossgen2 MSBuild targets used for ReadyToRun publishing to better align mobile (iOS-like + Android) behavior with OptimizationPreference, reduce duplicated RID checks, and adjust default stripping behavior for mobile builds.

Changes:

  • Introduces _IsIOSLikeRid / _IsAndroidRid helper properties and uses them to simplify mobile RID conditionals.
  • Defaults Crossgen2 to size-focused optimization (--Os) on mobile when OptimizationPreference is unset or Size, and uses --Ot when it is Speed (only when $(Optimize) is true).
  • Applies Crossgen2 --strip-debug-info / --strip-inlining-info on Android as well (and disables these strip flags for Debug / DebuggerSupport builds), while keeping --strip-il-bodies iOS-like only.

<PublishReadyToRunCrossgen2ExtraArgs Condition="'$(PublishReadyToRunStripDebugInfo)' != 'false' and $(RuntimeIdentifier.StartsWith('iossimulator-'))">$(PublishReadyToRunCrossgen2ExtraArgs);--strip-debug-info</PublishReadyToRunCrossgen2ExtraArgs>
<PublishReadyToRunCrossgen2ExtraArgs Condition="'$(PublishReadyToRunStripDebugInfo)' != 'false' and $(RuntimeIdentifier.StartsWith('tvossimulator-'))">$(PublishReadyToRunCrossgen2ExtraArgs);--strip-debug-info</PublishReadyToRunCrossgen2ExtraArgs>
<PublishReadyToRunCrossgen2ExtraArgs Condition="'$(PublishReadyToRunStripDebugInfo)' != 'false' and $(RuntimeIdentifier.StartsWith('maccatalyst-'))">$(PublishReadyToRunCrossgen2ExtraArgs);--strip-debug-info</PublishReadyToRunCrossgen2ExtraArgs>
<PublishReadyToRunCrossgen2ExtraArgs Condition="'$(PublishReadyToRunStripInliningInfo)' != 'false' and '$(DebuggerSupport)' != 'true' and '$(Configuration)' != 'Debug' and ('$(_IsIOSLikeRid)' == 'true' or '$(_IsAndroidRid)' == 'true')">$(PublishReadyToRunCrossgen2ExtraArgs);--strip-inlining-info</PublishReadyToRunCrossgen2ExtraArgs>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The properties here get duplicated in the command since they also come from the sdk, once the sdk gets updated. This enables imediate testing but I'm wondering if this code should be removed in the future, once we bump to a preview containing the corresponding sdk changes.

Comment thread src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets

@kotlarmilos kotlarmilos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Comment on lines +39 to +40
<PublishReadyToRunCrossgen2ExtraArgs Condition="'$(Optimize)' == 'true' and ('$(_IsIOSLikeRid)' == 'true' or '$(_IsAndroidRid)' == 'true') and ('$(OptimizationPreference)' == 'Size' or '$(OptimizationPreference)' == '')">--Os;$(PublishReadyToRunCrossgen2ExtraArgs)</PublishReadyToRunCrossgen2ExtraArgs>
<PublishReadyToRunCrossgen2ExtraArgs Condition="'$(Optimize)' == 'true' and ('$(_IsIOSLikeRid)' == 'true' or '$(_IsAndroidRid)' == 'true') and '$(OptimizationPreference)' == 'Speed'">--Ot;$(PublishReadyToRunCrossgen2ExtraArgs)</PublishReadyToRunCrossgen2ExtraArgs>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my understanding - why did you choose --Os over --Ot as the default optimization preference?

@davidnguyen-tech

Copy link
Copy Markdown
Member

Copilot says that this PR is causing some failures on iOS + macCatalyst because of the new --strip-il-bodies

@BrzVlad

BrzVlad commented Jul 8, 2026

Copy link
Copy Markdown
Member Author
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error : Error: Object reference not set to an instance of an object. [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error : System.NullReferenceException: Object reference not set to an instance of an object. [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRun.CopiedMethodILNode.GetData(NodeFactory factory, Boolean relocsOnly) in /_/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedMethodILNode.cs:line 59 [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRun.CopiedMethodILDeduplicator.InternKey..ctor(CopiedMethodILNode node, NodeFactory factory) in /_/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedMethodILDeduplicator.cs:line 68 [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRun.CopiedMethodILDeduplicator.DeduplicatePass(NodeFactory factory, Dictionary`2 previousSymbolRemapping, Dictionary`2 symbolRemapping) in /_/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedMethodILDeduplicator.cs:line 40 [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error :    at ILCompiler.ObjectDataInterner.EnsureMap(NodeFactory factory) in /_/src/coreclr/tools/Common/Compiler/ObjectDataInterner.cs:line 51 [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error :    at ILCompiler.ObjectDataInterner.GetDeduplicatedSymbol(NodeFactory factory, ISymbolNode original) in /_/src/coreclr/tools/Common/Compiler/ObjectDataInterner.cs:line 79 [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error :    at ILCompiler.ObjectWriter.ObjectWriter.EmitObject(Stream outputFileStream, IReadOnlyCollection`1 nodes, IObjectDumper dumper, Logger logger) in /_/src/coreclr/tools/Common/Compiler/ObjectWriter/ObjectWriter.cs:line 383 [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRunObjectWriter.EmitReadyToRunObjects(ReadyToRunContainerFormat format, Logger logger) in /_/src/coreclr/tools/aot/ILCompiler.ReadyToRun/CodeGen/ReadyToRunObjectWriter.cs:line 191 [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRunObjectWriter.EmitObject(String objectFilePath, EcmaModule componentModule, IEnumerable`1 inputFiles, IReadOnlyCollection`1 nodes, NodeFactory factory, Boolean generateMapFile, Boolean generateMapCsvFile, Boolean generatePdbFile, String pdbPath, Boolean generatePerfMapFile, String perfMapPath, Int32 perfMapFormatVersion, Boolean generateProfileFile, CallChainProfile callChainProfile, ReadyToRunContainerFormat format, Int32 customPESectionAlignment, Logger logger) in /_/src/coreclr/tools/aot/ILCompiler.ReadyToRun/CodeGen/ReadyToRunObjectWriter.cs:line 345 [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error :    at ILCompiler.ReadyToRunCodegenCompilation.Compile(String outputFile) in /_/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs:line 413 [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error :    at ILCompiler.Program.RunSingleCompilation(Dictionary`2 inFilePaths, InstructionSetSupport instructionSetSupport, String compositeRootPath, Dictionary`2 unrootedInputFilePaths, HashSet`1 versionBubbleModulesHash, ReadyToRunCompilerContext typeSystemContext, Logger logger) in /_/src/coreclr/tools/aot/crossgen2/Program.cs:line 691 [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error :    at ILCompiler.Program.Run() in /_/src/coreclr/tools/aot/crossgen2/Program.cs:line 314 [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]

@kotlarmilos Any idea about this before I try to reproduce ? Seems weird since this options should be part of P5, so reasonably well tested already

@kotlarmilos

Copy link
Copy Markdown
Member
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error : Error: Object reference not set to an instance of an object. [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error : System.NullReferenceException: Object reference not set to an instance of an object. [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRun.CopiedMethodILNode.GetData(NodeFactory factory, Boolean relocsOnly) in /_/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedMethodILNode.cs:line 59 [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRun.CopiedMethodILDeduplicator.InternKey..ctor(CopiedMethodILNode node, NodeFactory factory) in /_/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedMethodILDeduplicator.cs:line 68 [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRun.CopiedMethodILDeduplicator.DeduplicatePass(NodeFactory factory, Dictionary`2 previousSymbolRemapping, Dictionary`2 symbolRemapping) in /_/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/CopiedMethodILDeduplicator.cs:line 40 [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error :    at ILCompiler.ObjectDataInterner.EnsureMap(NodeFactory factory) in /_/src/coreclr/tools/Common/Compiler/ObjectDataInterner.cs:line 51 [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error :    at ILCompiler.ObjectDataInterner.GetDeduplicatedSymbol(NodeFactory factory, ISymbolNode original) in /_/src/coreclr/tools/Common/Compiler/ObjectDataInterner.cs:line 79 [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error :    at ILCompiler.ObjectWriter.ObjectWriter.EmitObject(Stream outputFileStream, IReadOnlyCollection`1 nodes, IObjectDumper dumper, Logger logger) in /_/src/coreclr/tools/Common/Compiler/ObjectWriter/ObjectWriter.cs:line 383 [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRunObjectWriter.EmitReadyToRunObjects(ReadyToRunContainerFormat format, Logger logger) in /_/src/coreclr/tools/aot/ILCompiler.ReadyToRun/CodeGen/ReadyToRunObjectWriter.cs:line 191 [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRunObjectWriter.EmitObject(String objectFilePath, EcmaModule componentModule, IEnumerable`1 inputFiles, IReadOnlyCollection`1 nodes, NodeFactory factory, Boolean generateMapFile, Boolean generateMapCsvFile, Boolean generatePdbFile, String pdbPath, Boolean generatePerfMapFile, String perfMapPath, Int32 perfMapFormatVersion, Boolean generateProfileFile, CallChainProfile callChainProfile, ReadyToRunContainerFormat format, Int32 customPESectionAlignment, Logger logger) in /_/src/coreclr/tools/aot/ILCompiler.ReadyToRun/CodeGen/ReadyToRunObjectWriter.cs:line 345 [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error :    at ILCompiler.ReadyToRunCodegenCompilation.Compile(String outputFile) in /_/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs:line 413 [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error :    at ILCompiler.Program.RunSingleCompilation(Dictionary`2 inFilePaths, InstructionSetSupport instructionSetSupport, String compositeRootPath, Dictionary`2 unrootedInputFilePaths, HashSet`1 versionBubbleModulesHash, ReadyToRunCompilerContext typeSystemContext, Logger logger) in /_/src/coreclr/tools/aot/crossgen2/Program.cs:line 691 [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]
/Users/runner/work/1/s/artifacts/bin/Crossgen2Tasks/Release/Microsoft.NET.CrossGen.targets(489,5): error :    at ILCompiler.Program.Run() in /_/src/coreclr/tools/aot/crossgen2/Program.cs:line 314 [/Users/runner/work/1/s/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj]

@kotlarmilos Any idea about this before I try to reproduce ? Seems weird since this options should be part of P5, so reasonably well tested already

No, I haven't seen this before. Could it happen if stripping is performed twice over the same assembly?

@kotlarmilos

Copy link
Copy Markdown
Member

Copilot says that this PR is causing some failures on iOS + macCatalyst because of the new --strip-il-bodies

This shouldn't be the case, it is already enabled in P5 on Apple mobile

@davidnguyen-tech

Copy link
Copy Markdown
Member

I'm trying to reproduce the failures locally, will keep you updated.

@davidnguyen-tech

Copy link
Copy Markdown
Member

Note

🤖 This comment was authored by GitHub Copilot (CLI) at the request of the account owner.

Root cause of the ios-arm64 / maccatalyst-arm64 R2R CI failures:

--strip-il-bodies was built to work only in composite R2R mode (all assemblies compiled into a single image). Proof:

But the iOS functional-test R2R build compiles in non-composite mode (per-assembly, --obj-format:pe, no --composite) — confirmed from the failing build's binlog. So the flag's check dereferences the null CompiledMethodDefs and crossgen2 dies with a NullReferenceException (CopiedMethodILNode.cs#L59) → the NETSDK1096 failure.

@kotlarmilos

Copy link
Copy Markdown
Member

@davidnguyen-tech Thanks, this is good direction!

--strip-il-bodies was built to work only in composite R2R mode (all assemblies compiled into a single image). Proof:

Correct, this PR adds --strip-il-bodies to the general PublishReadyToRunCrossgen2ExtraArgs, which the RunReadyToRunCompiler task appends to every crossgen2 invocation. The SDK only ever adds it through Crossgen2CompositeExtraCommandLineArgs, gated on PublishReadyToRunComposite == true.

But the iOS functional-test R2R build compiles in non-composite mode (per-assembly, --obj-format:pe, no --composite) — confirmed from the failing build's binlog

This could be a bug in how the functional tests are built where the composite mode isn't set properly. I confirmed the libraries and runtime tests run in composite mode.

Copilot AI review requested due to automatic review settings July 9, 2026 09:49
@BrzVlad

BrzVlad commented Jul 9, 2026

Copy link
Copy Markdown
Member Author

Tried to reproduce locally but failed. The functional tests are weird: https://github.com/dotnet/runtime/blob/main/src/tests/FunctionalTests/iOS/Simulator/CoreCLR/iOS.CoreCLR.R2R.Test.csproj, they set PublishReadyToRun manually. I suspect adding PublishReadyToRunComposite in this project might fix it as well. Anyhow, for now I just made crossgen2 not trip over strip-il-bodies in non composite mode

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets
Comment thread src/coreclr/tools/aot/crossgen2/Program.cs
Comment thread src/coreclr/tools/aot/crossgen2/Program.cs Outdated
Copilot AI review requested due to automatic review settings July 9, 2026 11:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets
nodeFactoryFlags.StripILBodies = Get(_command.StripILBodies);
if (nodeFactoryFlags.StripILBodies && !composite)
{
throw new Exception(SR.ErrorStripILBodiesRequiresComposite);
Comment thread src/coreclr/tools/aot/crossgen2/Properties/Resources.resx Outdated
Copilot AI review requested due to automatic review settings July 10, 2026 09:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 2

Comment thread src/coreclr/tools/aot/crossgen2/Program.cs
Comment thread src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets
BrzVlad added 2 commits July 13, 2026 13:29
This also makes the r2r use the size opt (--Os) as a default on mobile.
Refactor repeated rid check by using `_IsIOSLikeRid` like we do in the sdk.
Disable the strip flags on debug builds, to match the sdk
Enable --strip-debug-info and --strip-inlining-info on android release as well. --strip-il-bodies is not enabled because IL should still be needed for tiered jit.
Copilot AI review requested due to automatic review settings July 13, 2026 10:48
@BrzVlad BrzVlad force-pushed the feature-mobile-r2r-opt branch from 264b1d2 to 40cf589 Compare July 13, 2026 10:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets
Comment thread src/coreclr/tools/aot/crossgen2/Properties/Resources.resx
<PublishReadyToRunCrossgen2ExtraArgs Condition="'$(PublishReadyToRunStripDebugInfo)' != 'false' and '$(DebuggerSupport)' != 'true' and '$(Configuration)' != 'Debug' and ('$(_IsIOSLikeRid)' == 'true' or '$(_IsAndroidRid)' == 'true')">$(PublishReadyToRunCrossgen2ExtraArgs);--strip-debug-info</PublishReadyToRunCrossgen2ExtraArgs>
<PublishReadyToRunCrossgen2ExtraArgs Condition="'$(PublishReadyToRunStripILBodies)' != 'false' and '$(DebuggerSupport)' != 'true' and '$(Configuration)' != 'Debug' and '$(_IsIOSLikeRid)' == 'true'">$(PublishReadyToRunCrossgen2ExtraArgs);--strip-il-bodies</PublishReadyToRunCrossgen2ExtraArgs>

<PublishReadyToRunCrossgen2ExtraArgs Condition="'$(Optimize)' == 'true' and ('$(_IsIOSLikeRid)' == 'true' or '$(_IsAndroidRid)' == 'true') and ('$(OptimizationPreference)' == 'Size' or '$(OptimizationPreference)' == '')">--Os;$(PublishReadyToRunCrossgen2ExtraArgs)</PublishReadyToRunCrossgen2ExtraArgs>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MichalStrehovsky Should we add Balanced to differentiate from unset here? Then for mobiles unset would be size but otherwise it'd be Balanced.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That depends on how crossgen wants to document this. Defaulting to size already doesn't match the native AOT behaviors or documentation, so crossgen can do whatever it wants.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The native AOT docs literally say setting this to Size will prefer size at the cost of any other metric (startup, memory, etc.) and the user is supposed to measure whether the compromise is worth it to them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-crossgen2-coreclr only use for closed issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants