Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redo IL Verification #90418

Merged
merged 1 commit into from
Aug 18, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,6 @@ public ResultChecker (BaseAssemblyResolver originalsResolver,
_linkedReaderParameters = linkedReaderParameters;
}

private static bool ShouldValidateIL (AssemblyDefinition inputAssembly)
{
if (HasAttribute (inputAssembly, nameof (SkipPeVerifyAttribute)))
return false;

var caaIsUnsafeFlag = (CustomAttributeArgument caa) =>
(caa.Type.Name == "String" && caa.Type.Namespace == "System")
&& (string) caa.Value == "/unsafe";
var customAttributeHasUnsafeFlag = (CustomAttribute ca) => ca.ConstructorArguments.Any (caaIsUnsafeFlag);
if (GetCustomAttributes (inputAssembly, nameof (SetupCompileArgumentAttribute))
.Any (customAttributeHasUnsafeFlag))
return false;

return true;
}

public virtual void Check (ILCompilerTestCaseResult testResult)
{
InitializeResolvers (testResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ public Task CanVerifyInterfacesOnTypesInAssembly ()
return RunTest (allowMissingWarnings: true);
}

[Fact]
public Task ILVerificationWorks ()
{
return RunTest (allowMissingWarnings: true);
}

[Fact]
public Task VerifyAttributesInAssemblyWorks ()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

namespace Mono.Linker.Tests.Cases.Expectations.Assertions;

/// <summary>
/// This attribute is used to disable removing il verification errors that appear in the input assembly from the output verification results.
///
/// The original motivation for this is to make it easier to write a test that mostly verifies that the test frameworks ability to check il is working
/// correctly.
/// </summary>
[AttributeUsage (AttributeTargets.Class)]
public class DisableILVerifyDiffingAttribute : BaseExpectedLinkedBehaviorAttribute
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

namespace Mono.Linker.Tests.Cases.Expectations.Assertions;

[AttributeUsage (AttributeTargets.Class, AllowMultiple = true)]
public class ExpectILFailureAttribute : BaseExpectedLinkedBehaviorAttribute
{
public ExpectILFailureAttribute (params string[] messageContains)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,14 @@

namespace Mono.Linker.Tests.Cases.Expectations.Assertions
{

public enum SkipPeVerifyForToolchian
{
Pedump
}

[AttributeUsage (AttributeTargets.Class, AllowMultiple = true)]
public class SkipPeVerifyAttribute : BaseExpectedLinkedBehaviorAttribute
public class SkipILVerifyAttribute : BaseExpectedLinkedBehaviorAttribute
{
public SkipPeVerifyAttribute ()
{
}

public SkipPeVerifyAttribute (SkipPeVerifyForToolchian toolchain)
public SkipILVerifyAttribute ()
{
}

public SkipPeVerifyAttribute (string assemblyName)
public SkipILVerifyAttribute (string assemblyName)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers
[SetupLinkerKeepDebugMembers ("true")]
#endif

// Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168
[SkipPeVerify (SkipPeVerifyForToolchian.Pedump)]

[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerDisplayAttribute), ".ctor(System.String)")]
[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerDisplayAttribute), "set_Target(System.Type)")]
public class DebuggerDisplayAttributeOnAssemblyUsingTarget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers
{
[SetupLinkerTrimMode ("link")]

// Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168
[SkipPeVerify (SkipPeVerifyForToolchian.Pedump)]

[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerDisplayAttribute), ".ctor(System.String)")]
public class DebuggerDisplayAttributeOnAssemblyUsingTargetOnUnusedType
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers
[SetupLinkerTrimMode ("link")]
[SetupCompileBefore ("library.dll", new[] { "../Dependencies/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib.cs" })]

// Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168
[SkipPeVerify (SkipPeVerifyForToolchian.Pedump)]

[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerDisplayAttribute), ".ctor(System.String)")]
[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerDisplayAttribute), "set_TargetTypeName(System.String)")]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers
[SetupLinkerKeepDebugMembers ("true")]
#endif

// Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168
[SkipPeVerify (SkipPeVerifyForToolchian.Pedump)]

[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerDisplayAttribute), ".ctor(System.String)")]
[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerDisplayAttribute), "set_TargetTypeName(System.String)")]
public class DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInSameAssembly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers
#endif
[SetupCompileBefore ("library.dll", new[] { "../Dependencies/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib.cs" })]

// Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168
[SkipPeVerify (SkipPeVerifyForToolchian.Pedump)]

[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerDisplayAttribute), ".ctor(System.String)")]
[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerDisplayAttribute), "set_TargetTypeName(System.String)")]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers
[SetupLinkerTrimMode ("link")]
[SetupCompileBefore ("library.dll", new[] { "../Dependencies/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib.cs" })]

// Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168
[SkipPeVerify (SkipPeVerifyForToolchian.Pedump)]

