-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix marking of saved assemblies (#86474)
This ensures the fix from #82197 works also for assemblies which get the `save` action (which isn't supported from the command-line, but may happen in custom steps). It also ensures that `save` assemblies get fully marked regardless of `DisableMarkingOfCopyAssemblies`. --------- Co-authored-by: Jackson Schuster <36744439+jtschuster@users.noreply.github.com>
- Loading branch information
1 parent
a331b56
commit 840c20e
Showing
6 changed files
with
90 additions
and
8 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
13 changes: 13 additions & 0 deletions
13
...ases/Inheritance.Interfaces/StaticInterfaceMethods/Dependencies/CustomStepSaveAssembly.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,13 @@ | ||
using System; | ||
using Mono.Cecil; | ||
using Mono.Linker; | ||
using Mono.Linker.Steps; | ||
|
||
public class CustomStepSaveAssembly : BaseStep | ||
{ | ||
protected override void ProcessAssembly (AssemblyDefinition assembly) | ||
{ | ||
if (assembly.Name.Name == "test") | ||
Context.Annotations.SetAction (assembly, AssemblyAction.Save); | ||
} | ||
} |
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
59 changes: 59 additions & 0 deletions
59
...inker.Tests.Cases/Inheritance.Interfaces/StaticInterfaceMethods/OverrideInSaveAssembly.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,59 @@ | ||
// 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; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Mono.Linker.Tests.Cases.Expectations.Assertions; | ||
using Mono.Linker.Tests.Cases.Expectations.Metadata; | ||
using Mono.Linker.Tests.Cases.Inheritance.Interfaces.StaticInterfaceMethods.Dependencies; | ||
|
||
namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.StaticInterfaceMethods | ||
{ | ||
[KeptMemberInAssembly ("library", typeof (IStaticAbstractMethods), "Method()", "get_Property()", "Property", "set_Property(System.Int32)")] | ||
// Add a custom step which sets the assembly action of the test to "save" | ||
[SetupCompileBefore ("CustomStepSaveAssembly.dll", new[] { "Dependencies/CustomStepSaveAssembly.cs" }, new[] { "illink.dll", "Mono.Cecil.dll", "netstandard.dll" })] | ||
[SetupLinkerArgument ("--custom-step", "-MarkStep:CustomStepSaveAssembly,CustomStepSaveAssembly.dll")] | ||
[SetupCompileBefore ("library.dll", new[] { "Dependencies/Library.cs" })] | ||
[SetupLinkerAction ("link", "library")] | ||
/// <summary> | ||
/// Regression test for issue: https://github.com/dotnet/runtime/issues/86242 | ||
/// OverridesStaticInterfaceMethods.Method() (and Property.set/get) has an entry in .overrides pointing to IStaticAbstractMethods.Method. | ||
/// IStaticAbstractMethods.Method() isn't referenced anywhere else and isn't otherwise needed. | ||
/// Usually the interface method could be removed, and the pointer to it in the .overrides metadata would be removed | ||
/// However, since OverridesStaticInterfaceMethods is in a 'save' assembly, the .overrides metadata isn't swept. If we remove the method from the interface, | ||
/// we have a "dangling reference" which makes the metadata invalid. | ||
/// </summary> | ||
static class OverrideInSaveAssembly | ||
{ | ||
[Kept] | ||
public static void Main () | ||
{ | ||
OverridesStaticInterfaceMethods.Property = OverridesStaticInterfaceMethods.Method (); | ||
var x = OverridesStaticInterfaceMethods.Property; | ||
} | ||
[Kept] | ||
[KeptMember (".ctor()")] | ||
[KeptInterface (typeof (IStaticAbstractMethods))] | ||
class OverridesStaticInterfaceMethods : IStaticAbstractMethods | ||
{ | ||
[Kept] | ||
public static int Property { | ||
[Kept] | ||
[KeptOverride (typeof (IStaticAbstractMethods))] | ||
get => throw new NotImplementedException (); | ||
[Kept] | ||
[KeptOverride (typeof (IStaticAbstractMethods))] | ||
set => throw new NotImplementedException (); | ||
} | ||
[Kept] | ||
[KeptOverride (typeof (IStaticAbstractMethods))] | ||
|
||
public static int Method () => throw new NotImplementedException (); | ||
[Kept] | ||
public int InstanceMethod () => throw new NotImplementedException (); | ||
} | ||
} | ||
} |
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