From ceb41a0105889143e044258d82f173fa989f0dd8 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Mon, 12 Jun 2023 17:36:57 +0000 Subject: [PATCH 1/5] Check exit code in illink test infra --- .../TestCasesRunner/LinkedTestCaseResult.cs | 14 +++++++++++++- .../TestCasesRunner/LinkerDriver.cs | 4 ++-- .../TestCasesRunner/ResultChecker.cs | 1 + .../TestCasesRunner/TestRunner.cs | 16 +++++++++++++--- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/LinkedTestCaseResult.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/LinkedTestCaseResult.cs index b1da7c0970ded8..f0e856dfbb37cb 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/LinkedTestCaseResult.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/LinkedTestCaseResult.cs @@ -17,8 +17,19 @@ public class LinkedTestCaseResult public readonly ManagedCompilationResult CompilationResult; public readonly LinkerTestLogger Logger; public readonly LinkerCustomizations Customizations; + public readonly int ExitCode; - public LinkedTestCaseResult (TestCase testCase, NPath inputAssemblyPath, NPath outputAssemblyPath, NPath expectationsAssemblyPath, TestCaseSandbox sandbox, TestCaseMetadataProvider metadataProvider, ManagedCompilationResult compilationResult, LinkerTestLogger logger, LinkerCustomizations customizations) + public LinkedTestCaseResult ( + TestCase testCase, + NPath inputAssemblyPath, + NPath outputAssemblyPath, + NPath expectationsAssemblyPath, + TestCaseSandbox sandbox, + TestCaseMetadataProvider metadataProvider, + ManagedCompilationResult compilationResult, + LinkerTestLogger logger, + LinkerCustomizations customizations, + int exitCode) { TestCase = testCase; InputAssemblyPath = inputAssemblyPath; @@ -29,6 +40,7 @@ public LinkedTestCaseResult (TestCase testCase, NPath inputAssemblyPath, NPath o CompilationResult = compilationResult; Logger = logger; Customizations = customizations; + ExitCode = exitCode; } } } \ No newline at end of file diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/LinkerDriver.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/LinkerDriver.cs index 963c6a47956051..c47c5e8a062bf9 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/LinkerDriver.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/LinkerDriver.cs @@ -24,11 +24,11 @@ protected override LinkContext GetDefaultContext (Pipeline pipeline, ILogger log } } - public virtual void Link (string[] args, LinkerCustomizations customizations, ILogger logger) + public virtual int Link (string[] args, LinkerCustomizations customizations, ILogger logger) { Driver.ProcessResponseFile (args, out var queue); using (var driver = new TestDriver (queue, customizations)) { - driver.Run (logger); + return driver.Run (logger); } } } diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs index 816bff646401c4..5d2374ccaec372 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs @@ -77,6 +77,7 @@ static bool ShouldValidateIL (AssemblyDefinition inputAssembly) public virtual void Check (LinkedTestCaseResult linkResult) { + Assert.AreEqual (0, linkResult.ExitCode, $"ILLink returned non-zero exit code: '{linkResult.ExitCode}'"); InitializeResolvers (linkResult); try { diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs index 7d50e5ee2a1159..b4b58fd305b81a 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs @@ -109,9 +109,19 @@ private LinkedTestCaseResult Link (TestCase testCase, TestCaseSandbox sandbox, M AddLinkOptions (sandbox, compilationResult, builder, metadataProvider); LinkerTestLogger logger = new LinkerTestLogger (); - linker.Link (builder.ToArgs (), linkerCustomizations, logger); - - return new LinkedTestCaseResult (testCase, compilationResult.InputAssemblyPath, sandbox.OutputDirectory.Combine (compilationResult.InputAssemblyPath.FileName), compilationResult.ExpectationsAssemblyPath, sandbox, metadataProvider, compilationResult, logger, linkerCustomizations); + int exitCode = linker.Link (builder.ToArgs (), linkerCustomizations, logger); + + return new LinkedTestCaseResult ( + testCase, + compilationResult.InputAssemblyPath, + sandbox.OutputDirectory.Combine (compilationResult.InputAssemblyPath.FileName), + compilationResult.ExpectationsAssemblyPath, + sandbox, + metadataProvider, + compilationResult, + logger, + linkerCustomizations, + exitCode); } protected virtual void AddLinkOptions (TestCaseSandbox sandbox, ManagedCompilationResult compilationResult, LinkerArgumentBuilder builder, TestCaseMetadataProvider metadataProvider) From 73bc051ac5cae7036788c537de1fad4722c8d79a Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Wed, 14 Jun 2023 18:49:43 +0000 Subject: [PATCH 2/5] Correct typerefs referenced from debug info When linking `save` assemblis with `-b true` (linking debug info), we preserve all debug info (and don't sweep the debug info like we do for `link` assemblies). With this change, we now take into account type references that are only referenced by the debug info, preserving any assembly refs needed by them. This adds test infra to walk the type references in the output assembly, and check that they reference assembly refs that also exist in the output. Includes some test infra changes that were ultimately not necessary for the repro, but were useful, to allow passing multiple additional compiler args when compiling testcase dependencies. --- .../src/linker/Linker.Steps/MarkStep.cs | 2 +- .../src/linker/Linker.Steps/SweepStep.cs | 52 ++++++++--------- .../src/linker/Linker/TypeReferenceWalker.cs | 21 ++++++- .../Metadata/SetupCompileBeforeAttribute.cs | 2 +- .../Mono.Linker.Tests.Cases.csproj | 1 + .../AssemblyOnlyUsedByUsingSaveAction.cs | 42 ++++++++++++++ ...blyOnlyUsedByUsingSaveActionWithSymbols.cs | 45 +++++++++++++++ .../AssemblyOnlyUsedByUsingWithCsc.cs | 14 ++--- ...=> AssemblyOnlyUsedByUsing_UnusedUsing.cs} | 5 +- .../CustomMarkHandlerSaveAssembly.cs | 15 +++++ .../Symbols/ReferenceWithEmbeddedPdb.cs | 2 +- ...eWithEmbeddedPdbAndSymbolLinkingEnabled.cs | 2 +- ...ymbolLinkingEnabledAndDeterministicMvid.cs | 2 +- ...dedPdbAndSymbolLinkingEnabledAndNewMvid.cs | 2 +- .../ReferenceWithEmbeddedPdbCopyAction.cs | 2 +- ...dedPdbCopyActionAndSymbolLinkingEnabled.cs | 2 +- .../ReferenceWithEmbeddedPdbDeleteAction.cs | 2 +- ...dPdbDeleteActionAndSymbolLinkingEnabled.cs | 2 +- .../Symbols/ReferenceWithPortablePdb.cs | 2 +- ...eWithPortablePdbAndSymbolLinkingEnabled.cs | 2 +- ...ymbolLinkingEnabledAndDeterministicMvid.cs | 2 +- ...blePdbAndSymbolLinkingEnabledAndNewMvid.cs | 2 +- .../ReferenceWithPortablePdbCopyAction.cs | 2 +- ...blePdbCopyActionAndSymbolLinkingEnabled.cs | 2 +- .../ReferenceWithPortablePdbDeleteAction.cs | 2 +- ...ePdbDeleteActionAndSymbolLinkingEnabled.cs | 2 +- .../Symbols/ReferencesWithMixedSymbolTypes.cs | 6 +- ...MixedSymbolTypesAndSymbolLinkingEnabled.cs | 6 +- ...mbolTypesWithMdbAndSymbolLinkingEnabled.cs | 6 +- .../WorksWithDynamicAssembly.cs | 2 +- .../TestCasesRunner/ILVerifier.cs | 7 +-- .../TestCasesRunner/ResultChecker.cs | 56 +++++++++++++++++-- .../TestCasesRunner/SetupCompileInfo.cs | 2 +- .../TestCaseCompilationMetadataProvider.cs | 2 +- .../TestCasesRunner/TestCaseCompiler.cs | 2 +- 35 files changed, 241 insertions(+), 79 deletions(-) create mode 100644 src/tools/illink/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingSaveAction.cs create mode 100644 src/tools/illink/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingSaveActionWithSymbols.cs rename src/tools/illink/test/Mono.Linker.Tests.Cases/References/Dependencies/{AssemblyOnlyUsedByUsing_Copied.cs => AssemblyOnlyUsedByUsing_UnusedUsing.cs} (89%) create mode 100644 src/tools/illink/test/Mono.Linker.Tests.Cases/References/Dependencies/CustomMarkHandlerSaveAssembly.cs diff --git a/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs b/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs index b6376efeef6f5a..ab3619c5958d1c 100644 --- a/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs +++ b/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs @@ -1452,7 +1452,7 @@ sealed class TypeReferenceMarker : TypeReferenceWalker readonly MarkingHelpers markingHelpers; TypeReferenceMarker (AssemblyDefinition assembly, MarkingHelpers markingHelpers) - : base (assembly) + : base (assembly, walkSymbols: false) { this.markingHelpers = markingHelpers; } diff --git a/src/tools/illink/src/linker/Linker.Steps/SweepStep.cs b/src/tools/illink/src/linker/Linker.Steps/SweepStep.cs index 9e179e92a79a25..794ef60ea19a76 100644 --- a/src/tools/illink/src/linker/Linker.Steps/SweepStep.cs +++ b/src/tools/illink/src/linker/Linker.Steps/SweepStep.cs @@ -58,7 +58,7 @@ protected override void Process () foreach (var assembly in assemblies) RemoveUnmarkedAssembly (assembly); - // Look for references (included to previously unresolved assemblies) marked for deletion + // Look for references (including to previously unresolved assemblies) marked for deletion foreach (var assembly in assemblies) UpdateAssemblyReferencesToRemovedAssemblies (assembly); @@ -69,7 +69,7 @@ protected override void Process () case AssemblyAction.CopyUsed: case AssemblyAction.Link: case AssemblyAction.Save: - bool changed = AssemblyReferencesCorrector.SweepAssemblyReferences (assembly); + bool changed = SweepAssemblyReferences (assembly); if (changed && action == AssemblyAction.CopyUsed) Annotations.SetAction (assembly, AssemblyAction.Save); break; @@ -174,7 +174,7 @@ protected void ProcessAssemblyAction (AssemblyDefinition assembly) AssemblyAction assemblyAction = AssemblyAction.Copy; if (SweepTypeForwarders (assembly)) { // Need to sweep references, in case sweeping type forwarders removed any - AssemblyReferencesCorrector.SweepAssemblyReferences (assembly); + SweepAssemblyReferences (assembly); assemblyAction = AssemblyAction.Save; } @@ -194,7 +194,7 @@ protected void ProcessAssemblyAction (AssemblyDefinition assembly) case AssemblyAction.Save: if (SweepTypeForwarders (assembly)) { // Need to sweep references, in case sweeping type forwarders removed any - AssemblyReferencesCorrector.SweepAssemblyReferences (assembly); + SweepAssemblyReferences (assembly); } break; } @@ -242,7 +242,7 @@ protected virtual void SweepAssembly (AssemblyDefinition assembly) } if (SweepTypeForwarders (assembly) || updateScopes) - AssemblyReferencesCorrector.SweepAssemblyReferences (assembly); + SweepAssemblyReferences (assembly); } bool IsMarkedAssembly (AssemblyDefinition assembly) @@ -568,32 +568,32 @@ protected virtual void CustomAttributeUsageRemoved (ICustomAttributeProvider pro { } + bool SweepAssemblyReferences (AssemblyDefinition assembly) + { + // + // We used to run over list returned by GetTypeReferences but + // that returns typeref(s) of original assembly and we don't track + // which types are needed for which assembly which left us + // with dangling assembly references + // + assembly.MainModule.AssemblyReferences.Clear (); + + var arc = new AssemblyReferencesCorrector (assembly, walkSymbols: Context.LinkSymbols); + arc.Process (); + + return arc.ChangedAnyScopes; + } + sealed class AssemblyReferencesCorrector : TypeReferenceWalker { readonly DefaultMetadataImporter importer; - bool changedAnyScopes; + public bool ChangedAnyScopes { get; private set; } - AssemblyReferencesCorrector (AssemblyDefinition assembly) : base (assembly) + public AssemblyReferencesCorrector (AssemblyDefinition assembly, bool walkSymbols) : base (assembly, walkSymbols) { this.importer = new DefaultMetadataImporter (assembly.MainModule); - changedAnyScopes = false; - } - - public static bool SweepAssemblyReferences (AssemblyDefinition assembly) - { - // - // We used to run over list returned by GetTypeReferences but - // that returns typeref(s) of original assembly and we don't track - // which types are needed for which assembly which left us - // with dangling assembly references - // - assembly.MainModule.AssemblyReferences.Clear (); - - var arc = new AssemblyReferencesCorrector (assembly); - arc.Process (); - - return arc.changedAnyScopes; + ChangedAnyScopes = false; } protected override void ProcessTypeReference (TypeReference type) @@ -626,7 +626,7 @@ protected override void ProcessTypeReference (TypeReference type) return; type.Scope = tr.Scope; - changedAnyScopes = true; + ChangedAnyScopes = true; } protected override void ProcessExportedType (ExportedType exportedType) @@ -647,7 +647,7 @@ protected override void ProcessExportedType (ExportedType exportedType) return; exportedType.Scope = tr.Scope; - changedAnyScopes = true; + ChangedAnyScopes = true; } } } diff --git a/src/tools/illink/src/linker/Linker/TypeReferenceWalker.cs b/src/tools/illink/src/linker/Linker/TypeReferenceWalker.cs index 7ae2584732686f..7b372891203d5b 100644 --- a/src/tools/illink/src/linker/Linker/TypeReferenceWalker.cs +++ b/src/tools/illink/src/linker/Linker/TypeReferenceWalker.cs @@ -15,15 +15,18 @@ abstract class TypeReferenceWalker protected HashSet Visited { get; } = new HashSet (); - public TypeReferenceWalker (AssemblyDefinition assembly) + readonly bool walkSymbols; + + public TypeReferenceWalker (AssemblyDefinition assembly, bool walkSymbols) { this.assembly = assembly; + this.walkSymbols = walkSymbols; } // Traverse the assembly and mark the scopes of discovered type references (but not exported types). // This includes scopes referenced by Cecil TypeReference objects that don't represent rows in the typeref table, // such as references to built-in types, or attribute arguments which encode type references as strings. - protected virtual void Process () + public virtual void Process () { if (Visited.Count > 0) throw new InvalidOperationException (); @@ -103,6 +106,9 @@ void WalkScopes (TypeDefinition typeDefinition) if (m.HasBody) WalkTypeScope (m.Body); + + if (walkSymbols && m.DebugInformation?.Scope?.Import is ImportDebugInformation import) + WalkDebugInfoImportScope (import); } } @@ -315,6 +321,17 @@ void WalkForwardedTypesScope (CustomAttributeArgument attributeArgument) } } + void WalkDebugInfoImportScope (ImportDebugInformation import) + { + if (import.HasTargets) { + foreach (var target in import.Targets) + WalkScopeOfTypeReference (target.Type); + } + + if (import.Parent is ImportDebugInformation parent) + WalkDebugInfoImportScope (parent); + } + void WalkScopeOfTypeReference (TypeReference type) { if (type == null) diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileBeforeAttribute.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileBeforeAttribute.cs index 73e5c69c20ca05..50ddfa7b360675 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileBeforeAttribute.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileBeforeAttribute.cs @@ -11,7 +11,7 @@ namespace Mono.Linker.Tests.Cases.Expectations.Metadata [AttributeUsage (AttributeTargets.Class, AllowMultiple = true)] public class SetupCompileBeforeAttribute : BaseMetadataAttribute { - public SetupCompileBeforeAttribute (string outputName, string[] sourceFiles, string[] references = null, string[] defines = null, object[] resources = null, string additionalArguments = null, string compilerToUse = null, bool addAsReference = true, bool removeFromLinkerInput = false, string outputSubFolder = null) + public SetupCompileBeforeAttribute (string outputName, string[] sourceFiles, string[] references = null, string[] defines = null, object[] resources = null, string[] additionalArguments = null, string compilerToUse = null, bool addAsReference = true, bool removeFromLinkerInput = false, string outputSubFolder = null) { ArgumentNullException.ThrowIfNull (sourceFiles); diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Mono.Linker.Tests.Cases.csproj b/src/tools/illink/test/Mono.Linker.Tests.Cases/Mono.Linker.Tests.Cases.csproj index 08943354e19cea..453c2d2d26593b 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Mono.Linker.Tests.Cases.csproj +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Mono.Linker.Tests.Cases.csproj @@ -16,6 +16,7 @@ + diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingSaveAction.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingSaveAction.cs new file mode 100644 index 00000000000000..283cec481da843 --- /dev/null +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingSaveAction.cs @@ -0,0 +1,42 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Helpers; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.References.Dependencies; + +namespace Mono.Linker.Tests.Cases.References +{ + /// + /// We can't detect the using usage in the assembly. As a result, nothing in `library` is going to be marked and that assembly will be deleted. + /// With the assembly action of `save`, we remove unused assembly references from the assembly and rewrite it. + /// When cecil writes the assembly, the unused typeref is not written out. + /// + + // Add a custom step which sets the assembly action of the test to "save" + [SetupCompileBefore ("SetSaveAction.dll", new[] { "Dependencies/CustomMarkHandlerSaveAssembly.cs" }, + new[] { "illink.dll", "Mono.Cecil.dll", "netstandard.dll" })] + [SetupLinkerArgument ("--custom-step", "CustomMarkHandlerSaveAssembly,SetSaveAction.dll")] + + // When csc is used, `saved.dll` will have a reference to `library.dll` + [SetupCompileBefore ("library.dll", new[] { "Dependencies/AssemblyOnlyUsedByUsing_Lib.cs" })] + [SetupCompileBefore ("saved.dll", new[] { "Dependencies/AssemblyOnlyUsedByUsing_UnusedUsing.cs" }, + // Even though this testcase doesn't link symbols, tell the compiler to produce symbols to confirm that the behavior + // isn't affected by the presence of symbols when not passing '-b'. + new[] { "library.dll" }, additionalArguments: new string[] { "/debug:portable" }, compilerToUse: "csc")] + + // Here to assert that the test is setup correctly to preserve unused code in the saved assembly. This is an important aspect of the bug + [KeptMemberInAssembly ("saved.dll", typeof (AssemblyOnlyUsedByUsing_UnusedUsing), "Unused()")] + + // The library should be gone. The `using` statement leaves no traces in the IL so nothing in `library` will be marked + [RemovedAssembly ("library.dll")] + // The `save` action results in the reference to System.Runtime being resolved into a reference directly to System.Private.CoreLib. + // The reference to `library` is removed. + [KeptReferencesInAssembly ("saved.dll", new[] { "System.Private.CoreLib" })] + public class AssemblyOnlyUsedByUsingSaveAction + { + public static void Main () + { + // Use something to keep the reference at compile time + AssemblyOnlyUsedByUsing_UnusedUsing.UsedToKeepReference (); + } + } +} diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingSaveActionWithSymbols.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingSaveActionWithSymbols.cs new file mode 100644 index 00000000000000..ae1056ab89df00 --- /dev/null +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingSaveActionWithSymbols.cs @@ -0,0 +1,45 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Helpers; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.References.Dependencies; + +namespace Mono.Linker.Tests.Cases.References +{ + /// + /// We can't detect the using usage in the assembly. As a result, nothing in `library` is going to be marked and that assembly will be deleted. + /// With the assembly action of `save`, we remove unused assembly references from the assembly and rewrite it, preserving all methods. + /// When debug symbols are present for the `save` assembly, we do not trim debug symbols, so cecil keeps all type references in the + /// save assembly that are referenced by the debug info. This includes the unused typeref, so the assemblyref referenced by the typeref + /// must also be preserved. + /// + + // Add a custom step which sets the assembly action of the test to "save" + [SetupCompileBefore ("SetSaveAction_Symbols.dll", new[] { "Dependencies/CustomMarkHandlerSaveAssembly.cs" }, + new[] { "illink.dll", "Mono.Cecil.dll", "netstandard.dll" })] + [SetupLinkerArgument ("--custom-step", "CustomMarkHandlerSaveAssembly,SetSaveAction_Symbols.dll")] + + // When csc is used, `saved.dll` will have a reference to `library.dll` + [SetupCompileBefore ("library.dll", new[] { "Dependencies/AssemblyOnlyUsedByUsing_Lib.cs" })] + [SetupCompileBefore ("saved.dll", new[] { "Dependencies/AssemblyOnlyUsedByUsing_UnusedUsing.cs" }, + new[] { "library.dll" }, additionalArguments: new string[] { "/debug:portable" }, compilerToUse: "csc")] + + // Here to assert that the test is setup correctly to preserve unused code in the saved assembly. This is an important aspect of the bug + [KeptMemberInAssembly ("saved.dll", typeof (AssemblyOnlyUsedByUsing_UnusedUsing), "Unused()")] + + // The library should be gone. The `using` statement leaves no traces in the IL so nothing in `library` will be marked + [RemovedAssembly ("library.dll")] + // The `save` action results in the reference to System.Runtime being resolved into a reference directly to System.Private.CoreLib. + // The reference to `library` is kept, because it is referenced from a typeref that is referenced from the debug info. + [KeptReferencesInAssembly ("saved.dll", new[] { "System.Private.CoreLib", "library" })] + + // Linking debug symbols is required for cecil not to remove the typeref from the assembly, because it is only referenced from the debug info. + [SetupLinkerLinkSymbols ("true")] + public class AssemblyOnlyUsedByUsingSaveActionWithSymbols + { + public static void Main () + { + // Use something to keep the reference at compile time + AssemblyOnlyUsedByUsing_UnusedUsing.UsedToKeepReference (); + } + } +} diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingWithCsc.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingWithCsc.cs index bc607d4419164e..9171863d1da3f9 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingWithCsc.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingWithCsc.cs @@ -7,18 +7,18 @@ namespace Mono.Linker.Tests.Cases.References { /// /// We can't detect the using usage in the assembly. As a result, nothing in `library` is going to be marked and that assembly will be deleted. - /// Because of that, `copied` needs to have it's reference to `library` removed even though we specified an assembly action of `copy` + /// However, because we specified an assembly action of `copy`, we do not rewrite `copied`, and it ends up with an unused reference to the removed `library`. /// [SetupLinkerAction ("copy", "copied")] - [SetupCompileBefore ("library.dll", new[] { "Dependencies/AssemblyOnlyUsedByUsing_Lib.cs" })] // When csc is used, `copied.dll` will have a reference to `library.dll` - [SetupCompileBefore ("copied.dll", new[] { "Dependencies/AssemblyOnlyUsedByUsing_Copied.cs" }, new[] { "library.dll" }, compilerToUse: "csc")] + [SetupCompileBefore ("library.dll", new[] { "Dependencies/AssemblyOnlyUsedByUsing_Lib.cs" })] + [SetupCompileBefore ("copied.dll", new[] { "Dependencies/AssemblyOnlyUsedByUsing_UnusedUsing.cs" }, new[] { "library.dll" }, compilerToUse: "csc")] // Here to assert that the test is setup correctly to copy the copied assembly. This is an important aspect of the bug - [KeptMemberInAssembly ("copied.dll", typeof (AssemblyOnlyUsedByUsing_Copied), "Unused()")] + [KeptMemberInAssembly ("copied.dll", typeof (AssemblyOnlyUsedByUsing_UnusedUsing), "Unused()")] - // We library should be gone. The `using` statement leaves no traces in the IL so nothing in `library` will be marked + // The library should be gone. The `using` statement leaves no traces in the IL so nothing in `library` will be marked [RemovedAssembly ("library.dll")] [KeptReferencesInAssembly ("copied.dll", new[] { "System.Runtime", "library" })] public class AssemblyOnlyUsedByUsingWithCsc @@ -26,7 +26,7 @@ public class AssemblyOnlyUsedByUsingWithCsc public static void Main () { // Use something to keep the reference at compile time - AssemblyOnlyUsedByUsing_Copied.UsedToKeepReference (); + AssemblyOnlyUsedByUsing_UnusedUsing.UsedToKeepReference (); } } -} \ No newline at end of file +} diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/References/Dependencies/AssemblyOnlyUsedByUsing_Copied.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/References/Dependencies/AssemblyOnlyUsedByUsing_UnusedUsing.cs similarity index 89% rename from src/tools/illink/test/Mono.Linker.Tests.Cases/References/Dependencies/AssemblyOnlyUsedByUsing_Copied.cs rename to src/tools/illink/test/Mono.Linker.Tests.Cases/References/Dependencies/AssemblyOnlyUsedByUsing_UnusedUsing.cs index caa846e827e563..006c6b0ce4a844 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/References/Dependencies/AssemblyOnlyUsedByUsing_Copied.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/References/Dependencies/AssemblyOnlyUsedByUsing_UnusedUsing.cs @@ -1,11 +1,10 @@ - // This is what triggers the behavior difference between Roslyn and mcs. Roslyn will keep the reference // to this assembly because of this whereas mcs will not using ImportantForBug = Mono.Linker.Tests.Cases.References.Dependencies.AssemblyOnlyUsedByUsing_Lib; namespace Mono.Linker.Tests.Cases.References.Dependencies { - public class AssemblyOnlyUsedByUsing_Copied + public class AssemblyOnlyUsedByUsing_UnusedUsing { public static void UsedToKeepReference () { @@ -15,4 +14,4 @@ private static void Unused () { } } -} \ No newline at end of file +} diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/References/Dependencies/CustomMarkHandlerSaveAssembly.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/References/Dependencies/CustomMarkHandlerSaveAssembly.cs new file mode 100644 index 00000000000000..c95bd8b54ba842 --- /dev/null +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/References/Dependencies/CustomMarkHandlerSaveAssembly.cs @@ -0,0 +1,15 @@ +using System; +using Mono.Cecil; +using Mono.Linker; +using Mono.Linker.Steps; + +public class CustomMarkHandlerSaveAssembly : IMarkHandler +{ + public void Initialize (LinkContext context, MarkContext markContext) + { + markContext.RegisterMarkAssemblyAction (assembly => { + if (assembly.Name.Name == "saved") + context.Annotations.SetAction (assembly, AssemblyAction.Save); + }); + } +} diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdb.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdb.cs index 8eb4836ce67afb..f1f81fbabe183e 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdb.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdb.cs @@ -5,7 +5,7 @@ namespace Mono.Linker.Tests.Cases.Symbols { - [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: "/debug:embedded", compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: new[] { "/debug:embedded" }, compilerToUse: "csc")] [SetupLinkerLinkSymbols ("false")] [RemovedSymbols ("LibraryWithEmbeddedPdbSymbols.dll")] diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbAndSymbolLinkingEnabled.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbAndSymbolLinkingEnabled.cs index 1265d927ef8fd8..45b23a5b96a62d 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbAndSymbolLinkingEnabled.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbAndSymbolLinkingEnabled.cs @@ -5,7 +5,7 @@ namespace Mono.Linker.Tests.Cases.Symbols { - [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: "/debug:embedded", compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: new[] { "/debug:embedded" }, compilerToUse: "csc")] [SetupLinkerLinkSymbols ("true")] [KeptSymbols ("LibraryWithEmbeddedPdbSymbols.dll")] diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbAndSymbolLinkingEnabledAndDeterministicMvid.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbAndSymbolLinkingEnabledAndDeterministicMvid.cs index 3de804ae5b7469..2f21be5a6212b2 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbAndSymbolLinkingEnabledAndDeterministicMvid.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbAndSymbolLinkingEnabledAndDeterministicMvid.cs @@ -4,7 +4,7 @@ namespace Mono.Linker.Tests.Cases.Symbols { - [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: "/debug:embedded", compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: new[] { "/debug:embedded" }, compilerToUse: "csc")] [SetupLinkerLinkSymbols ("true")] [SetupLinkerArgument ("--deterministic", "true")] diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbAndSymbolLinkingEnabledAndNewMvid.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbAndSymbolLinkingEnabledAndNewMvid.cs index 637d598b9a8c15..6ec3277b92d0ff 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbAndSymbolLinkingEnabledAndNewMvid.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbAndSymbolLinkingEnabledAndNewMvid.cs @@ -4,7 +4,7 @@ namespace Mono.Linker.Tests.Cases.Symbols { - [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: "/debug:embedded", compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: new[] { "/debug:embedded" }, compilerToUse: "csc")] [SetupLinkerLinkSymbols ("true")] [SetupLinkerArgument ("--deterministic", "true")] diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbCopyAction.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbCopyAction.cs index 3be34790d05e56..bb8c4f4cd08ed9 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbCopyAction.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbCopyAction.cs @@ -4,7 +4,7 @@ namespace Mono.Linker.Tests.Cases.Symbols { - [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: "/debug:embedded", compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: new[] { "/debug:embedded" }, compilerToUse: "csc")] [SetupLinkerLinkSymbols ("false")] [SetupLinkerAction ("copy", "LibraryWithEmbeddedPdbSymbols")] diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbCopyActionAndSymbolLinkingEnabled.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbCopyActionAndSymbolLinkingEnabled.cs index 5e202274623db1..b61d450d2ff037 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbCopyActionAndSymbolLinkingEnabled.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbCopyActionAndSymbolLinkingEnabled.cs @@ -4,7 +4,7 @@ namespace Mono.Linker.Tests.Cases.Symbols { - [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: "/debug:embedded", compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: new[] { "/debug:embedded" }, compilerToUse: "csc")] [SetupLinkerLinkSymbols ("true")] [SetupLinkerAction ("copy", "LibraryWithEmbeddedPdbSymbols")] diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbDeleteAction.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbDeleteAction.cs index 31a47f88cbb3ab..e436bffc0a3de7 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbDeleteAction.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbDeleteAction.cs @@ -4,7 +4,7 @@ namespace Mono.Linker.Tests.Cases.Symbols { - [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: "/debug:embedded", compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: new[] { "/debug:embedded" }, compilerToUse: "csc")] [SetupLinkerLinkSymbols ("false")] [RemovedAssembly ("LibraryWithEmbeddedPdbSymbols.dll")] diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbDeleteActionAndSymbolLinkingEnabled.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbDeleteActionAndSymbolLinkingEnabled.cs index c570ec48009917..4cbfe74923be67 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbDeleteActionAndSymbolLinkingEnabled.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbDeleteActionAndSymbolLinkingEnabled.cs @@ -4,7 +4,7 @@ namespace Mono.Linker.Tests.Cases.Symbols { - [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: "/debug:embedded", compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: new[] { "/debug:embedded" }, compilerToUse: "csc")] [SetupLinkerLinkSymbols ("true")] [RemovedAssembly ("LibraryWithEmbeddedPdbSymbols.dll")] diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdb.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdb.cs index 7fa2733ad7ad66..5d23cc56405173 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdb.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdb.cs @@ -5,7 +5,7 @@ namespace Mono.Linker.Tests.Cases.Symbols { - [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: "/debug:portable", compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: new[] { "/debug:portable" }, compilerToUse: "csc")] [SetupLinkerLinkSymbols ("false")] [RemovedSymbols ("LibraryWithPortablePdbSymbols.dll")] diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbAndSymbolLinkingEnabled.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbAndSymbolLinkingEnabled.cs index 291ec6bdd5a39a..430d9abca42f03 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbAndSymbolLinkingEnabled.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbAndSymbolLinkingEnabled.cs @@ -5,7 +5,7 @@ namespace Mono.Linker.Tests.Cases.Symbols { - [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: "/debug:portable", compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: new[] { "/debug:portable" }, compilerToUse: "csc")] [SetupLinkerLinkSymbols ("true")] [KeptSymbols ("LibraryWithPortablePdbSymbols.dll")] diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbAndSymbolLinkingEnabledAndDeterministicMvid.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbAndSymbolLinkingEnabledAndDeterministicMvid.cs index 6de9854946a24e..7ea5441e024ac5 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbAndSymbolLinkingEnabledAndDeterministicMvid.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbAndSymbolLinkingEnabledAndDeterministicMvid.cs @@ -4,7 +4,7 @@ namespace Mono.Linker.Tests.Cases.Symbols { - [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: "/debug:portable", compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: new[] { "/debug:portable" }, compilerToUse: "csc")] [SetupLinkerLinkSymbols ("true")] [SetupLinkerArgument ("--deterministic", "true")] diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbAndSymbolLinkingEnabledAndNewMvid.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbAndSymbolLinkingEnabledAndNewMvid.cs index a63248b8ab4ec6..7f1ce479fb1638 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbAndSymbolLinkingEnabledAndNewMvid.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbAndSymbolLinkingEnabledAndNewMvid.cs @@ -4,7 +4,7 @@ namespace Mono.Linker.Tests.Cases.Symbols { - [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: "/debug:portable", compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: new[] { "/debug:portable" }, compilerToUse: "csc")] [SetupLinkerLinkSymbols ("true")] [SetupLinkerArgument ("--new-mvid", "true")] diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbCopyAction.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbCopyAction.cs index de06cb99daeb7e..81716cdb97672c 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbCopyAction.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbCopyAction.cs @@ -4,7 +4,7 @@ namespace Mono.Linker.Tests.Cases.Symbols { - [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: "/debug:portable", compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: new[] { "/debug:portable" }, compilerToUse: "csc")] [SetupLinkerLinkSymbols ("false")] [SetupLinkerAction ("copy", "LibraryWithPortablePdbSymbols")] diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbCopyActionAndSymbolLinkingEnabled.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbCopyActionAndSymbolLinkingEnabled.cs index 42813cc9904347..ae77b9e4340e48 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbCopyActionAndSymbolLinkingEnabled.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbCopyActionAndSymbolLinkingEnabled.cs @@ -4,7 +4,7 @@ namespace Mono.Linker.Tests.Cases.Symbols { - [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: "/debug:portable", compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: new[] { "/debug:portable" }, compilerToUse: "csc")] [SetupLinkerLinkSymbols ("true")] [SetupLinkerAction ("copy", "LibraryWithPortablePdbSymbols")] diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbDeleteAction.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbDeleteAction.cs index 9b0b44377af094..d60e7858ff1b93 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbDeleteAction.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbDeleteAction.cs @@ -4,7 +4,7 @@ namespace Mono.Linker.Tests.Cases.Symbols { - [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: "/debug:portable", compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: new[] { "/debug:portable" }, compilerToUse: "csc")] [SetupLinkerLinkSymbols ("false")] [RemovedAssembly ("LibraryWithPortablePdbSymbols.dll")] diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbDeleteActionAndSymbolLinkingEnabled.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbDeleteActionAndSymbolLinkingEnabled.cs index 70d5f1c0fb270b..01e2b61827329e 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbDeleteActionAndSymbolLinkingEnabled.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbDeleteActionAndSymbolLinkingEnabled.cs @@ -4,7 +4,7 @@ namespace Mono.Linker.Tests.Cases.Symbols { - [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: "/debug:portable", compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: new[] { "/debug:portable" }, compilerToUse: "csc")] [SetupLinkerLinkSymbols ("true")] [RemovedAssembly ("LibraryWithPortablePdbSymbols.dll")] diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypes.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypes.cs index d4d004129fcd80..bca76ff9f5597b 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypes.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypes.cs @@ -13,9 +13,9 @@ namespace Mono.Linker.Tests.Cases.Symbols [Reference ("Dependencies/LibraryWithPdb/LibraryWithPdb.dll")] [ReferenceDependency ("Dependencies/LibraryWithPdb/LibraryWithPdb.pdb")] - [SetupCompileBefore ("LibraryWithCompilerDefaultSymbols.dll", new[] { "Dependencies/LibraryWithCompilerDefaultSymbols.cs" }, additionalArguments: "/debug:full")] - [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: "/debug:portable", compilerToUse: "csc")] - [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: "/debug:embedded", compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithCompilerDefaultSymbols.dll", new[] { "Dependencies/LibraryWithCompilerDefaultSymbols.cs" }, additionalArguments: new[] { "/debug:full" })] + [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: new[] { "/debug:portable" }, compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: new[] { "/debug:embedded" }, compilerToUse: "csc")] [SetupCompileArgument ("/debug:full")] [SetupLinkerLinkSymbols ("false")] diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypesAndSymbolLinkingEnabled.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypesAndSymbolLinkingEnabled.cs index 5f829acb37a2e3..0e1c493d637dc4 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypesAndSymbolLinkingEnabled.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypesAndSymbolLinkingEnabled.cs @@ -10,9 +10,9 @@ namespace Mono.Linker.Tests.Cases.Symbols [Reference ("Dependencies/LibraryWithPdb/LibraryWithPdb.dll")] [ReferenceDependency ("Dependencies/LibraryWithPdb/LibraryWithPdb.pdb")] - [SetupCompileBefore ("LibraryWithCompilerDefaultSymbols.dll", new[] { "Dependencies/LibraryWithCompilerDefaultSymbols.cs" }, additionalArguments: "/debug:full")] - [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: "/debug:portable", compilerToUse: "csc")] - [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: "/debug:embedded", compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithCompilerDefaultSymbols.dll", new[] { "Dependencies/LibraryWithCompilerDefaultSymbols.cs" }, additionalArguments: new[] { "/debug:full" })] + [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: new[] { "/debug:portable" }, compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: new[] { "/debug:embedded" }, compilerToUse: "csc")] [SetupCompileArgument ("/debug:full")] [SetupLinkerLinkSymbols ("true")] diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypesWithMdbAndSymbolLinkingEnabled.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypesWithMdbAndSymbolLinkingEnabled.cs index 323e1ff9fe45a1..7ab84855a7f2cb 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypesWithMdbAndSymbolLinkingEnabled.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypesWithMdbAndSymbolLinkingEnabled.cs @@ -16,9 +16,9 @@ namespace Mono.Linker.Tests.Cases.Symbols [Reference ("Dependencies/LibraryWithPdb/LibraryWithPdb.dll")] [ReferenceDependency ("Dependencies/LibraryWithPdb/LibraryWithPdb.pdb")] - [SetupCompileBefore ("LibraryWithCompilerDefaultSymbols.dll", new[] { "Dependencies/LibraryWithCompilerDefaultSymbols.cs" }, additionalArguments: "/debug:full")] - [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: "/debug:portable", compilerToUse: "csc")] - [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: "/debug:embedded", compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithCompilerDefaultSymbols.dll", new[] { "Dependencies/LibraryWithCompilerDefaultSymbols.cs" }, additionalArguments: new[] { "/debug:full" })] + [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: new[] { "/debug:portable" }, compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: new[] { "/debug:embedded" }, compilerToUse: "csc")] [SetupCompileArgument ("/debug:full")] [SetupLinkerLinkSymbols ("true")] diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/UnreachableBlock/WorksWithDynamicAssembly.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/UnreachableBlock/WorksWithDynamicAssembly.cs index 2b33fd2d378851..3b9ef031884360 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/UnreachableBlock/WorksWithDynamicAssembly.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/UnreachableBlock/WorksWithDynamicAssembly.cs @@ -8,7 +8,7 @@ namespace Mono.Linker.Tests.Cases.UnreachableBlock [SetupCompileArgument ("/optimize+")] [SetupLinkerArgument ("--enable-opt", "ipconstprop")] [SetupCompileBefore ("library.dll", new string[] { "Dependencies/ReferencedAssemblyWithUnreachableBlocks.cs" }, - addAsReference: false, additionalArguments: "/optimize+", compilerToUse: "csc")] + addAsReference: false, additionalArguments: new[] { "/optimize+" }, compilerToUse: "csc")] [RemovedMemberInAssembly ("library.dll", "Mono.Linker.Tests.Cases.UnreachableBlock.Dependencies.AssemblyWithUnreachableBlocks", new string[] { "NeverReached()" })] [ExpectedInstructionSequenceOnMemberInAssembly ("library.dll", diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ILVerifier.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ILVerifier.cs index d9d4b8a432348a..8ef1b7906d36b0 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ILVerifier.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ILVerifier.cs @@ -46,7 +46,7 @@ public ILVerifier (NPath assemblyPath) var allResults = _verifier.Verify (Resolve (assemblyName)) ?? Enumerable.Empty (); - Results = allResults.Where (r => r.Code switch { + Results = allResults.Where (r => r.Code is not ( ILVerify.VerifierError.None // Static interface methods cause this warning or ILVerify.VerifierError.CallAbstract @@ -57,10 +57,7 @@ or ILVerify.VerifierError.Unverifiable // ref returning a ref local causes this warning but is okay or VerifierError.ReturnPtrToStack // Span indexing with indexer (ex. span[^4]) causes this warning - or VerifierError.InitOnly - => false, - _ => true - }); + or VerifierError.InitOnly)); } PEReader LoadAssembly (string assemblyName) diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs index 5d2374ccaec372..11937e403b11cd 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs @@ -49,13 +49,45 @@ public ResultChecker (BaseAssemblyResolver originalsResolver, BaseAssemblyResolv _linkedReaderParameters = linkedReaderParameters; } - static void VerifyIL (NPath pathToAssembly) + static void VerifyIL (NPath pathToAssembly, AssemblyDefinition linked) { + ValidateTypeRefsHaveValidAssemblyRefs (linked); + var verifier = new ILVerifier (pathToAssembly); - foreach (var result in verifier.Results) { - if (result.Code == ILVerify.VerifierError.None) - continue; + foreach (var result in verifier.Results) Assert.Fail (ILVerifier.GetErrorMessage (result)); + } + + static void ValidateTypeRefsHaveValidAssemblyRefs (AssemblyDefinition linked) + { + Console.WriteLine ("Validating type references have valid assembly references: " + linked.FullName); + foreach (var typeRef in linked.MainModule.GetTypeReferences ()) { + switch (typeRef.Scope) { + case null: + // There should be an ExportedType row for this typeref + var exportedType = linked.MainModule.ExportedTypes.SingleOrDefault (et => et.FullName == typeRef.FullName); + Assert.IsNotNull (exportedType, $"Type reference '{typeRef.FullName}' with null scope has no ExportedType row"); + // The exported type's Implementation must be an index into the File/ExportedType/AssemblyRef table + switch (exportedType.Scope) { + case AssemblyNameReference: + // There should be an AssemblyRef row for this assembly + var assemblyRef = linked.MainModule.AssemblyReferences.Single (ar => ar.Name == exportedType.Scope.Name); + Assert.IsNotNull (assemblyRef, $"Exported type '{exportedType.FullName}' has a reference to assembly '{exportedType.Scope.Name}' which is not a reference of '{linked.FullName}'"); + break; + default: + throw new NotImplementedException ($"Unexpected scope type '{exportedType.Scope.GetType ()}' for exported type '{exportedType.FullName}'"); + } + continue; + case AssemblyNameReference: + { + // There should be an AssemblyRef row for this assembly + var assemblyRef = linked.MainModule.AssemblyReferences.Single (ar => ar.Name == typeRef.Scope.Name); + Assert.IsNotNull (assemblyRef, $"Type reference '{typeRef.FullName}' has a reference to assembly '{typeRef.Scope.Name}' which is not a reference of '{linked.FullName}'"); + continue; + } + default: + throw new NotImplementedException ($"Unexpected scope type '{typeRef.Scope.GetType ()}' for type reference '{typeRef.FullName}'"); + } } } @@ -87,7 +119,7 @@ public virtual void Check (LinkedTestCaseResult linkResult) var linked = ResolveLinkedAssembly (linkResult.OutputAssemblyPath.FileNameWithoutExtension); if (ShouldValidateIL (original)) - VerifyIL (linkResult.OutputAssemblyPath); + VerifyIL (linkResult.OutputAssemblyPath, linked); InitialChecking (linkResult, original, linked); @@ -100,6 +132,7 @@ public virtual void Check (LinkedTestCaseResult linkResult) } VerifyLinkingOfOtherAssemblies (original); + VerifyILOfOtherAssemblies (linkResult); AdditionalChecking (linkResult, original); } finally { _originalsResolver.Dispose (); @@ -117,6 +150,19 @@ bool HasActiveSkipKeptItemsValidationAttribute (ICustomAttributeProvider provide } } + void VerifyILOfOtherAssemblies (LinkedTestCaseResult linkResult) + { + foreach (var linkedAssemblyPath in linkResult.Sandbox.OutputDirectory.Files ("*.dll")) { + if (linkedAssemblyPath == linkResult.OutputAssemblyPath) + continue; + + var linked = ResolveLinkedAssembly (linkedAssemblyPath.FileNameWithoutExtension); + VerifyIL (linkedAssemblyPath, linked); + + var original = ResolveOriginalsAssembly (linkedAssemblyPath.FileNameWithoutExtension); + } + } + protected virtual AssemblyChecker CreateAssemblyChecker (AssemblyDefinition original, AssemblyDefinition linked, LinkedTestCaseResult linkedTestCase) { return new AssemblyChecker (original, linked, linkedTestCase); diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/SetupCompileInfo.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/SetupCompileInfo.cs index 7a01221e2959cb..b6cf9a4fca0066 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/SetupCompileInfo.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/SetupCompileInfo.cs @@ -12,7 +12,7 @@ public class SetupCompileInfo public string[] Defines; public string[] References; public SourceAndDestinationPair[] Resources; - public string AdditionalArguments; + public string[] AdditionalArguments; public string CompilerToUse; public bool AddAsReference; public bool RemoveFromLinkerInput; diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompilationMetadataProvider.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompilationMetadataProvider.cs index 4b7f22134ea50d..15a4ac56de0baa 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompilationMetadataProvider.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompilationMetadataProvider.cs @@ -227,7 +227,7 @@ private SetupCompileInfo CreateSetupCompileAssemblyInfo (CustomAttribute attribu References = ((CustomAttributeArgument[]) ctorArguments[2].Value)?.Select (arg => arg.Value.ToString ()).ToArray (), Defines = ((CustomAttributeArgument[]) ctorArguments[3].Value)?.Select (arg => arg.Value.ToString ()).ToArray (), Resources = ResourcesForAttributeArgument (ctorArguments[4]), - AdditionalArguments = (string) ctorArguments[5].Value, + AdditionalArguments = ((CustomAttributeArgument[]) ctorArguments[5].Value)?.Select (arg => arg.Value.ToString ()).ToArray (), CompilerToUse = (string) ctorArguments[6].Value, AddAsReference = ctorArguments.Count >= 8 ? (bool) ctorArguments[7].Value : true, RemoveFromLinkerInput = ctorArguments.Count >= 9 ? (bool) ctorArguments[8].Value : false, diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompiler.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompiler.cs index 504e1e6b2c59ae..aba20b96f3b157 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompiler.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompiler.cs @@ -94,7 +94,7 @@ protected virtual CompilerOptions CreateOptionsForSupportingAssembly (SetupCompi { var allDefines = defines.Concat (setupCompileInfo.Defines ?? Array.Empty ()).ToArray (); var allReferences = references.Concat (setupCompileInfo.References?.Select (p => MakeSupportingAssemblyReferencePathAbsolute (outputDirectory, p)) ?? Array.Empty ()).ToArray (); - string[] additionalArguments = string.IsNullOrEmpty (setupCompileInfo.AdditionalArguments) ? null : new[] { setupCompileInfo.AdditionalArguments }; + string[] additionalArguments = setupCompileInfo.AdditionalArguments; return new CompilerOptions { OutputPath = outputDirectory.Combine (setupCompileInfo.OutputName), SourceFiles = sourceFiles, From 3dbe1e834c29d3c3e7a6f5228e64f8b0e62ecbc8 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Wed, 14 Jun 2023 18:58:34 +0000 Subject: [PATCH 3/5] Don't run ILVerifier over all testcase dependencies --- .../References/AssemblyOnlyUsedByUsingSaveAction.cs | 2 +- .../AssemblyOnlyUsedByUsingSaveActionWithSymbols.cs | 2 +- .../TestCasesRunner/LinkedTestCaseResult.cs | 2 +- .../Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs | 10 ++++------ 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingSaveAction.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingSaveAction.cs index 283cec481da843..ad98b500a4eb37 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingSaveAction.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingSaveAction.cs @@ -26,7 +26,7 @@ namespace Mono.Linker.Tests.Cases.References // Here to assert that the test is setup correctly to preserve unused code in the saved assembly. This is an important aspect of the bug [KeptMemberInAssembly ("saved.dll", typeof (AssemblyOnlyUsedByUsing_UnusedUsing), "Unused()")] - // The library should be gone. The `using` statement leaves no traces in the IL so nothing in `library` will be marked + // The library should be gone. The `using` statement leaves no traces in the IL so nothing in `library` will be marked [RemovedAssembly ("library.dll")] // The `save` action results in the reference to System.Runtime being resolved into a reference directly to System.Private.CoreLib. // The reference to `library` is removed. diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingSaveActionWithSymbols.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingSaveActionWithSymbols.cs index ae1056ab89df00..f4a8479647dcc3 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingSaveActionWithSymbols.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingSaveActionWithSymbols.cs @@ -26,7 +26,7 @@ namespace Mono.Linker.Tests.Cases.References // Here to assert that the test is setup correctly to preserve unused code in the saved assembly. This is an important aspect of the bug [KeptMemberInAssembly ("saved.dll", typeof (AssemblyOnlyUsedByUsing_UnusedUsing), "Unused()")] - // The library should be gone. The `using` statement leaves no traces in the IL so nothing in `library` will be marked + // The library should be gone. The `using` statement leaves no traces in the IL so nothing in `library` will be marked [RemovedAssembly ("library.dll")] // The `save` action results in the reference to System.Runtime being resolved into a reference directly to System.Private.CoreLib. // The reference to `library` is kept, because it is referenced from a typeref that is referenced from the debug info. diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/LinkedTestCaseResult.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/LinkedTestCaseResult.cs index f0e856dfbb37cb..e6f9ae8bfee6fa 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/LinkedTestCaseResult.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/LinkedTestCaseResult.cs @@ -43,4 +43,4 @@ public LinkedTestCaseResult ( ExitCode = exitCode; } } -} \ No newline at end of file +} diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs index 11937e403b11cd..a7f88050fb0553 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs @@ -51,8 +51,6 @@ public ResultChecker (BaseAssemblyResolver originalsResolver, BaseAssemblyResolv static void VerifyIL (NPath pathToAssembly, AssemblyDefinition linked) { - ValidateTypeRefsHaveValidAssemblyRefs (linked); - var verifier = new ILVerifier (pathToAssembly); foreach (var result in verifier.Results) Assert.Fail (ILVerifier.GetErrorMessage (result)); @@ -118,8 +116,10 @@ public virtual void Check (LinkedTestCaseResult linkResult) Assert.IsTrue (linkResult.OutputAssemblyPath.FileExists (), $"The linked output assembly was not found. Expected at {linkResult.OutputAssemblyPath}"); var linked = ResolveLinkedAssembly (linkResult.OutputAssemblyPath.FileNameWithoutExtension); - if (ShouldValidateIL (original)) + if (ShouldValidateIL (original)) { VerifyIL (linkResult.OutputAssemblyPath, linked); + ValidateTypeRefsHaveValidAssemblyRefs (linked); + } InitialChecking (linkResult, original, linked); @@ -157,9 +157,7 @@ void VerifyILOfOtherAssemblies (LinkedTestCaseResult linkResult) continue; var linked = ResolveLinkedAssembly (linkedAssemblyPath.FileNameWithoutExtension); - VerifyIL (linkedAssemblyPath, linked); - - var original = ResolveOriginalsAssembly (linkedAssemblyPath.FileNameWithoutExtension); + ValidateTypeRefsHaveValidAssemblyRefs (linked); } } From 1a90728a488e6e275c54c6fc5159518e98d77c60 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Wed, 14 Jun 2023 19:19:52 +0000 Subject: [PATCH 4/5] Revert exit code checking test infra This should be adequately covered by NoLinkedOutputAttribute --- .../TestCasesRunner/LinkedTestCaseResult.cs | 16 ++-------------- .../TestCasesRunner/ResultChecker.cs | 1 - .../TestCasesRunner/TestRunner.cs | 16 +++------------- 3 files changed, 5 insertions(+), 28 deletions(-) diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/LinkedTestCaseResult.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/LinkedTestCaseResult.cs index e6f9ae8bfee6fa..b1da7c0970ded8 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/LinkedTestCaseResult.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/LinkedTestCaseResult.cs @@ -17,19 +17,8 @@ public class LinkedTestCaseResult public readonly ManagedCompilationResult CompilationResult; public readonly LinkerTestLogger Logger; public readonly LinkerCustomizations Customizations; - public readonly int ExitCode; - public LinkedTestCaseResult ( - TestCase testCase, - NPath inputAssemblyPath, - NPath outputAssemblyPath, - NPath expectationsAssemblyPath, - TestCaseSandbox sandbox, - TestCaseMetadataProvider metadataProvider, - ManagedCompilationResult compilationResult, - LinkerTestLogger logger, - LinkerCustomizations customizations, - int exitCode) + public LinkedTestCaseResult (TestCase testCase, NPath inputAssemblyPath, NPath outputAssemblyPath, NPath expectationsAssemblyPath, TestCaseSandbox sandbox, TestCaseMetadataProvider metadataProvider, ManagedCompilationResult compilationResult, LinkerTestLogger logger, LinkerCustomizations customizations) { TestCase = testCase; InputAssemblyPath = inputAssemblyPath; @@ -40,7 +29,6 @@ public LinkedTestCaseResult ( CompilationResult = compilationResult; Logger = logger; Customizations = customizations; - ExitCode = exitCode; } } -} +} \ No newline at end of file diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs index a7f88050fb0553..c8f74355fb49be 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs @@ -107,7 +107,6 @@ static bool ShouldValidateIL (AssemblyDefinition inputAssembly) public virtual void Check (LinkedTestCaseResult linkResult) { - Assert.AreEqual (0, linkResult.ExitCode, $"ILLink returned non-zero exit code: '{linkResult.ExitCode}'"); InitializeResolvers (linkResult); try { diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs index b4b58fd305b81a..7d50e5ee2a1159 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs @@ -109,19 +109,9 @@ private LinkedTestCaseResult Link (TestCase testCase, TestCaseSandbox sandbox, M AddLinkOptions (sandbox, compilationResult, builder, metadataProvider); LinkerTestLogger logger = new LinkerTestLogger (); - int exitCode = linker.Link (builder.ToArgs (), linkerCustomizations, logger); - - return new LinkedTestCaseResult ( - testCase, - compilationResult.InputAssemblyPath, - sandbox.OutputDirectory.Combine (compilationResult.InputAssemblyPath.FileName), - compilationResult.ExpectationsAssemblyPath, - sandbox, - metadataProvider, - compilationResult, - logger, - linkerCustomizations, - exitCode); + linker.Link (builder.ToArgs (), linkerCustomizations, logger); + + return new LinkedTestCaseResult (testCase, compilationResult.InputAssemblyPath, sandbox.OutputDirectory.Combine (compilationResult.InputAssemblyPath.FileName), compilationResult.ExpectationsAssemblyPath, sandbox, metadataProvider, compilationResult, logger, linkerCustomizations); } protected virtual void AddLinkOptions (TestCaseSandbox sandbox, ManagedCompilationResult compilationResult, LinkerArgumentBuilder builder, TestCaseMetadataProvider metadataProvider) From cd9f4a814392062e38a0e94394c7053e94ccd177 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Fri, 16 Jun 2023 17:06:16 +0000 Subject: [PATCH 5/5] Remove left-over output from debugging --- .../test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs index c8f74355fb49be..acdcc296683630 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs @@ -58,7 +58,6 @@ static void VerifyIL (NPath pathToAssembly, AssemblyDefinition linked) static void ValidateTypeRefsHaveValidAssemblyRefs (AssemblyDefinition linked) { - Console.WriteLine ("Validating type references have valid assembly references: " + linked.FullName); foreach (var typeRef in linked.MainModule.GetTypeReferences ()) { switch (typeRef.Scope) { case null: