Skip to content

Commit 6650a8a

Browse files
authored
Suppress warnings in 6.0 framework (dotnet/linker#3000)
This includes a sidecar XML file which will suppress new warnings in the 6.0 framework. Note that a few of the new warnings for compiler-generated code are suppressed in 7.0 with attributes on local functions. In the XML I had to suppress them with an attribute on the user method (since the signature format doesn't support compiler-generated code). Also note that this approach only includes suppressions for the core framework, not OOB assemblies. OOB assemblies or third-party nuget packages will require a slightly different approach to avoid warnings about unresolved members referenced in XML, in apps where those assemblies aren't used. There are no warnings that we need to suppress in OOB assemblies - only new warnings in already trim-incompatible code. This also includes a fix for a varargs method issue I found while running on the 6.0 framework. Commit migrated from dotnet/linker@1a13498
1 parent 6e79042 commit 6650a8a

6 files changed

Lines changed: 176 additions & 2 deletions

File tree

src/tools/illink/src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ GenericParameterValue genericParam
11451145
_requireDynamicallyAccessedMembersAction.Invoke (instanceValue, _annotations.GetMethodThisParameterValue (calledMethod));
11461146
}
11471147
for (int argumentIndex = 0; argumentIndex < argumentValues.Count; argumentIndex++) {
1148-
if (calledMethod.ParameterReferenceKind (argumentIndex) == ReferenceKind.Out)
1148+
if (argumentIndex >= calledMethod.GetParametersCount () || calledMethod.ParameterReferenceKind (argumentIndex) == ReferenceKind.Out)
11491149
continue;
11501150
_requireDynamicallyAccessedMembersAction.Invoke (argumentValues[argumentIndex], _annotations.GetMethodParameterValue (calledMethod, argumentIndex));
11511151
}

src/tools/illink/src/ILLink.Tasks/ILLink.Tasks.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
<Content Include="build/Microsoft.NET.ILLink.targets" PackagePath="build/">
4545
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
4646
</Content>
47+
<Content Include="build/6.0_suppressions.xml" PackagePath="build/">
48+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
49+
</Content>
4750
</ItemGroup>
4851

4952
<ItemGroup>
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<linker>
3+
<assembly fullname="System.Private.CoreLib">
4+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
5+
<argument>ILLink</argument>
6+
<argument>IL2070</argument>
7+
<property name="Scope">member</property>
8+
<property name="Target">M:System.Reflection.CustomAttribute.AddCustomAttributes(System.RuntimeType.ListBuilder{System.Object}@,System.Reflection.RuntimeModule,System.Int32,System.RuntimeType,System.Boolean,System.RuntimeType.ListBuilder{System.Object})</property>
9+
<property name="Justification">Suppressed in 7.0 for ref param changes: https://github.com/dotnet/runtime/commit/50d289cc2b945c8ee6b4cca5b71d8d137c09a762</property>
10+
</attribute>
11+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
12+
<argument>ILLink</argument>
13+
<argument>IL2063</argument>
14+
<property name="Scope">member</property>
15+
<property name="Target">M:System.RuntimeType.GetInterface(System.String,System.Boolean)</property>
16+
<property name="Justification">Suppressed in 7.0 for dataflow improvements: https://github.com/dotnet/runtime/commit/2e353d18b81732133aadbee888a801fd9f935fbf</property>
17+
</attribute>
18+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
19+
<argument>ILLink</argument>
20+
<argument>IL2067</argument>
21+
<property name="Scope">member</property>
22+
<property name="Target">M:System.RuntimeTypeHandle.CreateInstanceForAnotherGenericParameter(System.RuntimeType,System.RuntimeType,System.RuntimeType)</property>
23+
<property name="Justification">Suppressed in 7.0 for ref param changes: https://github.com/dotnet/runtime/commit/50d289cc2b945c8ee6b4cca5b71d8d137c09a762</property>
24+
</attribute>
25+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
26+
<argument>ILLink</argument>
27+
<argument>IL2067</argument>
28+
<property name="Scope">member</property>
29+
<property name="Target">M:System.RuntimeTypeHandle.CreateInstanceForAnotherGenericParameter(System.RuntimeType,System.RuntimeType)</property>
30+
<property name="Justification">Suppressed in 7.0 for ref param changes: https://github.com/dotnet/runtime/commit/50d289cc2b945c8ee6b4cca5b71d8d137c09a762</property>
31+
</attribute>
32+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
33+
<argument>ILLink</argument>
34+
<argument>IL2068</argument>
35+
<property name="Scope">member</property>
36+
<property name="Target">M:System.Reflection.Emit.TypeBuilder.CreateTypeNoLock</property>
37+
<property name="Justification">Suppressed in 7.0 for ref param changes: https://github.com/dotnet/runtime/commit/50d289cc2b945c8ee6b4cca5b71d8d137c09a762</property>
38+
</attribute>
39+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
40+
<argument>ILLink</argument>
41+
<argument>IL2069</argument>
42+
<property name="Scope">member</property>
43+
<property name="Target">M:System.Reflection.Emit.TypeBuilder.CreateTypeNoLock</property>
44+
<property name="Justification">Suppressed in 7.0 for ref param changes: https://github.com/dotnet/runtime/commit/50d289cc2b945c8ee6b4cca5b71d8d137c09a762</property>
45+
</attribute>
46+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
47+
<argument>ILLink</argument>
48+
<argument>IL2119</argument>
49+
<property name="Scope">member</property>
50+
<property name="Target">M:System.Diagnostics.Tracing.EventSource.WriteEventString(System.String)</property>
51+
<property name="Justification">Suppressed in 7.0 for compiler-generated code changes: https://github.com/dotnet/runtime/commit/4a79e0696b1e425a58d8f5104cc572f39dd3005ea</property>
52+
</attribute>
53+
</assembly>
54+
55+
<assembly fullname="System.ComponentModel.Annotations">
56+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
57+
<argument>ILLink</argument>
58+
<argument>IL2068</argument>
59+
<property name="Scope">member</property>
60+
<property name="Target">M:System.ComponentModel.DataAnnotations.AssociatedMetadataTypeTypeDescriptor.TypeDescriptorCache.GetAssociatedMetadataType(System.Type)</property>
61+
<property name="Justification">Suppressed in 7.0 for ref param changes: https://github.com/dotnet/runtime/commit/50d289cc2b945c8ee6b4cca5b71d8d137c09a762</property>
62+
</attribute>
63+
</assembly>
64+
65+
<assembly fullname="System.Data.Common">
66+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
67+
<argument>ILLink</argument>
68+
<argument>IL2060</argument>
69+
<property name="Scope">member</property>
70+
<property name="Target">M:System.Data.DataRowExtensions.UnboxT`1.Create()</property>
71+
<property name="Justification">Suppressed in 7.0 for new constraint warning: https://github.com/dotnet/runtime/commit/31d5d23e9c6f3da877343ccb020e85ca9f136c05</property>
72+
</attribute>
73+
</assembly>
74+
75+
<assembly fullname="System.Reflection.Metadata">
76+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
77+
<argument>ILLink</argument>
78+
<argument>IL2070</argument>
79+
<property name="Scope">member</property>
80+
<property name="Target">M:System.Reflection.CustomAttribute.AddCustomAttributes(System.RuntimeType.ListBuilder`1@,System.Reflection.RuntimeModule,System.Int32,System.RuntimeType,System.Bool,System.RuntimeType.ListBuilder{System.Object})</property>
81+
<property name="Justification">Suppressed in 7.0 for ref param changes: https://github.com/dotnet/runtime/commit/50d289cc2b945c8ee6b4cca5b71d8d137c09a762</property>
82+
</attribute>
83+
</assembly>
84+
85+
<assembly fullname="System.Diagnostics.DiagnosticSource">
86+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
87+
<argument>ILLink</argument>
88+
<argument>IL2119</argument>
89+
<property name="Scope">member</property>
90+
<property name="Target">M:System.Diagnostics.DiagnosticSourceEventSource.FilterAndTransform.#ctor(System.String,System.Int32,System.Int32,System.Diagnostics.DiagnosticSourceEventSource,System.Diagnostics.DiagnosticSourceEventSource.FilterAndTransform)</property>
91+
<property name="Justification">Suppressed in 7.0 for compiler-generated code changes: https://github.com/dotnet/runtime/commit/4a79e0696b1e425a58d8f5104cc572f39dd3005ea</property>
92+
</attribute>
93+
</assembly>
94+
95+
<assembly fullname="System.Runtime.Serialization.Formatters">
96+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
97+
<argument>ILLink</argument>
98+
<argument>IL2065</argument>
99+
<property name="Scope">member</property>
100+
<property name="Target">M:System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(System.Type)</property>
101+
<property name="Justification">Suppressed in 7.0 for dataflow improvements: https://github.com/dotnet/runtime/commit/2e353d18b81732133aadbee888a801fd9f935fbf</property>
102+
</attribute>
103+
</assembly>
104+
105+
<assembly fullname="System.Text.Json">
106+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
107+
<argument>ILLink</argument>
108+
<argument>IL2055</argument>
109+
<property name="Scope">member</property>
110+
<property name="Target">M:System.Text.Json.Serialization.Converters.FSharpTypeConverterFactory.CreateConverter(System.Type,System.Text.Json.JsonSerializerOptions)</property>
111+
<property name="Justification">Suppressed in 7.0 for new constraint warning: https://github.com/dotnet/runtime/commit/31d5d23e9c6f3da877343ccb020e85ca9f136c05</property>
112+
</attribute>
113+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
114+
<argument>ILLink</argument>
115+
<argument>IL2070</argument>
116+
<property name="Scope">member</property>
117+
<property name="Target">M:System.Text.Json.Serialization.Converters.EnumConverterFactory.GetEnumConverterType(System.Type)</property>
118+
<property name="Justification">Suppressed in 7.0 for new constraint warning: https://github.com/dotnet/runtime/commit/31d5d23e9c6f3da877343ccb020e85ca9f136c05</property>
119+
</attribute>
120+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
121+
<argument>ILLink</argument>
122+
<argument>IL2070</argument>
123+
<property name="Scope">member</property>
124+
<property name="Target">M:System.Text.Json.Serialization.Converters.NullableConverterFactory.GetNullableConverterType(System.Type)</property>
125+
<property name="Justification">Suppressed in 7.0 for new constraint warning: https://github.com/dotnet/runtime/commit/31d5d23e9c6f3da877343ccb020e85ca9f136c05</property>
126+
</attribute>
127+
</assembly>
128+
129+
<assembly fullname="System.Private.Xml">
130+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
131+
<argument>ILLink</argument>
132+
<argument>IL2118</argument>
133+
<property name="Scope">member</property>
134+
<property name="Target">M:System.Xml.Serialization.TypeScope.#cctor</property>
135+
<property name="Justification">Suppressed in 7.0 for compiler-generated code changes: https://github.com/dotnet/runtime/commit/4a79e0696b1e425a58d8f5104cc572f39dd3005ea</property>
136+
</attribute>
137+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
138+
<argument>ILLink</argument>
139+
<argument>IL2118</argument>
140+
<property name="Scope">member</property>
141+
<property name="Target">M:System.Xml.Serialization.TypeScope.AddSoapEncodedTypes(System.String)</property>
142+
<property name="Justification">Suppressed in 7.0 for compiler-generated code changes: https://github.com/dotnet/runtime/commit/4a79e0696b1e425a58d8f5104cc572f39dd3005ea</property>
143+
</attribute>
144+
</assembly>
145+
146+
<assembly fullname="System.Private.DataContractSerialization">
147+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
148+
<argument>ILLink</argument>
149+
<argument>IL2118</argument>
150+
<property name="Scope">member</property>
151+
<property name="Target">M:System.Runtime.Serialization.DateTimeDataContract.#ctor</property>
152+
<property name="Justification">Suppressed in 7.0 for compiler-generated code changes: https://github.com/dotnet/runtime/commit/4a79e0696b1e425a58d8f5104cc572f39dd3005ea</property>
153+
</attribute>
154+
</assembly>
155+
156+
</linker>

