Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions tests/linker-ios/dont link/CanaryTest.cs
Original file line number Diff line number Diff line change
@@ -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);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This sounds like a bug in mono -> https://bugzilla.xamarin.com/show_bug.cgi?id=51626

}
}
}
1 change: 1 addition & 0 deletions tests/linker-ios/dont link/dont link.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
<Compile Include="DontLinkRegressionTests.cs" />
<Compile Include="TableViewSourceTest.cs" />
<Compile Include="CalendarTest.cs" />
<Compile Include="CanaryTest.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions tests/linker-ios/link sdk/CanaryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
11 changes: 11 additions & 0 deletions tools/linker/MonoTouch.Tuner/InlinerSubStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
}
Expand Down