Skip to content

Commit 6229f5f

Browse files
authored
Redo ILVerfificaiton (#90418)
* Now checks all assemblies in the output directory rather than just `test.exe` * Once again respects the the ability to skip verifying a single assembly via `[SkipIlVerify("foo.dll")]` * Now loads core libraries from the output directory (if they exist) instead of from the runtime install dir. * ALC logic was removed. I do not understand what value this provided. * The class libraries lead to a lot of errors. Rather than having to filter out a large number of errors, I added diff'ing. ILVerify will check the input assembly and remove any errors that existed in the input assembly. This makes verifying class libraries viable. Without it, you'd have to use `[SkipIlverify]` on every core link test or filter out a lot of `VerifierError` values. * Moved IL verification back to `InitialChecking` where `PeVerifier` was * Add a test to verify that il verification is mostly working. It doesn't give complete coverage over every behavior, but it's better than nothing. * `SkipPeVerify` renamed to `SkipIlVerify` * `SkipPeVerifyForToolchian` was removed. There is only 1 tool now. * Removed `PeVerifier`. * Remove many [SkipIlVerify] attributes. Diffing means they are no longer needed * `ValidateTypeRefsHaveValidAssemblyRefs` now runs regardless of whether or not the IL is verified. It wasn't clear to me why this logic would only be useful when il was verified. * Change `UninitializedLocals` to use `ExpectIlFailure`. This test seems to expect invalid il. Might as well assert that rather than skip ilverify entirely. * Remove the logic that disables ilverify when a test uses the unsafe argument. Diffing makes this obsolete. * IL Verification errors have been greatly improved. ** will now output all IL errors in the failure message rather than just the first invalid IL. ** Type and Method names are now displayed in the error message. I didn't do an exhaustive implementation, SRM is so tedious to use, but it's better than not having it ** Tokens and Offsets are formatted nicely * Extension points opened up for Unity. ** We need to supply different search directories. ** We need to search for `.winmd` files since we support windows runtime. ** In general I opened some things up in case we need to call them
1 parent 5ef2a9b commit 6229f5f

File tree

60 files changed

+653
-314
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+653
-314
lines changed

src/coreclr/tools/aot/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,6 @@ public ResultChecker (BaseAssemblyResolver originalsResolver,
4545
_linkedReaderParameters = linkedReaderParameters;
4646
}
4747

48-
private static bool ShouldValidateIL (AssemblyDefinition inputAssembly)
49-
{
50-
if (HasAttribute (inputAssembly, nameof (SkipPeVerifyAttribute)))
51-
return false;
52-
53-
var caaIsUnsafeFlag = (CustomAttributeArgument caa) =>
54-
(caa.Type.Name == "String" && caa.Type.Namespace == "System")
55-
&& (string) caa.Value == "/unsafe";
56-
var customAttributeHasUnsafeFlag = (CustomAttribute ca) => ca.ConstructorArguments.Any (caaIsUnsafeFlag);
57-
if (GetCustomAttributes (inputAssembly, nameof (SetupCompileArgumentAttribute))
58-
.Any (customAttributeHasUnsafeFlag))
59-
return false;
60-
61-
return true;
62-
}
63-
6448
public virtual void Check (ILCompilerTestCaseResult testResult)
6549
{
6650
InitializeResolvers (testResult);

src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/TestFrameworkTests.g.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ public Task CanVerifyInterfacesOnTypesInAssembly ()
7575
return RunTest (allowMissingWarnings: true);
7676
}
7777

78+
[Fact]
79+
public Task ILVerificationWorks ()
80+
{
81+
return RunTest (allowMissingWarnings: true);
82+
}
83+
7884
[Fact]
7985
public Task VerifyAttributesInAssemblyWorks ()
8086
{
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
6+
namespace Mono.Linker.Tests.Cases.Expectations.Assertions;
7+
8+
/// <summary>
9+
/// This attribute is used to disable removing il verification errors that appear in the input assembly from the output verification results.
10+
///
11+
/// 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
12+
/// correctly.
13+
/// </summary>
14+
[AttributeUsage (AttributeTargets.Class)]
15+
public class DisableILVerifyDiffingAttribute : BaseExpectedLinkedBehaviorAttribute
16+
{
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
6+
namespace Mono.Linker.Tests.Cases.Expectations.Assertions;
7+
8+
[AttributeUsage (AttributeTargets.Class, AllowMultiple = true)]
9+
public class ExpectILFailureAttribute : BaseExpectedLinkedBehaviorAttribute
10+
{
11+
public ExpectILFailureAttribute (params string[] messageContains)
12+
{
13+
}
14+
}
Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,14 @@
55

66
namespace Mono.Linker.Tests.Cases.Expectations.Assertions
77
{
8-
9-
public enum SkipPeVerifyForToolchian
10-
{
11-
Pedump
12-
}
13-
148
[AttributeUsage (AttributeTargets.Class, AllowMultiple = true)]
15-
public class SkipPeVerifyAttribute : BaseExpectedLinkedBehaviorAttribute
9+
public class SkipILVerifyAttribute : BaseExpectedLinkedBehaviorAttribute
1610
{
17-
public SkipPeVerifyAttribute ()
18-
{
19-
}
20-
21-
public SkipPeVerifyAttribute (SkipPeVerifyForToolchian toolchain)
11+
public SkipILVerifyAttribute ()
2212
{
2313
}
2414

25-
public SkipPeVerifyAttribute (string assemblyName)
15+
public SkipILVerifyAttribute (string assemblyName)
2616
{
2717
}
2818
}

src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnAssemblyUsingTarget.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers
1414
[SetupLinkerKeepDebugMembers ("true")]
1515
#endif
1616

17-
// Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168
18-
[SkipPeVerify (SkipPeVerifyForToolchian.Pedump)]
19-
2017
[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerDisplayAttribute), ".ctor(System.String)")]
2118
[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerDisplayAttribute), "set_Target(System.Type)")]
2219
public class DebuggerDisplayAttributeOnAssemblyUsingTarget

