From d8c8eccd164a42ffce6e27afd0c9516510aa37ff Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Fri, 18 Nov 2022 18:10:51 +0000 Subject: [PATCH 1/3] Make root behavior independent of assembly kind --- src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets | 4 ++-- src/linker/Linker.Steps/RootAssemblyInputStep.cs | 5 ----- src/linker/Linker/AssemblyRootMode.cs | 3 +-- src/linker/Linker/Driver.cs | 8 +++----- test/ILLink.Tasks.Tests/Mock.cs | 2 +- 5 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets b/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets index 84430b7686bb..108c5c25bd63 100644 --- a/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets +++ b/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets @@ -279,9 +279,9 @@ Copyright (c) .NET Foundation. All rights reserved. - + - + diff --git a/src/linker/Linker.Steps/RootAssemblyInputStep.cs b/src/linker/Linker.Steps/RootAssemblyInputStep.cs index 7e4d47b2cc4a..2bc77920e401 100644 --- a/src/linker/Linker.Steps/RootAssemblyInputStep.cs +++ b/src/linker/Linker.Steps/RootAssemblyInputStep.cs @@ -42,11 +42,6 @@ protected override void Process () } switch (rootMode) { - case AssemblyRootMode.Default: - if (assembly.MainModule.Kind == ModuleKind.Dll) - goto case AssemblyRootMode.AllMembers; - else - goto case AssemblyRootMode.EntryPoint; case AssemblyRootMode.EntryPoint: var ep = assembly.MainModule.EntryPoint; if (ep == null) { diff --git a/src/linker/Linker/AssemblyRootMode.cs b/src/linker/Linker/AssemblyRootMode.cs index 07ceac1625a6..c9a3d98a604c 100644 --- a/src/linker/Linker/AssemblyRootMode.cs +++ b/src/linker/Linker/AssemblyRootMode.cs @@ -5,9 +5,8 @@ namespace Mono.Linker { public enum AssemblyRootMode { - Default = 0, + AllMembers = 0, EntryPoint, - AllMembers, VisibleMembers, Library } diff --git a/src/linker/Linker/Driver.cs b/src/linker/Linker/Driver.cs index f92457544ef5..7b9e10bdda64 100644 --- a/src/linker/Linker/Driver.cs +++ b/src/linker/Linker/Driver.cs @@ -639,10 +639,10 @@ protected int SetupContext (ILogger? customLogger = null) return -1; } - AssemblyRootMode rmode = AssemblyRootMode.Default; + AssemblyRootMode rmode = AssemblyRootMode.AllMembers; var rootMode = GetNextStringValue (); if (rootMode != null) { - var parsed_rmode = ParseAssemblyRootsMode (rootMode); + var parsed_rmode = ParseAssemblyRootMode (rootMode); if (parsed_rmode is null) return -1; @@ -1115,11 +1115,9 @@ static string[] ReadLines (string file) return null; } - AssemblyRootMode? ParseAssemblyRootsMode (string s) + AssemblyRootMode? ParseAssemblyRootMode (string s) { switch (s.ToLowerInvariant ()) { - case "default": - return AssemblyRootMode.Default; case "all": return AssemblyRootMode.AllMembers; case "visible": diff --git a/test/ILLink.Tasks.Tests/Mock.cs b/test/ILLink.Tasks.Tests/Mock.cs index e4fba2d23064..979d62b1448a 100644 --- a/test/ILLink.Tasks.Tests/Mock.cs +++ b/test/ILLink.Tasks.Tests/Mock.cs @@ -178,7 +178,7 @@ public Dictionary GetCustomData () protected override List CreateDefaultResolvers () { return new List () { - new RootAssemblyInput (null, AssemblyRootMode.Default) + new RootAssemblyInput (null, AssemblyRootMode.EntryPoint) }; } } From dc96e01b42575cc8463f615b24a2be828d5e7d16 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Fri, 18 Nov 2022 19:09:30 +0000 Subject: [PATCH 2/3] Fix up tests --- ...es.BaseProvidesInterfaceEdgeCaseTests.g.cs | 19 +++++++++++++++++++ .../StaticInterfaceMethodsInPreservedScope.cs | 3 +-- ...VirtualInterfaceMethodsInPreservedScope.cs | 3 +-- .../Libraries/DefaultLibraryLinkBehavior.cs | 3 ++- .../TestCasesRunner/LinkerArgumentBuilder.cs | 3 ++- 5 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/Inheritance.Interfaces.BaseProvidesInterfaceEdgeCaseTests.g.cs diff --git a/test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/Inheritance.Interfaces.BaseProvidesInterfaceEdgeCaseTests.g.cs b/test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/Inheritance.Interfaces.BaseProvidesInterfaceEdgeCaseTests.g.cs new file mode 100644 index 000000000000..5aaf8776a261 --- /dev/null +++ b/test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/Inheritance.Interfaces.BaseProvidesInterfaceEdgeCaseTests.g.cs @@ -0,0 +1,19 @@ +using System; +using System.Threading.Tasks; +using Xunit; + +namespace ILLink.RoslynAnalyzer.Tests.Inheritance.Interfaces +{ + public sealed partial class BaseProvidesInterfaceEdgeCaseTests : LinkerTestBase + { + + protected override string TestSuiteName => "Inheritance.Interfaces.BaseProvidesInterfaceEdgeCase"; + + [Fact] + public Task BaseProvidesInterfaceMethodCircularReference () + { + return RunTest (allowMissingWarnings: true); + } + + } +} \ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/StaticInterfaceMethodsInPreservedScope.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/StaticInterfaceMethodsInPreservedScope.cs index b57d58c395f3..362413c3f971 100644 --- a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/StaticInterfaceMethodsInPreservedScope.cs +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/StaticInterfaceMethodsInPreservedScope.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. +// 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; @@ -15,7 +15,6 @@ namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.StaticInterfaceMethods { [SetupCompileBefore ("library.dll", new[] { "Dependencies/Library.cs" })] [SetupLinkerAction ("skip", "library")] - [SetupLinkerArgument ("-a", "test.exe")] public static class StaticInterfaceMethodsInPreservedScope { [Kept] diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/StaticVirtualInterfaceMethodsInPreservedScope.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/StaticVirtualInterfaceMethodsInPreservedScope.cs index 3dac2feb789f..26a5a2cc0661 100644 --- a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/StaticVirtualInterfaceMethodsInPreservedScope.cs +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/StaticVirtualInterfaceMethodsInPreservedScope.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. +// 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; @@ -15,7 +15,6 @@ namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.StaticInterfaceMethods { [SetupCompileBefore ("library.dll", new[] { "Dependencies/Library.cs" })] [SetupLinkerAction ("skip", "library")] - [SetupLinkerArgument ("-a", "test.exe")] public static class StaticVirtualInterfaceMethodsInPreservedScope { [Kept] diff --git a/test/Mono.Linker.Tests.Cases/Libraries/DefaultLibraryLinkBehavior.cs b/test/Mono.Linker.Tests.Cases/Libraries/DefaultLibraryLinkBehavior.cs index 19ae1ea1cf80..fd0c55781622 100644 --- a/test/Mono.Linker.Tests.Cases/Libraries/DefaultLibraryLinkBehavior.cs +++ b/test/Mono.Linker.Tests.Cases/Libraries/DefaultLibraryLinkBehavior.cs @@ -1,9 +1,10 @@ -using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Assertions; using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.Libraries { [SetupCompileAsLibrary] + [SetupLinkerArgument ("-a", "test.dll")] [Kept] [KeptMember (".ctor()")] public class DefaultLibraryLinkBehavior diff --git a/test/Mono.Linker.Tests/TestCasesRunner/LinkerArgumentBuilder.cs b/test/Mono.Linker.Tests/TestCasesRunner/LinkerArgumentBuilder.cs index 43dbcdd21c10..ae0673e9903a 100644 --- a/test/Mono.Linker.Tests/TestCasesRunner/LinkerArgumentBuilder.cs +++ b/test/Mono.Linker.Tests/TestCasesRunner/LinkerArgumentBuilder.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. +// 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.Collections.Generic; @@ -61,6 +61,7 @@ public virtual void LinkFromAssembly (string fileName) { Append ("-a"); Append (fileName); + Append ("entrypoint"); } public virtual void LinkFromPublicAndFamily (string fileName) From 33434126aadce8fea4163398c12532faa88a1ad3 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Fri, 18 Nov 2022 19:58:50 +0000 Subject: [PATCH 3/3] Clean up old comment --- src/ILLink.Tasks/LinkTask.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/ILLink.Tasks/LinkTask.cs b/src/ILLink.Tasks/LinkTask.cs index 170ef8f7bf81..b89b893be681 100644 --- a/src/ILLink.Tasks/LinkTask.cs +++ b/src/ILLink.Tasks/LinkTask.cs @@ -43,11 +43,8 @@ public class ILLink : ToolTask /// /// The names of the assemblies to root. This should contain /// assembly names without an extension, not file names or - /// paths. Exactly which parts of the assemblies get rooted - /// is subject to change. Currently these get passed to - /// illink with "-a", which roots the entry point for - /// executables, and everything for libraries. To control - /// the behaviour explicitly, set RootMode metadata. + /// paths. The default is to root everything in these assemblies. + // For more fine-grained control, set RootMode metadata. /// [Required] public ITaskItem[] RootAssemblyNames { get; set; }