Skip to content

Commit

Permalink
Update linker warning numbers (#40865)
Browse files Browse the repository at this point in the history
* Update linker warning numbers

In response to dotnet/linker#1385.
This replaces the global suppressions for IL2006 with the warnings that it was split into.

* Add suppressions for linker tests
  • Loading branch information
sbomer authored Aug 17, 2020
1 parent e756708 commit b61effa
Show file tree
Hide file tree
Showing 30 changed files with 80 additions and 56 deletions.
4 changes: 2 additions & 2 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>0375524a91a47ca4db3ee1be548f74bab7e26e76</Sha>
</Dependency>
<Dependency Name="Microsoft.NET.ILLink.Tasks" Version="5.0.0-preview.3.20412.1">
<Dependency Name="Microsoft.NET.ILLink.Tasks" Version="5.0.0-preview.3.20413.1">
<Uri>https://github.com/mono/linker</Uri>
<Sha>fc5e4aa86ad543ab3a730e0e0e8dacc6a379d4a5</Sha>
<Sha>2b04c065c84aa8f30600e3b1989c537fc77de95b</Sha>
</Dependency>
<Dependency Name="Microsoft.DotNet.XHarness.TestRunners.Xunit" Version="1.0.0-prerelease.20411.1">
<Uri>https://github.com/dotnet/xharness</Uri>
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
<!-- Docs -->
<MicrosoftPrivateIntellisenseVersion>3.0.0-preview-20200715.1</MicrosoftPrivateIntellisenseVersion>
<!-- ILLink -->
<MicrosoftNETILLinkTasksVersion>5.0.0-preview.3.20412.1</MicrosoftNETILLinkTasksVersion>
<MicrosoftNETILLinkTasksVersion>5.0.0-preview.3.20413.1</MicrosoftNETILLinkTasksVersion>
<!-- ICU -->
<MicrosoftNETCoreRuntimeICUTransportVersion>5.0.0-preview.8.20410.1</MicrosoftNETCoreRuntimeICUTransportVersion>
<!-- Mono LLVM -->
Expand Down
11 changes: 8 additions & 3 deletions eng/illink.targets
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,6 @@
<!-- keep DynamicDependencyAttribute unless a project explicitly disables it -->
<ILLinkArgs Condition="'$(ILLinkKeepDepAttributes)' != 'false'">$(ILLinkArgs) --keep-dep-attributes true</ILLinkArgs>
<!-- suppress warnings with the following codes:
IL2006: The generic parameter 'T' from A with dynamically accessed member kinds B is passed into the generic parameter
'T' from 'System.Lazy<T>' which requires dynamically accessed member kinds 'PublicParameterlessConstructor'
IL2008: Could not find type A specified in resource B
IL2009: Could not find method A in type B specified in resource C
IL2012: Could not find field A in type B specified in resource C
Expand All @@ -236,7 +234,14 @@
IL2050: P/invoke method A declares a parameter with COM marshalling. Correctness of COM interop
cannot be guaranteed after trimming. Interfaces and interface members might be removed.
-->
<ILLinkArgs>$(ILLinkArgs) --nowarn IL2006;IL2008;IL2009;IL2012;IL2025;IL2026;IL2035;IL2050</ILLinkArgs>
<LinkerNoWarn>IL2008;IL2009;IL2012;IL2025;IL2026;IL2035;IL2050</LinkerNoWarn>
<!-- IL2032,IL2055,IL2057-IL2061: Reflection intrinsics with unknown arguments -->
<LinkerNoWarn>$(LinkerNoWarn);IL2032;IL2055;IL2057;IL2058;IL2059;IL2060;IL2061</LinkerNoWarn>
<!-- IL2062-IL2066: Unknown values passed to locations with DynamicallyAccessedMemberTypes -->
<LinkerNoWarn>$(LinkerNoWarn);IL2062;IL2063;IL2064;IL2065;IL2066</LinkerNoWarn>
<!-- IL2067-IL2091: Unsatisfied DynamicallyAccessedMembers requirements -->
<LinkerNoWarn>$(LinkerNoWarn);IL2067;IL2068;IL2069;IL2070;IL2071;IL2072;IL2073;IL2074;IL2075;IL2076;IL2077;IL2078;IL2079;IL2080;IL2081;IL2082;IL2083;IL2084;IL2085;IL2086;IL2087;IL2088;IL2089;IL2090;IL2091</LinkerNoWarn>
<ILLinkArgs>$(ILLinkArgs) --nowarn $(LinkerNoWarn)</ILLinkArgs>
</PropertyGroup>

<MakeDir Directories="$(ILLinkTrimInputPath)" />
Expand Down
9 changes: 8 additions & 1 deletion eng/testing/linker/project.csproj.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
<RuntimePackDir>{RuntimePackDir}</RuntimePackDir>
<TargetingPackDir>{TargetingPackDir}</TargetingPackDir>

<LinkerNoWarn>IL2006;IL2026</LinkerNoWarn>
<!-- These can be removed once we get an SDK with https://github.com/mono/linker/pull/1385. -->
<LinkerNoWarn>IL2026</LinkerNoWarn>
<!-- IL2032,IL2055,IL2057-IL2061: Reflection intrinsics with unknown arguments -->
<LinkerNoWarn>$(LinkerNoWarn);IL2032;IL2055;IL2057;IL2058;IL2059;IL2060;IL2061</LinkerNoWarn>
<!-- IL2062-IL2066: Unknown values passed to locations with DynamicallyAccessedMemberTypes -->
<LinkerNoWarn>$(LinkerNoWarn);IL2062;IL2063;IL2064;IL2065;IL2066</LinkerNoWarn>
<!-- IL2067-IL2091: Unsatisfied DynamicallyAccessedMembers requirements -->
<LinkerNoWarn>$(LinkerNoWarn);IL2067;IL2068;IL2069;IL2070;IL2071;IL2072;IL2073;IL2074;IL2075;IL2076;IL2077;IL2078;IL2079;IL2080;IL2081;IL2082;IL2083;IL2084;IL2085;IL2086;IL2087;IL2088;IL2089;IL2090;IL2091</LinkerNoWarn>
<!-- https://github.com/dotnet/runtime/issues/40336 - need to suppress IL2008;IL2009;IL2037 on non-Windows -->
<LinkerNoWarn Condition="!$(RuntimeIdentifier.StartsWith('win'))">$(LinkerNoWarn);IL2008;IL2009;IL2037</LinkerNoWarn>
<_ExtraTrimmerArgs>{ExtraTrimmerArgs} $(_ExtraTrimmerArgs) --nowarn $(LinkerNoWarn)</_ExtraTrimmerArgs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static partial class Marshal
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern int SizeOfHelper(Type t, bool throwIfNotMarshalable);

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern",
Justification = "Trimming doesn't affect types eligible for marshalling. Different exception for invalid inputs doesn't matter.")]
public static IntPtr OffsetOf(Type t, string fieldName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3863,7 +3863,9 @@ private void CreateInstanceCheckThis()
throw new NotSupportedException(SR.Acc_CreateVoid);
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2082:UnrecognizedReflectionPattern",
Justification = "Implementation detail of Activator that linker intrinsically recognizes")]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2085:UnrecognizedReflectionPattern",
Justification = "Implementation detail of Activator that linker intrinsically recognizes")]
internal object? CreateInstanceImpl(
BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace System
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public abstract class ValueType
{
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern",
Justification = "Trimmed fields don't make a difference for equality")]
public override bool Equals(object? obj)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static bool TryGetDefaultValue(ParameterInfo parameter, out object? defau
defaultValue = CreateValueType(parameter.ParameterType);
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2067:UnrecognizedReflectionPattern",
Justification = "CreateInstance is only called on a ValueType, which will always have a default constructor.")]
object? CreateValueType(Type t) => Activator.CreateInstance(t);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ protected override Expression VisitDisposeCache(ServiceCallSite callSite, object
VisitCallSiteMain(callSite, context));
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2060:UnrecognizedReflectionPattern",
Justification = "Calling Array.Empty<T>() is safe since the T doesn't have linker annotations.")]
internal static MethodInfo GetArrayEmptyMethodInfo(Type itemType) =>
ArrayEmptyMethodInfo.MakeGenericMethod(itemType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ public static partial class Activator
throw new ArgumentException(SR.Arg_MustBeType, nameof(type));
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
Justification = "Implementation detail of Activator that linker intrinsically recognizes")]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "Implementation detail of Activator that linker intrinsically recognizes")]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2057:UnrecognizedReflectionPattern",
Justification = "Implementation detail of Activator that linker intrinsically recognizes")]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2072:UnrecognizedReflectionPattern",
Justification = "Implementation detail of Activator that linker intrinsically recognizes")]
private static ObjectHandle? CreateInstanceInternal(string assemblyString,
string typeName,
bool ignoreCase,
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/Attribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public abstract partial class Attribute
protected Attribute() { }

#if !CORERT
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern",
Justification = "Unused fields don't make a difference for equality")]
public override bool Equals(object? obj)
{
Expand Down Expand Up @@ -49,7 +49,7 @@ public override bool Equals(object? obj)
return true;
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern",
Justification = "Unused fields don't make a difference for hashcode quality")]
public override int GetHashCode()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ internal static bool MatchesExactly(this SignatureType pattern, Type actual)
return signatureType.TryResolve(genericMethod.GetGenericArguments());
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2055:UnrecognizedReflectionPattern",
Justification = "Used to find matching method overloads. Only used for assignability checks.")]
private static Type? TryResolve(this SignatureType signatureType, Type[] genericMethodParameters)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public virtual IEnumerable<MethodInfo> GetDeclaredMethods(string name)
yield return method;
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern",
Justification = "The yield return state machine doesn't propagate annotations")]
static MethodInfo[] GetDeclaredOnlyMethods(
Type type) => type.GetMethods(TypeInfo.DeclaredOnlyLookup);
Expand Down Expand Up @@ -85,7 +85,7 @@ public virtual IEnumerable<System.Reflection.TypeInfo> DeclaredNestedTypes
yield return t.GetTypeInfo();
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern",
Justification = "The yield return state machine doesn't propagate annotations")]
static Type[] GetDeclaredOnlyNestedTypes(
Type type) => type.GetNestedTypes(TypeInfo.DeclaredOnlyLookup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ internal static bool TrackAsyncMethodCompletion
/// <summary>Gets a description of the state of the state machine object, suitable for debug purposes.</summary>
/// <param name="stateMachine">The state machine object.</param>
/// <returns>A description of the state machine.</returns>
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern",
Justification = "It's okay if unused fields disappear from debug views")]
internal static string GetAsyncStateMachineDescription(IAsyncStateMachine stateMachine)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ public static void Prelink(MethodInfo m)
PrelinkCore(m);
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern",
Justification = "This only needs to prelink methods that are actually used")]
public static void PrelinkAll(Type c)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private Array GetEnumRawConstantValues()
return values;
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2085:UnrecognizedReflectionPattern",
Justification = "Literal fields on enums can never be trimmed")]
// This will return enumValues and enumNames sorted by the values.
private void GetEnumData(out string[] enumNames, out Array enumValues)
Expand Down
18 changes: 9 additions & 9 deletions src/libraries/System.Private.CoreLib/src/System/Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public ConstructorInfo? TypeInitializer
protected abstract ConstructorInfo? GetConstructorImpl(BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[] types, ParameterModifier[]? modifiers);

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2085:UnrecognizedReflectionPattern",
Justification = "Linker doesn't recognize GetConstructors(BindingFlags.Public) but this is what the body is doing")]
public ConstructorInfo[] GetConstructors() => GetConstructors(BindingFlags.Public | BindingFlags.Instance);

