Skip to content

Commit

Permalink
[main] Update dependencies from mono/linker (#56593)
Browse files Browse the repository at this point in the history
* Update linker warning suppressions

dotnet/linker#2145 warns when accessing members
annotated with DynamicallyAccessedMembers using reflection, and
dotnet/linker#2162 updates the warning origin of
warnings for DynamicallyAccessedMembers on types.

This adds suppressions for the new warnings.

* Add windows-specific suppressions

* Update dependencies from https://github.com/mono/linker build 20210729.2

Microsoft.NET.ILLink.Tasks
 From Version 6.0.100-preview.6.21378.1 -> To Version 6.0.100-preview.6.21379.2

* Fix failures and address feedback

- Annotate mono's EnumBuilder and TypeBuilder
- Add (non-unique) readable short names to the warning codes

* Update dependencies from https://github.com/mono/linker build 20210730.2

Microsoft.NET.ILLink.Tasks
 From Version 6.0.100-preview.6.21378.1 -> To Version 6.0.100-preview.6.21380.2

* Suppress IL2111

* Update dependencies from https://github.com/mono/linker build 20210802.2

Microsoft.NET.ILLink.Tasks
 From Version 6.0.100-preview.6.21378.1 -> To Version 6.0.100-preview.6.21402.2

* Feedback

- Suppress IL2111 in trimming tests
- Remove unnecessary DynamicDependency
- Fix indentation

* Update readable warning names

Co-authored-by: Sven Boemer <sbomer@gmail.com>
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 3, 2021
1 parent a33ea98 commit a35aff7
Show file tree
Hide file tree
Showing 20 changed files with 159 additions and 37 deletions.
4 changes: 2 additions & 2 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>95863758cd16c345d0b8fca067d5db5d6901e498</Sha>
</Dependency>
<Dependency Name="Microsoft.NET.ILLink.Tasks" Version="6.0.100-preview.6.21378.1">
<Dependency Name="Microsoft.NET.ILLink.Tasks" Version="6.0.100-preview.6.21402.2">
<Uri>https://github.com/mono/linker</Uri>
<Sha>0cb9250a903cfc90cbac602ed79c0cbc588d8d3f</Sha>
<Sha>ae18468b8712503aee67911228dd921601bd423a</Sha>
</Dependency>
<Dependency Name="Microsoft.DotNet.XHarness.TestRunners.Xunit" Version="1.0.0-prerelease.21373.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 @@ -166,7 +166,7 @@
<!-- Docs -->
<MicrosoftPrivateIntellisenseVersion>5.0.0-preview-20201009.2</MicrosoftPrivateIntellisenseVersion>
<!-- ILLink -->
<MicrosoftNETILLinkTasksVersion>6.0.100-preview.6.21378.1</MicrosoftNETILLinkTasksVersion>
<MicrosoftNETILLinkTasksVersion>6.0.100-preview.6.21402.2</MicrosoftNETILLinkTasksVersion>
<MicrosoftNETILLinkAnalyzerPackageVersion>$(MicrosoftNETILLinkTasksVersion)</MicrosoftNETILLinkAnalyzerPackageVersion>
<!-- ICU -->
<MicrosoftNETCoreRuntimeICUTransportVersion>6.0.0-rc.1.21369.1</MicrosoftNETCoreRuntimeICUTransportVersion>
Expand Down
2 changes: 2 additions & 0 deletions eng/testing/linker/SupportFiles/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<!-- Suppress analyzer and linker warnings as these are tests -->
<EnableTrimAnalyzer>false</EnableTrimAnalyzer>
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>
<!-- Can be removed when SDK update picks up https://github.com/dotnet/sdk/pull/18655. -->
<NoWarn>$(NoWarn);IL2111</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions eng/testing/tests.mobile.targets
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<PublishTrimmed>true</PublishTrimmed>
<!-- Suppress linker warnings as these are tests -->
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>
<!-- Can be removed when SDK update picks up https://github.com/dotnet/sdk/pull/18655. -->
<NoWarn>$(NoWarn);IL2111</NoWarn>
<!-- https://github.com/dotnet/sdk/issues/18581 tracks needing to set 2 properties to disable warnings. -->
<EnableTrimAnalyzer>false</EnableTrimAnalyzer>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,10 @@ private sealed class LicenseClassFactory : IClassFactory2
private readonly LicenseInteropProxy _licenseProxy = new LicenseInteropProxy();
private readonly Guid _classId;

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicConstructors)]
private readonly Type _classType;

