From e7ac39f0ee9a6ca777f6d7f8634a715b26cfae9e Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Thu, 19 Feb 2026 17:32:03 +0100 Subject: [PATCH] [clr-ios] Add options to strip inlining and debug info in Crossgen2 --- .../ReadyToRunCodegenNodeFactory.cs | 22 +++++++++++++------ .../aot/crossgen2/Crossgen2RootCommand.cs | 6 +++++ src/coreclr/tools/aot/crossgen2/Program.cs | 2 ++ .../aot/crossgen2/Properties/Resources.resx | 6 +++++ .../Microsoft.NET.CrossGen.targets | 12 ++++++++++ 5 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRunCodegenNodeFactory.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRunCodegenNodeFactory.cs index a2a846481e3091..d53e4f03074115 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRunCodegenNodeFactory.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRunCodegenNodeFactory.cs @@ -62,6 +62,8 @@ public struct NodeFactoryOptimizationFlags public bool PrintReproArgs; public bool EnableCachedInterfaceDispatchSupport; public bool IsComponentModule; + public bool StripInliningInfo; + public bool StripDebugInfo; } // To make the code future compatible to the composite R2R story @@ -753,7 +755,7 @@ public void AttachToDependencyGraph(DependencyAnalyzerBase graph, I TypesTableNode typesTable = new TypesTableNode(inputModule); tableHeader.Add(Internal.Runtime.ReadyToRunSectionType.AvailableTypes, typesTable, typesTable); - if (CompilationModuleGroup.IsCompositeBuildMode) + if (CompilationModuleGroup.IsCompositeBuildMode && !OptimizationFlags.StripInliningInfo) { InliningInfoNode inliningInfoTable = new InliningInfoNode(inputModule, InliningInfoNode.InfoType.InliningInfo2); tableHeader.Add(Internal.Runtime.ReadyToRunSectionType.InliningInfo2, inliningInfoTable, inliningInfoTable); @@ -788,10 +790,13 @@ public void AttachToDependencyGraph(DependencyAnalyzerBase graph, I } } - InliningInfoNode crossModuleInliningInfoTable = new InliningInfoNode(null, - CompilationModuleGroup.IsCompositeBuildMode ? InliningInfoNode.InfoType.CrossModuleInliningForCrossModuleDataOnly : InliningInfoNode.InfoType.CrossModuleAllMethods); - Header.Add(Internal.Runtime.ReadyToRunSectionType.CrossModuleInlineInfo, crossModuleInliningInfoTable, crossModuleInliningInfoTable); - this.CrossModuleInlningInfo = crossModuleInliningInfoTable; + if (!OptimizationFlags.StripInliningInfo) + { + InliningInfoNode crossModuleInliningInfoTable = new InliningInfoNode(null, + CompilationModuleGroup.IsCompositeBuildMode ? InliningInfoNode.InfoType.CrossModuleInliningForCrossModuleDataOnly : InliningInfoNode.InfoType.CrossModuleAllMethods); + Header.Add(Internal.Runtime.ReadyToRunSectionType.CrossModuleInlineInfo, crossModuleInliningInfoTable, crossModuleInliningInfoTable); + this.CrossModuleInlningInfo = crossModuleInliningInfoTable; + } InstanceEntryPointTable = new InstanceEntryPointTableNode(this); Header.Add(Internal.Runtime.ReadyToRunSectionType.InstanceMethodEntryPoints, InstanceEntryPointTable, InstanceEntryPointTable); @@ -799,8 +804,11 @@ public void AttachToDependencyGraph(DependencyAnalyzerBase graph, I ImportSectionsTable = new ImportSectionsTableNode(this); Header.Add(Internal.Runtime.ReadyToRunSectionType.ImportSections, ImportSectionsTable, ImportSectionsTable); - DebugInfoTable = new DebugInfoTableNode(); - Header.Add(Internal.Runtime.ReadyToRunSectionType.DebugInfo, DebugInfoTable, DebugInfoTable); + if (!OptimizationFlags.StripDebugInfo) + { + DebugInfoTable = new DebugInfoTableNode(); + Header.Add(Internal.Runtime.ReadyToRunSectionType.DebugInfo, DebugInfoTable, DebugInfoTable); + } EagerImports = new ImportSectionNode( "EagerImports", diff --git a/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs b/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs index c31f7175e0b7c8..ada92cd4d77f93 100644 --- a/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs +++ b/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs @@ -142,6 +142,10 @@ internal class Crossgen2RootCommand : RootCommand new("--make-repro-path") { Description = "Path where to place a repro package" }; public Option HotColdSplitting { get; } = new("--hot-cold-splitting") { Description = SR.HotColdSplittingOption }; + public Option StripInliningInfo { get; } = + new("--strip-inlining-info") { Description = SR.StripInliningInfoOption }; + public Option StripDebugInfo { get; } = + new("--strip-debug-info") { Description = SR.StripDebugInfoOption }; public Option SynthesizeRandomMibc { get; } = new("--synthesize-random-mibc"); @@ -219,6 +223,8 @@ public Crossgen2RootCommand(string[] args) : base(SR.Crossgen2BannerText) Options.Add(CallChainProfileFile); Options.Add(MakeReproPath); Options.Add(HotColdSplitting); + Options.Add(StripInliningInfo); + Options.Add(StripDebugInfo); Options.Add(SynthesizeRandomMibc); Options.Add(DeterminismStress); diff --git a/src/coreclr/tools/aot/crossgen2/Program.cs b/src/coreclr/tools/aot/crossgen2/Program.cs index 2ac14e471e8448..30ca9d3d3d0110 100644 --- a/src/coreclr/tools/aot/crossgen2/Program.cs +++ b/src/coreclr/tools/aot/crossgen2/Program.cs @@ -624,6 +624,8 @@ private void RunSingleCompilation(Dictionary inFilePaths, Instru nodeFactoryFlags.DeterminismStress = Get(_command.DeterminismStress); nodeFactoryFlags.PrintReproArgs = Get(_command.PrintReproInstructions); nodeFactoryFlags.EnableCachedInterfaceDispatchSupport = Get(_command.EnableCachedInterfaceDispatchSupport) ?? !typeSystemContext.TargetAllowsRuntimeCodeGeneration; + nodeFactoryFlags.StripInliningInfo = Get(_command.StripInliningInfo); + nodeFactoryFlags.StripDebugInfo = Get(_command.StripDebugInfo); builder .UseMapFile(Get(_command.Map)) diff --git a/src/coreclr/tools/aot/crossgen2/Properties/Resources.resx b/src/coreclr/tools/aot/crossgen2/Properties/Resources.resx index ca30cc9a5e31d0..b21edaf9f22af1 100644 --- a/src/coreclr/tools/aot/crossgen2/Properties/Resources.resx +++ b/src/coreclr/tools/aot/crossgen2/Properties/Resources.resx @@ -435,4 +435,10 @@ Error: Producing ReadyToRun output in the {0} format is only supported for Composite ReadyToRun images. + + Strip inlining info from the R2R image. + + + Strip debug info from the R2R image. + \ No newline at end of file diff --git a/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets b/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets index e20b05ee033e52..a51c1b4c5f97b1 100644 --- a/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets +++ b/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets @@ -32,6 +32,18 @@ Copyright (c) .NET Foundation. All rights reserved. false false false + + $(PublishReadyToRunCrossgen2ExtraArgs);--strip-inlining-info + $(PublishReadyToRunCrossgen2ExtraArgs);--strip-inlining-info + $(PublishReadyToRunCrossgen2ExtraArgs);--strip-inlining-info + $(PublishReadyToRunCrossgen2ExtraArgs);--strip-inlining-info + $(PublishReadyToRunCrossgen2ExtraArgs);--strip-inlining-info + + $(PublishReadyToRunCrossgen2ExtraArgs);--strip-debug-info + $(PublishReadyToRunCrossgen2ExtraArgs);--strip-debug-info + $(PublishReadyToRunCrossgen2ExtraArgs);--strip-debug-info + $(PublishReadyToRunCrossgen2ExtraArgs);--strip-debug-info + $(PublishReadyToRunCrossgen2ExtraArgs);--strip-debug-info