-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid copy action for root assemblies (#96363)
Changes TrimmerRootAssembly (and the underlying option -a) to root all members of the assembly, without setting the action to copy. This allows us to perform branch removal and attribute removal for the assembly. This includes changes to MarkStep to ensure that rooted assemblies are marked visible to reflection. This for example ensures that parameter names don't get removed. With the change to MarkEntireType that calls MarkType instead of Annotations.Mark, we are now reaching MarkType for the dependency from the copy assembly to the attribute it contains, producing an unexpected IL2045. Silence this by checking the DependencyKind. Also fixes a bug in constant method analysis that this uncovered: BitVector32.CreateMask(int.MinValue) was incorrectly being treated as returning constant 1. The IL from the beginning of that method: IL_0000: ldarg.0 IL_0001: brtrue.s IL_0005 IL_0003: ldc.i4.1 IL_0004: ret The brtrue.s branch was being analyzed as not taken because the argument was not 1. The branch should be analyzed as taken for any non-zero argument.
- Loading branch information
Showing
25 changed files
with
318 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
.../illink/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupLinkerLinkAllAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
|
||
namespace Mono.Linker.Tests.Cases.Expectations.Metadata | ||
{ | ||
[AttributeUsage (AttributeTargets.Class, AllowMultiple = false)] | ||
public class SetupLinkerLinkAllAttribute : BaseMetadataAttribute | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/tools/illink/test/Mono.Linker.Tests.Cases/Libraries/Dependencies/RootAllLibrary.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// 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.Diagnostics.CodeAnalysis; | ||
using System.Runtime.CompilerServices; | ||
using Mono.Linker.Tests.Cases.Libraries.Dependencies; | ||
|
||
#if RootAllLibrary | ||
[assembly: TypeForwardedTo (typeof (RootAllLibrary_ExportedType))] | ||
#endif | ||
|
||
namespace Mono.Linker.Tests.Cases.Libraries.Dependencies | ||
{ | ||
public class RootAllLibrary | ||
{ | ||
public static void Public () | ||
{ | ||
} | ||
|
||
private static void Private () | ||
{ | ||
} | ||
|
||
private class NestedType | ||
{ | ||
} | ||
|
||
public static void RemovedBranch () | ||
{ | ||
if (SubstitutedProperty) | ||
RootAllLibrary_OptionalDependency.Use (); | ||
} | ||
|
||
// Substituted to false in RootAllLibrary_Substitutions.xml | ||
static bool SubstitutedProperty { | ||
get { | ||
RequiresUnreferencedCode (); | ||
return true; | ||
} | ||
} | ||
|
||
[RequiresUnreferencedCode (nameof (RequiresUnreferencedCode))] | ||
static void RequiresUnreferencedCode () | ||
{ | ||
} | ||
|
||
[RootAllLibrary_RemovedAttribute] | ||
class TypeWithRemovedAttribute | ||
{ | ||
} | ||
} | ||
|
||
class NonPublicType | ||
{ | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...illink/test/Mono.Linker.Tests.Cases/Libraries/Dependencies/RootAllLibrary_ExportedType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// 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. | ||
|
||
namespace Mono.Linker.Tests.Cases.Libraries.Dependencies | ||
{ | ||
public class RootAllLibrary_ExportedType | ||
{ | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...ink/test/Mono.Linker.Tests.Cases/Libraries/Dependencies/RootAllLibrary_LinkAttributes.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<linker> | ||
<assembly fullname="removedattribute"> | ||
<type fullname="Mono.Linker.Tests.Cases.Libraries.Dependencies.RootAllLibrary_RemovedAttribute"> | ||
<attribute internal="RemoveAttributeInstances" /> | ||
</type> | ||
</assembly> | ||
</linker> |
12 changes: 12 additions & 0 deletions
12
.../test/Mono.Linker.Tests.Cases/Libraries/Dependencies/RootAllLibrary_OptionalDependency.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Mono.Linker.Tests.Cases.Libraries.Dependencies | ||
{ | ||
public class RootAllLibrary_OptionalDependency | ||
{ | ||
[RequiresUnreferencedCode (nameof (RootAllLibrary_OptionalDependency))] | ||
public static void Use () | ||
{ | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...nk/test/Mono.Linker.Tests.Cases/Libraries/Dependencies/RootAllLibrary_RemovedAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System; | ||
|
||
namespace Mono.Linker.Tests.Cases.Libraries.Dependencies | ||
{ | ||
public class RootAllLibrary_RemovedAttribute : Attribute | ||
{ | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...link/test/Mono.Linker.Tests.Cases/Libraries/Dependencies/RootAllLibrary_Substitutions.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<linker> | ||
<assembly fullname="library"> | ||
<type fullname="Mono.Linker.Tests.Cases.Libraries.Dependencies.RootAllLibrary"> | ||
<method signature="System.Boolean get_SubstitutedProperty()" body="stub" value="false" /> | ||
</type> | ||
</assembly> | ||
</linker> |
Oops, something went wrong.