From 9427f79e8eb81da796075cf45f40618e822d64f8 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Wed, 2 Oct 2024 22:07:53 +0000 Subject: [PATCH 1/2] Avoid warning for rooted RUC field --- .../src/linker/Linker.Steps/MarkStep.cs | 1 + .../RequiresInRootAllAssembly.cs | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/tools/illink/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInRootAllAssembly.cs diff --git a/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs b/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs index 27859afd6df756..d025204b1315d3 100644 --- a/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs +++ b/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs @@ -1728,6 +1728,7 @@ void ProcessAnalysisAnnotationsForField (FieldDefinition field, DependencyKind d case DependencyKind.AlreadyMarked: case DependencyKind.TypePreserve: case DependencyKind.PreservedMethod: + case DependencyKind.MemberOfType: return; case DependencyKind.DynamicallyAccessedMemberOnType: diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInRootAllAssembly.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInRootAllAssembly.cs new file mode 100644 index 00000000000000..87adbac313aab0 --- /dev/null +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInRootAllAssembly.cs @@ -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.Diagnostics.CodeAnalysis; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.RequiresCapability +{ + [SetupLinkerArgument ("-a", "test.exe")] + + [SkipKeptItemsValidation] + [ExpectedNoWarnings] + public class RequiresInRootAllAssembly + { + public static void Main () + { + } + + [RequiresDynamicCode ("--MethodWhichRequires--")] + public static void MethodWhichRequires () { } + + [RequiresDynamicCode ("--InstanceMethodWhichRequires--")] + public void InstanceMethodWhichRequires () { } + + public sealed class ClassWithDAMAnnotatedMembers + { + public static void Method ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type type) { } + + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] + public static Type Field; + } + + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] + public sealed class ClassWithDAMAnnotation + { + public void Method () { } + } + + [RequiresUnreferencedCode ("--ClassWithRequires--")] + public sealed class ClassWithRequires + { + public static int Field; + + internal static int InternalField; + + private static int PrivateField; + + public static void Method () { } + + public void InstanceMethod () { } + + public static int Property { get; set; } + + public static event EventHandler PropertyChanged; + } + } +} From 8b26f8861e95a2dfc94e9451ccb049b5dc008c47 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Thu, 3 Oct 2024 09:47:23 -0700 Subject: [PATCH 2/2] Update src/tools/illink/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInRootAllAssembly.cs Co-authored-by: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> --- .../RequiresCapability/RequiresInRootAllAssembly.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInRootAllAssembly.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInRootAllAssembly.cs index 87adbac313aab0..b8fa63c186c1c9 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInRootAllAssembly.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInRootAllAssembly.cs @@ -8,7 +8,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability { - [SetupLinkerArgument ("-a", "test.exe")] + [SetupLinkerArgument ("-a", "test.exe", "all")] [SkipKeptItemsValidation] [ExpectedNoWarnings]