From eb5206f082bfa872bd6bdf82e6c21bb4c5b61157 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 10 Sep 2020 08:30:45 +0200 Subject: [PATCH] [dotnet-linker] Add OptimizeGeneratedCodeSubStep into the pipeline. (#9608) Fixes these linkall tests: Linker.Shared.OptimizeGeneratedCodeTest [FAIL] IsARM64CallingConvention : optimized: no ldsfld instruction Expected: 0 But was: 1 at Linker.Shared.BaseOptimizeGeneratedCodeTest.IsARM64CallingConvention() in /Users/rolf/work/maccore/main/xamarin-macios/tests/linker/BaseOptimizeGeneratedCodeTest.cs:line 527 [FAIL] SetupBlockPerfTest : At least 6x speedup Expected: greater than 6 But was: 1.0876440665344851d at Linker.Shared.BaseOptimizeGeneratedCodeTest.SetupBlockPerfTest() in /Users/rolf/work/maccore/main/xamarin-macios/tests/linker/BaseOptimizeGeneratedCodeTest.cs:line 120 And linkall is now green for .NET/Debug. --- tests/xharness/Harness.cs | 2 +- tools/common/Application.cs | 1 + tools/dotnet-linker/Compat.cs | 8 +++++++- tools/dotnet-linker/LinkerConfiguration.cs | 4 ++++ tools/dotnet-linker/SetupStep.cs | 1 + tools/dotnet-linker/dotnet-linker.csproj | 9 +++++++++ tools/linker/CoreOptimizeGeneratedCode.cs | 2 +- 7 files changed, 24 insertions(+), 3 deletions(-) diff --git a/tests/xharness/Harness.cs b/tests/xharness/Harness.cs index 84df31ff5e..c7d2f8e5c5 100644 --- a/tests/xharness/Harness.cs +++ b/tests/xharness/Harness.cs @@ -395,7 +395,7 @@ namespace Xharness { IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "dont link", "dont link.csproj"))) { Configurations = new string [] { "Debug", "Release" } }); IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "dont link", "dotnet", "iOS", "dont link.csproj"))) { Configurations = new string [] { "Debug", "Release" }, IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = true, SkipiOS32Variation = true }); IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link all", "link all.csproj"))) { Configurations = new string [] { "Debug", "Release" } }); - IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link all", "dotnet", "iOS", "link all.csproj"))) { Configurations = new string [] { "Debug", "Release" }, IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = true, SkipiOS32Variation = true, Ignore = true }); + IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link all", "dotnet", "iOS", "link all.csproj"))) { Configurations = new string [] { "Debug" /*, "Release" */ }, IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = true, SkipiOS32Variation = true }); IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link sdk", "link sdk.csproj"))) { Configurations = new string [] { "Debug", "Release" } }); IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link sdk", "dotnet", "iOS", "link sdk.csproj"))) { Configurations = new string [] { "Debug" /*, "Release" */ }, IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = true, SkipiOS32Variation = true }); diff --git a/tools/common/Application.cs b/tools/common/Application.cs index 29bea63e14..5984998893 100644 --- a/tools/common/Application.cs +++ b/tools/common/Application.cs @@ -707,6 +707,7 @@ namespace Xamarin.Bundler { public IEnumerable Abis { get { return abis; } + set { abis = new List (value); } } public bool IsArchEnabled (Abi arch) diff --git a/tools/dotnet-linker/Compat.cs b/tools/dotnet-linker/Compat.cs index 03bada023a..36ca00d6b5 100644 --- a/tools/dotnet-linker/Compat.cs +++ b/tools/dotnet-linker/Compat.cs @@ -1,6 +1,7 @@ // Compat.cs: might not be ideal but it eases code sharing with existing code during the initial implementation. using System; using System.Collections.Generic; +using System.Runtime.CompilerServices; using Mono.Cecil; using Mono.Linker; @@ -160,9 +161,14 @@ namespace Mono.Linker { { return LinkerConfiguration.GetInstance (context).Assemblies; } + + static ConditionalWeakTable>> custom_annotations = new ConditionalWeakTable>> (); public static Dictionary GetCustomAnnotations (this AnnotationStore self, string name) { - throw new NotImplementedException (); + var store = custom_annotations.GetOrCreateValue (self); + if (!store.TryGetValue (name, out var dict)) + store [name] = dict = new Dictionary (); + return dict; } } } diff --git a/tools/dotnet-linker/LinkerConfiguration.cs b/tools/dotnet-linker/LinkerConfiguration.cs index 1e59a0cc38..361147523e 100644 --- a/tools/dotnet-linker/LinkerConfiguration.cs +++ b/tools/dotnet-linker/LinkerConfiguration.cs @@ -208,6 +208,10 @@ namespace Xamarin.Linker { Application.DeploymentTarget = DeploymentTarget; Application.SdkVersion = SdkVersion; + DerivedLinkContext.Target = Target; + Target.Abis = Abis; + Application.Abis = Abis; + switch (Platform) { case ApplePlatform.iOS: case ApplePlatform.TVOS: diff --git a/tools/dotnet-linker/SetupStep.cs b/tools/dotnet-linker/SetupStep.cs index f12f054ffc..1c121fe05e 100644 --- a/tools/dotnet-linker/SetupStep.cs +++ b/tools/dotnet-linker/SetupStep.cs @@ -55,6 +55,7 @@ namespace Xamarin { // [assembly: LinkSafe] attributes, which means we treat them as sdk assemblies and those may have // Preserve attributes. prelink_substeps.Add (new ApplyPreserveAttribute ()); + prelink_substeps.Add (new OptimizeGeneratedCodeSubStep ()); prelink_substeps.Add (new MarkNSObjects ()); prelink_substeps.Add (new PreserveSmartEnumConversionsSubStep ()); } diff --git a/tools/dotnet-linker/dotnet-linker.csproj b/tools/dotnet-linker/dotnet-linker.csproj index 30780ebb4a..cd869961f6 100644 --- a/tools/dotnet-linker/dotnet-linker.csproj +++ b/tools/dotnet-linker/dotnet-linker.csproj @@ -101,6 +101,9 @@ external\tools\linker\CustomSymbolWriter.cs + + external\tools\linker\CoreOptimizeGeneratedCode.cs + external\src\ObjCRuntime\Registrar.cs @@ -164,6 +167,12 @@ external\mono-archive\Linker\I18nAssemblies.cs + + mono-archive\Linker\MethodDefinitionExtensions.cs + + + mono-archive\Linker\Linker\TypeReferenceExtensions.cs + external\mono-archive\Mono.Tuner\CecilRocks.cs diff --git a/tools/linker/CoreOptimizeGeneratedCode.cs b/tools/linker/CoreOptimizeGeneratedCode.cs index cb2c422de3..93754c2b00 100644 --- a/tools/linker/CoreOptimizeGeneratedCode.cs +++ b/tools/linker/CoreOptimizeGeneratedCode.cs @@ -573,7 +573,7 @@ namespace Xamarin.Linker { } } } -#if TRACE +#if false Console.WriteLine ($"{caller.FullName}:"); for (int i = 0; i < reachable.Length; i++) { Console.WriteLine ($"{(reachable [i] ? " " : "- ")} {instructions [i]}");