Expand All @@ -165,7 +165,7 @@ public ConstructorInfo? TypeInitializer
public abstract EventInfo? GetEvent(string name, BindingFlags bindingAttr);

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicEvents)]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2085:UnrecognizedReflectionPattern",
Justification = "Linker doesn't recognize GetEvents(BindingFlags.Public) but this is what the body is doing")]
public virtual EventInfo[] GetEvents() => GetEvents(Type.DefaultLookup);

Expand All @@ -179,7 +179,7 @@ public ConstructorInfo? TypeInitializer
public abstract FieldInfo? GetField(string name, BindingFlags bindingAttr);

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2085:UnrecognizedReflectionPattern",
Justification = "Linker doesn't recognize GetFields(BindingFlags.Public) but this is what the body is doing")]
public FieldInfo[] GetFields() => GetFields(Type.DefaultLookup);

Expand All @@ -193,7 +193,7 @@ public ConstructorInfo? TypeInitializer
| DynamicallyAccessedMemberTypes.PublicProperties
| DynamicallyAccessedMemberTypes.PublicConstructors
| DynamicallyAccessedMemberTypes.PublicNestedTypes)]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2085:UnrecognizedReflectionPattern",
Justification = "Linker doesn't recognize GetMember(BindingFlags.Public) but this is what the body is doing")]
public MemberInfo[] GetMember(string name) => GetMember(name, Type.DefaultLookup);

