Skip to content

Commit

Permalink
Make default rooting behavior consistent (dotnet/linker#3124)
Browse files Browse the repository at this point in the history
Now specifying an assembly as a root without any other qualifiers will default to rooting everything.

Commit migrated from dotnet/linker@e775974
  • Loading branch information
sbomer authored Nov 21, 2022
1 parent a1ef8af commit 1eaf094
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 26 deletions.
7 changes: 2 additions & 5 deletions src/tools/illink/src/ILLink.Tasks/LinkTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@ public class ILLink : ToolTask
/// <summary>
/// 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.
/// </summary>
[Required]
public ITaskItem[] RootAssemblyNames { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ Copyright (c) .NET Foundation. All rights reserved.
<ManagedAssemblyToLink Include="@(_TrimmableManagedAssemblyToLink)" IsTrimmable="true" />
</ItemGroup>

<!-- Root the main assembly, whether or not it has IsTrimmable set. -->
<!-- Root the main assembly entry point. -->
<ItemGroup>
<TrimmerRootAssembly Include="@(IntermediateAssembly)" />
<TrimmerRootAssembly Include="@(IntermediateAssembly)" RootMode="EntryPoint" />
</ItemGroup>

<!-- For .NET < 6, root and copy assemblies without IsTrimmable=true MSBuild metadata. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions src/tools/illink/src/linker/Linker/AssemblyRootMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ namespace Mono.Linker
{
public enum AssemblyRootMode
{
Default = 0,
AllMembers = 0,
EntryPoint,
AllMembers,
VisibleMembers,
Library
}
Expand Down
8 changes: 3 additions & 5 deletions src/tools/illink/src/linker/Linker/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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":
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

}
}
2 changes: 1 addition & 1 deletion src/tools/illink/test/ILLink.Tasks.Tests/Mock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public Dictionary<string, string> GetCustomData ()
protected override List<BaseStep> CreateDefaultResolvers ()
{
return new List<BaseStep> () {
new RootAssemblyInput (null, AssemblyRootMode.Default)
new RootAssemblyInput (null, AssemblyRootMode.EntryPoint)
};
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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]
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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]
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -61,6 +61,7 @@ public virtual void LinkFromAssembly (string fileName)
{
Append ("-a");
Append (fileName);
Append ("entrypoint");
}

public virtual void LinkFromPublicAndFamily (string fileName)
Expand Down

0 comments on commit 1eaf094

Please sign in to comment.