src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,15 @@ Copyright (c) .NET Foundation. All rights reserved.
205205
<Warning Condition="'$(TrimmerDefaultAction)' != '' And $([MSBuild]::VersionGreaterThan('$(TargetFrameworkVersion)', '6.0'))"
206206
Text="Property 'TrimmerDefaultAction' is deprecated in .NET 7 and will be ignored. Use TrimMode instead." />
207207

208+
<!-- Use a sidecar file to suppress warnings when targeting net6.0, for changes that added or changed warnings. -->
209+
<ItemGroup Condition="$([MSBuild]::VersionEquals($(TargetFrameworkVersion), '6.0'))">
210+
<_ILLinkSuppressions Include="$(MSBuildThisFileDirectory)6.0_suppressions.xml" />
211+
</ItemGroup>
212+
213+
<PropertyGroup Condition="'@(_ILLinkSuppressions->Count())' != '0'">
214+
<_ExtraTrimmerArgs>$(_ExtraTrimmerArgs) --link-attributes "@(_ILLinkSuppressions->'%(Identity)', '" --link-attributes "')"</_ExtraTrimmerArgs>
215+
</PropertyGroup>
216+
208217
<!-- Set up TrimMode and TrimmerDefaultAction. -->
209218
<PropertyGroup>
210219
<TrimMode Condition="'$(TrimMode)' == '' And $([MSBuild]::VersionLessThan($(TargetFrameworkVersion), '6.0'))">copyused</TrimMode>