Expand Down Expand Up @@ -277,7 +277,7 @@ public ConstructorInfo? TypeInitializer
protected virtual MethodInfo? GetMethodImpl(string name, int genericParameterCount, BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[]? types, ParameterModifier[]? modifiers) => throw new NotSupportedException();

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2085:UnrecognizedReflectionPattern",
Justification = "Linker doesn't recognize GetMethods(BindingFlags.Public) but this is what the body is doing")]
public MethodInfo[] GetMethods() => GetMethods(Type.DefaultLookup);

Expand All @@ -291,7 +291,7 @@ public ConstructorInfo? TypeInitializer
public abstract Type? GetNestedType(string name, BindingFlags bindingAttr);

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicNestedTypes)]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2085:UnrecognizedReflectionPattern",
Justification = "Linker doesn't recognize GetNestedTypes(BindingFlags.Public) but this is what the body is doing")]
public Type[] GetNestedTypes() => GetNestedTypes(Type.DefaultLookup);

Expand All @@ -310,7 +310,7 @@ public ConstructorInfo? TypeInitializer
}

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2085:UnrecognizedReflectionPattern",
Justification = "Linker doesn't recognize GetPropertyImpl(BindingFlags.Public) but this is what the body is doing")]
public PropertyInfo? GetProperty(string name, Type? returnType)
{
Expand Down Expand Up @@ -342,7 +342,7 @@ public ConstructorInfo? TypeInitializer
protected abstract PropertyInfo? GetPropertyImpl(string name, BindingFlags bindingAttr, Binder? binder, Type? returnType, Type[]? types, ParameterModifier[]? modifiers);

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2085:UnrecognizedReflectionPattern",
Justification = "Linker doesn't recognize GetProperties(BindingFlags.Public) but this is what the body is doing")]
public PropertyInfo[] GetProperties() => GetProperties(Type.DefaultLookup);

Expand Down Expand Up @@ -431,7 +431,7 @@ protected virtual TypeCode GetTypeCodeImpl()
public virtual bool IsInstanceOfType([NotNullWhen(true)] object? o) => o == null ? false : IsAssignableFrom(o.GetType());
public virtual bool IsEquivalentTo([NotNullWhen(true)] Type? other) => this == other;

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2085:UnrecognizedReflectionPattern",
Justification = "The single instance field on enum types is never trimmed")]
public virtual Type GetEnumUnderlyingType()
{
Expand Down
Loading

0 comments on commit b61effa

Please sign in to comment.