src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnAssemblyUsingTargetOnUnusedType.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers
1010
{
1111
[SetupLinkerTrimMode ("link")]
12-
13-
// Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168
14-
[SkipPeVerify (SkipPeVerifyForToolchian.Pedump)]
15-
1612
[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerDisplayAttribute), ".ctor(System.String)")]
1713
public class DebuggerDisplayAttributeOnAssemblyUsingTargetOnUnusedType
1814
{

src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers
1313
[SetupLinkerTrimMode ("link")]
1414
[SetupCompileBefore ("library.dll", new[] { "../Dependencies/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib.cs" })]
1515

16-
// Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168
17-
[SkipPeVerify (SkipPeVerifyForToolchian.Pedump)]
18-
1916
[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerDisplayAttribute), ".ctor(System.String)")]
2017
[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerDisplayAttribute), "set_TargetTypeName(System.String)")]
2118

src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInSameAssembly.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers
1313
[SetupLinkerKeepDebugMembers ("true")]
1414
#endif
1515

16-
// Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168
17-
[SkipPeVerify (SkipPeVerifyForToolchian.Pedump)]
18-
1916
[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerDisplayAttribute), ".ctor(System.String)")]
2017
[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerDisplayAttribute), "set_TargetTypeName(System.String)")]
2118
public class DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInSameAssembly

src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameOfGenericTypeInOtherAssembly.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers
1515
#endif
1616
[SetupCompileBefore ("library.dll", new[] { "../Dependencies/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib.cs" })]
1717

18-
// Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168
19-
[SkipPeVerify (SkipPeVerifyForToolchian.Pedump)]
20-
2118
[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerDisplayAttribute), ".ctor(System.String)")]
2219
[KeptMemberInAssembly (PlatformAssemblies.CoreLib, typeof (DebuggerDisplayAttribute), "set_TargetTypeName(System.String)")]
2320

0 commit comments

Comments
 (0)