src/tools/illink/src/linker/Linker.Dataflow/MethodBodyScanner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ protected void AssignRefAndOutParameters (
11021102
for (int ilArgumentIndex = offset; ilArgumentIndex < methodArguments.Count; ilArgumentIndex++, parameterIndex++) {
11031103
if (calledMethod.ParameterReferenceKind (ilArgumentIndex) is not (ReferenceKind.Ref or ReferenceKind.Out))
11041104
continue;
1105-
SingleValue newByRefValue = methodIsResolved
1105+
SingleValue newByRefValue = methodIsResolved && parameterIndex < calledMethodDefinition!.Parameters.Count
11061106
? _context.Annotations.FlowAnnotations.GetMethodParameterValue (calledMethodDefinition!, parameterIndex)
11071107
: UnknownValue.Instance;
11081108
StoreInReference (methodArguments[ilArgumentIndex], newByRefValue, callingMethodBody.Method, operation, locals, curBasicBlock, ref ipState);

src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public static void Main ()
4343

4444
TestParameterOverwrite (typeof (TestType));
4545

46+
TestVarargsMethod (typeof (TestType), __arglist (0, 1, 2));
47+
4648
WriteCapturedParameter.Test ();
4749
}
4850

@@ -237,6 +239,10 @@ static void TestParameterOverwrite ([DynamicallyAccessedMembers (DynamicallyAcce
237239
type.GetFields ();
238240
}
239241

242+
static void TestVarargsMethod ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type type, __arglist)
243+
{
244+
}
245+
240246
class WriteCapturedParameter
241247
{
242248
[ExpectedWarning ("IL2072", nameof (GetUnknownType), "parameter")]

0 commit comments

Comments
 (0)