[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerDisplayAttribute), ".ctor(System.String)")]
[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerDisplayAttribute), "set_TargetTypeName(System.String)")]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers
{
// Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168
[SkipPeVerify (SkipPeVerifyForToolchian.Pedump)]
public class DebuggerDisplayAttributeOnGenerics
{
public static void Main ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers
{
[SetupLinkerTrimMode ("link")]
// Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168
[SkipPeVerify (SkipPeVerifyForToolchian.Pedump)]

[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerDisplayAttribute), ".ctor(System.String)")]
public class DebuggerDisplayAttributeOnType
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers
[SetupLinkerKeepDebugMembers ("true")]
#endif

// Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168
[SkipPeVerify (SkipPeVerifyForToolchian.Pedump)]
public class DebuggerDisplayAttributeOnTypeThatIsNotUsed
{
public static void Main ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers
{
[SetupLinkerTrimMode ("link")]

// Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168
[SkipPeVerify (SkipPeVerifyForToolchian.Pedump)]

[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerTypeProxyAttribute), ".ctor(System.Type)")]
[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerTypeProxyAttribute), "set_Target(System.Type)")]
public class DebuggerTypeProxyAttributeOnAssemblyUsingTarget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers
{
[SetupLinkerTrimMode ("link")]
// Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168
[SkipPeVerify (SkipPeVerifyForToolchian.Pedump)]

[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerTypeProxyAttribute), ".ctor(System.Type)")]
public class DebuggerTypeProxyAttributeOnType
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace Mono.Linker.Tests.Cases.Attributes
{
[SkipPeVerify]
[Define ("REFERENCE_INCLUDED")]
[SetupCompileBefore ("library.dll", new[] { "Dependencies/AttributeDefinedInReference.cs" })]
[SetupLinkerAction ("skip", "library")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ namespace Mono.Linker.Tests.Cases.Attributes
[KeptAttributeInAssembly ("System.dll", typeof (AssemblyDescriptionAttribute))]
[KeptAttributeInAssembly ("System.dll", typeof (AssemblyCompanyAttribute))]
#endif
[SkipPeVerify]
public class CoreLibraryAssemblyAttributesAreKept
{
public static void Main ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace Mono.Linker.Tests.Cases.Attributes
/// The purpose of this test is mainly to provide coverage on the `KeptAttributeOnFixedBufferType` attribute
/// </summary>
[SetupCompileArgument ("/unsafe")]
// Can't verify because the test contains unsafe code
[SkipPeVerify]
public class FixedLengthArrayAttributesArePreserved
{
public static void Main ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
namespace Mono.Linker.Tests.Cases.Attributes
{
[SetupLinkerTrimMode ("link")]
[SkipPeVerify]

[KeptInterface (typeof (IUserData))]
public class MarshalAsCustomMarshalerInterface : IUserData
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ namespace Mono.Linker.Tests.Cases.Attributes.NoSecurity
[RemovedTypeInAssembly (PlatformAssemblies.CoreLib, typeof (SecurityCriticalAttribute))]
[RemovedTypeInAssembly (PlatformAssemblies.CoreLib, typeof (SecuritySafeCriticalAttribute))]
[RemovedTypeInAssembly (PlatformAssemblies.CoreLib, typeof (SuppressUnmanagedCodeSecurityAttribute))]

// Fails with `Runtime critical type System.Reflection.CustomAttributeData not found` which is a known short coming
[SkipPeVerify (SkipPeVerifyForToolchian.Pedump)]
[SkipPeVerify ("System.dll")]

// System.Core.dll is referenced by System.dll in the .NET FW class libraries. Our GetType reflection marking code
// detects a GetType("SHA256CryptoServiceProvider") in System.dll, which then causes a type in System.Core.dll to be marked.
// PeVerify fails on the original GAC copy of System.Core.dll so it's expected that it will also fail on the stripped version we output
[SkipPeVerify ("System.Core.dll")]
public class CoreLibrarySecurityAttributeTypesAreRemoved
{
public static void Main ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@ namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed
[SetupLinkerTrimMode ("link")]
[SetupLinkerArgument ("--used-attrs-only", "true")]
[Reference ("System.dll")]
// System.Core.dll is referenced by System.dll in the .NET FW class libraries. Our GetType reflection marking code
// detects a GetType("SHA256CryptoServiceProvider") in System.dll, which then causes a type in System.Core.dll to be marked.
// PeVerify fails on the original GAC copy of System.Core.dll so it's expected that it will also fail on the stripped version we output
[SkipPeVerify ("System.Core.dll")]
// Fails with `Runtime critical type System.Reflection.CustomAttributeData not found`
[SkipPeVerify (SkipPeVerifyForToolchian.Pedump)]
#if !NETCOREAPP
// .NET Framework System.dll doesn't pass peverify
[SkipPeVerify ("System.dll")]
#endif

class CanLinkCoreLibrariesWithOnlyKeepUsedAttributes
{
static void Main ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed
#if !NETCOREAPP
[RemovedAttributeInAssembly ("System.dll", typeof (AssemblyDescriptionAttribute))]
#endif
[SkipPeVerify]
public class CoreLibraryUnusedAssemblyAttributesAreRemoved
{
public static void Main ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed
#if !NETCOREAPP
[KeptAttributeInAssembly ("System.dll", typeof (AssemblyDescriptionAttribute))]
#endif
[SkipPeVerify]
public class CoreLibraryUsedAssemblyAttributesAreKept
{
public static void Main ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed
{
[SetupLinkerArgument ("--used-attrs-only", "true")]
[SetupCompileArgument ("/unsafe")]

// Can't verify because the test contains unsafe code
[SkipPeVerify]
public class FixedLengthArrayAttributesArePreserved
{
public static void Main ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed
[SetupCSharpCompilerToUse ("csc")]
[SetupLinkerArgument ("--used-attrs-only", "true")]
[SetupLinkerTrimMode ("link")]
[IgnoreDescriptors (false)]
public class NullableOnConstraints
{
public static void Main ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed
{
[SetupLinkerArgument ("--used-attrs-only", "true")]
// System.Core.dll is referenced by System.dll in the .NET FW class libraries. Our GetType reflection marking code
// detects a GetType("SHA256CryptoServiceProvider") in System.dll, which then causes a type in System.Core.dll to be marked.
// PeVerify fails on the original GAC copy of System.Core.dll so it's expected that it will also fail on the stripped version we output
[SkipPeVerify ("System.Core.dll")]
class UnusedAttributeTypeOnMethodIsRemoved
{
static void Main ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ namespace Mono.Linker.Tests.Cases.CoreLink

[KeptAssembly (PlatformAssemblies.CoreLib)]
[KeptAllTypesAndMembersInAssembly (PlatformAssemblies.CoreLib)]

[SkipPeVerify]
class CopyOfCoreLibrariesKeepsUnusedTypes
{
public static void Main ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Mono.Linker.Tests.Cases.CoreLink
{
[TestCaseRequirements (TestRunCharacteristics.TargetingNetCore, "Only for .NET Core")]
/// <summary>
/// Delegate and is created from
/// Delegate and is created from
/// </summary>
[SetupLinkerTrimMode ("link")]
[KeptBaseOnTypeInAssembly (PlatformAssemblies.CoreLib, typeof (MulticastDelegate), PlatformAssemblies.CoreLib, typeof (Delegate))]
Expand All @@ -22,9 +22,6 @@ namespace Mono.Linker.Tests.Cases.CoreLink
[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (Delegate), "Equals(System.Object)")]
[KeptInterfaceOnTypeInAssembly (PlatformAssemblies.CoreLib, typeof (Delegate), PlatformAssemblies.CoreLib, typeof (ICloneable))]
[KeptInterfaceOnTypeInAssembly (PlatformAssemblies.CoreLib, typeof (Delegate), PlatformAssemblies.CoreLib, typeof (ISerializable))]

// Fails due to Runtime critical type System.Reflection.CustomAttributeData not found.
[SkipPeVerify (SkipPeVerifyForToolchian.Pedump)]
public class DelegateAndMulticastDelegateKeepInstantiatedReqs
{
public static void Main ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
namespace Mono.Linker.Tests.Cases.CoreLink
{
[SetupLinkerTrimMode ("link")]
// Need to skip due to `Runtime critical type System.Reflection.CustomAttributeData not found` failure
[SkipPeVerify (SkipPeVerifyForToolchian.Pedump)]
public class InstantiatedStructWithOverridesFromObject
{
public static void Main ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
namespace Mono.Linker.Tests.Cases.CoreLink
{
[SetupLinkerTrimMode ("link")]
// Need to skip due to `Runtime critical type System.Reflection.CustomAttributeData not found` failure
[SkipPeVerify (SkipPeVerifyForToolchian.Pedump)]
public class InstantiatedTypeWithOverridesFromObject
{
public static void Main ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ namespace Mono.Linker.Tests.Cases.CoreLink
// we known should be removed which will at least verify that the core library was processed
[RemovedMemberInAssembly (PlatformAssemblies.CoreLib, typeof (Stack), ".ctor(System.Collections.ICollection)")]

// Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168
[SkipPeVerify (SkipPeVerifyForToolchian.Pedump)]
class LinkingOfCoreLibrariesRemovesUnusedMethods
{
public static void Main ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,6 @@ namespace Mono.Linker.Tests.Cases.CoreLink
[KeptAssembly ("System.dll")]
[KeptTypeInAssembly ("System.dll", typeof (System.Collections.Generic.SortedList<,>))]
[RemovedTypeInAssembly ("System.dll", typeof (System.Collections.Generic.SortedDictionary<,>))]

// Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168
[SkipPeVerify (SkipPeVerifyForToolchian.Pedump)]

// All sorts of stuff is flagged as invalid even in the original System.dll and System.Configuration.dll for mono class libraries
[SkipPeVerify ("System.dll")]
[SkipPeVerify ("System.Configuration.dll")]
// System.Core.dll is referenced by System.dll in the .NET FW class libraries. Our GetType reflection marking code
// detects a GetType("SHA256CryptoServiceProvider") in System.dll, which then causes a type in System.Core.dll to be marked.
// PeVerify fails on the original GAC copy of System.Core.dll so it's expected that it will also fail on the stripped version we output
[SkipPeVerify ("System.Core.dll")]
class LinkingOfCoreLibrariesRemovesUnusedTypes
{
public static void Main ()
Expand Down
Loading