public LicenseClassFactory(Guid clsid, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type classType)
public LicenseClassFactory(Guid clsid, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicConstructors)] Type classType)
{
_classId = clsid;
_classType = classType;
Expand Down Expand Up @@ -627,6 +627,9 @@ internal sealed class LicenseInteropProxy
private object? _licContext;
private Type? _targetRcwType;

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:ReflectionToDynamicallyAccessedMembers",
Justification = "The type parameter to LicenseManager.CreateWithContext method has PublicConstructors annotation. We only invoke this method" +
"from AllocateAndValidateLicense which annotates the value passed in with the same annotation.")]
public LicenseInteropProxy()
{
Type licManager = Type.GetType("System.ComponentModel.LicenseManager, System.ComponentModel.TypeConverter", throwOnError: true)!;
Expand Down Expand Up @@ -742,7 +745,7 @@ public string RequestLicKey(Type type)
// If we are being entered because of a call to ICF::CreateInstanceLic(),
// "isDesignTime" will be "false" and "key" will point to a non-null
// license key.
public object AllocateAndValidateLicense(Type type, string? key, bool isDesignTime)
public object AllocateAndValidateLicense([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type, string? key, bool isDesignTime)
{
object?[] parameters;
object? licContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,8 @@ Namespace Microsoft.VisualBasic.CompilerServices

<UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification:=IDOBinder.SuppressionJustification)>
<UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:ReflectionToDynamicallyAccessedMembers",
Justification:=IDOBinder.SuppressionJustification)>
Public Overrides Function FallbackConvert(
ByVal target As DynamicMetaObject,
ByVal errorSuggestion As DynamicMetaObject) As DynamicMetaObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@

namespace System.Data.Common
{
// This coarse suppression silences all RequiresUnreferencedCode warnings in the class.
// https://github.com/mono/linker/issues/2136 tracks making it possible to add more granular suppressions at the member level, and with a different warning code.
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "The use of GetType preserves members with RequiresUnreferencedCode, but the GetType callsites either "
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113:ReflectionToRequiresUnreferencedCode",
Justification = "The use of GetType preserves ICustomTypeDescriptor members with RequiresUnreferencedCode, but the GetType callsites either "
+ "occur in RequiresUnreferencedCode scopes, or have individually justified suppressions.")]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
public class DbConnectionStringBuilder : IDictionary, ICustomTypeDescriptor
Expand Down Expand Up @@ -393,6 +391,9 @@ internal Attribute[] GetAttributesFromCollection(AttributeCollection collection)
return attributes;
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
Justification = "The use of GetType preserves this member with RequiresUnreferencedCode, but the GetType callsites either "
+ "occur in RequiresUnreferencedCode scopes, or have individually justified suppressions.")]
[RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered.")]
private PropertyDescriptorCollection GetProperties()
{
Expand All @@ -419,6 +420,9 @@ private PropertyDescriptorCollection GetProperties()
return propertyDescriptors;
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
Justification = "The use of GetType preserves this member with RequiresUnreferencedCode, but the GetType callsites either "
+ "occur in RequiresUnreferencedCode scopes, or have individually justified suppressions.")]
[RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered.")]
protected virtual void GetProperties(Hashtable propertyDescriptors)
{
Expand Down Expand Up @@ -526,6 +530,9 @@ protected virtual void GetProperties(Hashtable propertyDescriptors)
}
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
Justification = "The use of GetType preserves this member with RequiresUnreferencedCode, but the GetType callsites either "
+ "occur in RequiresUnreferencedCode scopes, or have individually justified suppressions.")]
[RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
private PropertyDescriptorCollection GetProperties(Attribute[]? attributes)
{
Expand Down
8 changes: 4 additions & 4 deletions src/libraries/System.Data.Common/src/System/Data/DataSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ namespace System.Data
[XmlSchemaProvider(nameof(GetDataSetSchema))]
[XmlRoot(nameof(DataSet))]
[System.Runtime.CompilerServices.TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
// This coarse suppression silences all RequiresUnreferencedCode warnings in the class.
// https://github.com/mono/linker/issues/2136 tracks making it possible to add more granular suppressions at the member level, and with a different warning code.
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "CreateInstanceOfThisType's use of GetType uses only the parameterless constructor, but the annotations preserve all non-public constructors causing a warning for the serialization constructors. Those constructors won't be used here.")]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors)] // needed by Clone() to preserve derived ctors
public class DataSet : MarshalByValueComponent, IListSource, IXmlSerializable, ISupportInitializeNotification, ISerializable
{
Expand Down Expand Up @@ -231,11 +227,15 @@ protected void GetSerializationData(SerializationInfo info, StreamingContext con

// Deserialize all the tables schema and data of the dataset from binary/xml stream.
[RequiresUnreferencedCode(RequiresUnreferencedCodeMessage)]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
Justification = "CreateInstanceOfThisType's use of GetType uses only the parameterless constructor, but the annotations preserve all non-public constructors causing a warning for the serialization constructors. Those constructors won't be used here.")]
protected DataSet(SerializationInfo info, StreamingContext context) : this(info, context, true)
{
}

