diff --git a/tests/linker-ios/dont link/CanaryTest.cs b/tests/linker-ios/dont link/CanaryTest.cs new file mode 100644 index 000000000000..d66b5cee8e69 --- /dev/null +++ b/tests/linker-ios/dont link/CanaryTest.cs @@ -0,0 +1,33 @@ +using System; +using System.Reflection; +using NUnit.Framework; + +namespace DontLink { + + [TestFixture] + public class CanaryTest { + + static void AssertCallStaticReturnBool (Type t, string method, bool expected) + { + AssertCallStaticReturnBool (t, method, null, expected); + } + + static void AssertCallStaticReturnBool (Type t, string method, object [] parameters, bool expected) + { + var m = t.GetMethod (method, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); + Assert.NotNull (m, $"{t.Name}::{method} is missing"); + var result = (bool)m.Invoke (null, parameters); + Assert.That (result, Is.EqualTo (expected), $"{t.Name}::{method} returned `{result}` not the expected `{expected}`"); + } + + [Test] + public void Mscorlib () + { + // type is internal - but we need to ensure it does not change the value it returns (without a corresponding update to InlinerSubStep.cs) + var bc = Type.GetType ("System.Runtime.Versioning.BinaryCompatibility, mscorlib"); + Assert.IsNotNull (bc, "BinaryCompatibility"); + AssertCallStaticReturnBool (bc, "get_TargetsAtLeast_Desktop_V4_5", true); + AssertCallStaticReturnBool (bc, "get_TargetsAtLeast_Desktop_V4_5_1", false); + } + } +} diff --git a/tests/linker-ios/dont link/dont link.csproj b/tests/linker-ios/dont link/dont link.csproj index 6b30d76bd7da..5b5abaeed9e9 100644 --- a/tests/linker-ios/dont link/dont link.csproj +++ b/tests/linker-ios/dont link/dont link.csproj @@ -150,6 +150,7 @@ + diff --git a/tests/linker-ios/link sdk/CanaryTest.cs b/tests/linker-ios/link sdk/CanaryTest.cs index ecf00f336dd7..56121cf34c64 100644 --- a/tests/linker-ios/link sdk/CanaryTest.cs +++ b/tests/linker-ios/link sdk/CanaryTest.cs @@ -29,6 +29,7 @@ public void Mscorlib () { // Not critical (on failure) but not optimal - the linker should be able to remove those types entirely AssertAbsentType ("System.Security.SecurityManager, mscorlib"); + AssertAbsentType ("System.Runtime.Versioning.BinaryCompatibility, mscorlib"); } } } diff --git a/tools/linker/MonoTouch.Tuner/InlinerSubStep.cs b/tools/linker/MonoTouch.Tuner/InlinerSubStep.cs index 128b831d27b5..f6a76a04f369 100644 --- a/tools/linker/MonoTouch.Tuner/InlinerSubStep.cs +++ b/tools/linker/MonoTouch.Tuner/InlinerSubStep.cs @@ -53,6 +53,17 @@ protected override void Process (MethodDefinition method) break; } } + // this removes System.Runtime.Versioning's BinaryCompatibility / BinaryCompatibilityMap / CompatibilitySwitch / TargetFrameworkId + if (!mr.HasParameters && mr.DeclaringType.Is ("System.Runtime.Versioning", "BinaryCompatibility")) { + switch (mr.Name) { + case "get_TargetsAtLeast_Desktop_V4_5": + il.OpCode = OpCodes.Ldc_I4_1; + break; + case "get_TargetsAtLeast_Desktop_V4_5_1": + il.OpCode = OpCodes.Ldc_I4_0; + break; + } + } } } }