From 5770762bd9e0ad9eb0b3af4fe177ee6bc6be9acb Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 2 Sep 2020 09:34:13 +0200 Subject: [PATCH 1/6] [dotnet-linker] Add OptimizeGeneratedCodeSubStep to the pipeline. --- tools/dotnet-linker/SetupStep.cs | 1 + tools/dotnet-linker/dotnet-linker.csproj | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/tools/dotnet-linker/SetupStep.cs b/tools/dotnet-linker/SetupStep.cs index f12f054ffc1..1c121fe05e3 100644 --- a/tools/dotnet-linker/SetupStep.cs +++ b/tools/dotnet-linker/SetupStep.cs @@ -55,6 +55,7 @@ protected override void Process () // [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 30780ebb4ac..cd869961f63 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 From 6237834ae1b67c585048081361556e2c6872f265 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 2 Sep 2020 09:35:20 +0200 Subject: [PATCH 2/6] [dotnet-linker] Set the application's and the target's Abis from the linker configuration. The OptimizeGeneratedCodeSubStep requires this. --- tools/common/Application.cs | 1 + tools/dotnet-linker/LinkerConfiguration.cs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/tools/common/Application.cs b/tools/common/Application.cs index 29bea63e147..5984998893a 100644 --- a/tools/common/Application.cs +++ b/tools/common/Application.cs @@ -707,6 +707,7 @@ public void RunRegistrar () public IEnumerable Abis { get { return abis; } + set { abis = new List (value); } } public bool IsArchEnabled (Abi arch) diff --git a/tools/dotnet-linker/LinkerConfiguration.cs b/tools/dotnet-linker/LinkerConfiguration.cs index 1e59a0cc38e..b4131c3d643 100644 --- a/tools/dotnet-linker/LinkerConfiguration.cs +++ b/tools/dotnet-linker/LinkerConfiguration.cs @@ -208,6 +208,9 @@ public static LinkerConfiguration GetInstance (LinkContext context) Application.DeploymentTarget = DeploymentTarget; Application.SdkVersion = SdkVersion; + Target.Abis = Abis; + Application.Abis = Abis; + switch (Platform) { case ApplePlatform.iOS: case ApplePlatform.TVOS: From 2ac78d4ac2fe8c24970dba0fc061209e52c29e45 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 2 Sep 2020 09:39:54 +0200 Subject: [PATCH 3/6] [dotnet-linker] Set DerivedLinkContext's Target. The OptimizeGeneratedCodeSubStep requires this. --- tools/dotnet-linker/LinkerConfiguration.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/dotnet-linker/LinkerConfiguration.cs b/tools/dotnet-linker/LinkerConfiguration.cs index b4131c3d643..361147523e4 100644 --- a/tools/dotnet-linker/LinkerConfiguration.cs +++ b/tools/dotnet-linker/LinkerConfiguration.cs @@ -208,6 +208,7 @@ public static LinkerConfiguration GetInstance (LinkContext context) Application.DeploymentTarget = DeploymentTarget; Application.SdkVersion = SdkVersion; + DerivedLinkContext.Target = Target; Target.Abis = Abis; Application.Abis = Abis; From 3efaf27fddd5f7f8265d3754f0fa38f6a8622fdb Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 2 Sep 2020 10:47:33 +0200 Subject: [PATCH 4/6] [dotnet-linker] Implement a custom annotation storage independent of any linker code. The OptimizeGeneratedCodeSubStep requires this. --- tools/dotnet-linker/Compat.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/dotnet-linker/Compat.cs b/tools/dotnet-linker/Compat.cs index 03bada023a9..36ca00d6b55 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 @@ public static IEnumerable GetAssemblies (this LinkContext co { 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; } } } From 266aae7f97007549081789982a557f1a37dc15dc Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 2 Sep 2020 10:48:38 +0200 Subject: [PATCH 5/6] [linker] TRACE is always defined for .NET, so just use '#if false' instead. This makes the build log much less verbose by default (the tracing code will output a lot of text). --- tools/linker/CoreOptimizeGeneratedCode.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/linker/CoreOptimizeGeneratedCode.cs b/tools/linker/CoreOptimizeGeneratedCode.cs index cb2c422de38..93754c2b00e 100644 --- a/tools/linker/CoreOptimizeGeneratedCode.cs +++ b/tools/linker/CoreOptimizeGeneratedCode.cs @@ -573,7 +573,7 @@ protected void EliminateDeadCode (MethodDefinition caller) } } } -#if TRACE +#if false Console.WriteLine ($"{caller.FullName}:"); for (int i = 0; i < reachable.Length; i++) { Console.WriteLine ($"{(reachable [i] ? " " : "- ")} {instructions [i]}"); From 652ce3daca4e4cba648fe4b8e49d0a9f8fa26120 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 2 Sep 2020 11:57:01 +0200 Subject: [PATCH 6/6] [xharness] The linkall test is now green for .NET/Debug. --- tests/xharness/Harness.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/xharness/Harness.cs b/tests/xharness/Harness.cs index 84df31ff5e0..c7d2f8e5c56 100644 --- a/tests/xharness/Harness.cs +++ b/tests/xharness/Harness.cs @@ -395,7 +395,7 @@ void AutoConfigureIOS () 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 });