[RequiresUnreferencedCode(RequiresUnreferencedCodeMessage)]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
Justification = "CreateInstanceOfThisType's use of GetType uses only the parameterless constructor, but the annotations preserve all non-public constructors causing a warning for the serialization constructors. Those constructors won't be used here.")]
protected DataSet(SerializationInfo info, StreamingContext context, bool ConstructSchema) : this()
{
SerializationFormat remotingFormat = SerializationFormat.Xml;
Expand Down
6 changes: 2 additions & 4 deletions src/libraries/System.Data.Common/src/System/Data/DataTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ namespace System.Data
[XmlSchemaProvider(nameof(GetDataTableSchema))]
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
// This coarse suppression silences all RequiresUnreferencedCode warnings in the class.
// https://github.com/mono/linker/issues/2136 tracks making it possible to add more granular suppressions at the member level, and with a different warning code.
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "CreateInstance's use of GetType uses only the parameterless constructor. Warnings are about serialization related constructors.")]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
public class DataTable : MarshalByValueComponent, IListSource, ISupportInitializeNotification, ISerializable, IXmlSerializable
{
Expand Down Expand Up @@ -196,6 +192,8 @@ public DataTable(string? tableName, string? tableNamespace) : this(tableName)
}

// Deserialize the table from binary/xml stream.
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
Justification = "CreateInstance's use of GetType uses only the parameterless constructor. Warnings are about serialization related constructors.")]
[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
protected DataTable(SerializationInfo info, StreamingContext context) : this()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,14 @@ internal static DataTable GetSchemaTableFromDataTable(DataTable table)
DataColumn ColumnSize = new DataColumn(SchemaTableColumn.ColumnSize, typeof(int));
DataColumn NumericPrecision = new DataColumn(SchemaTableColumn.NumericPrecision, typeof(short));
DataColumn NumericScale = new DataColumn(SchemaTableColumn.NumericScale, typeof(short));
DataColumn DataType = new DataColumn(SchemaTableColumn.DataType, typeof(Type));
DataColumn DataType = GetSystemTypeDataColumn();

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:ReflectionToDynamicallyAccessedMembers",
Justification = "The problem is Type.TypeInitializer which requires constructors on the Type instance." +
"In this case the TypeInitializer property is not accessed dynamically.")]
static DataColumn GetSystemTypeDataColumn() =>
new DataColumn(SchemaTableColumn.DataType, typeof(Type));

DataColumn ProviderType = new DataColumn(SchemaTableColumn.ProviderType, typeof(int));
DataColumn IsLong = new DataColumn(SchemaTableColumn.IsLong, typeof(bool));
DataColumn AllowDBNull = new DataColumn(SchemaTableColumn.AllowDBNull, typeof(bool));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ namespace System.Data
/// This is the generic base class for TypedDataSet
/// </summary>
[Serializable]
// This coarse suppression silences all RequiresUnreferencedCode warnings in the class.
// https://github.com/mono/linker/issues/2136 tracks making it possible to add more granular suppressions at the member level, and with a different warning code.
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "DataTable.CreateInstance's use of GetType uses only the parameterless constructor. Warnings are about serialization related constructors.")]
public abstract class TypedTableBase<T> : DataTable, IEnumerable<T> where T : DataRow
{

Expand All @@ -32,6 +28,8 @@ protected TypedTableBase() : base() { }
/// </summary>
/// <param name="info">SerializationInfo containing data to construct the object.</param>
/// <param name="context">The streaming context for the object being deserialized.</param>
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
Justification = "DataTable.CreateInstance's use of GetType uses only the parameterless constructor, not this serialization related constructor.")]
[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
protected TypedTableBase(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,10 @@
<property name="Scope">member</property>
<property name="Target">M:System.Data.OleDb.OleDbDataReader.GetFieldType(System.Int32)</property>
</attribute>
</assembly>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2111</argument>
<property name="Scope">member</property>
<property name="Target">M:System.Data.OleDb.OleDbDataReader.BuildSchemaTable(MetaData[])</property>
</attribute> </assembly>
</linker>
Loading

0 comments on commit a35aff7

Please sign in to comment.