From 4f9af86c9b0e2a645ba6e24ab3894f84992c1d14 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Thu, 29 Jul 2021 18:44:31 +0000 Subject: [PATCH 1/9] Update linker warning suppressions https://github.com/mono/linker/pull/2145 warns when accessing members annotated with DynamicallyAccessedMembers using reflection, and https://github.com/mono/linker/pull/2162 updates the warning origin of warnings for DynamicallyAccessedMembers on types. This adds suppressions for the new warnings. --- .../VisualBasic/CompilerServices/IDOBinder.vb | 4 +- .../Data/Common/DbConnectionStringBuilder.cs | 15 +++-- .../src/System/Data/DataSet.cs | 8 +-- .../src/System/Data/DataTable.cs | 6 +- .../src/System/Data/DataTableReader.cs | 11 +++- .../src/System/Data/TypedTableBase.cs | 6 +- .../DiagnosticSourceEventSource.cs | 32 ++++++++-- .../Linq/Expressions/Compiler/AssemblyGen.cs | 3 + .../System/Diagnostics/Tracing/EventSource.cs | 61 +++++++++++++++++-- .../TraceLogging/TraceLoggingEventSource.cs | 12 ++++ .../Serialization/PrimitiveDataContract.cs | 3 + 11 files changed, 131 insertions(+), 30 deletions(-) diff --git a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/IDOBinder.vb b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/IDOBinder.vb index 9644a77fd43df3..9d5c5b8fa521e4 100644 --- a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/IDOBinder.vb +++ b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/IDOBinder.vb @@ -822,7 +822,9 @@ Namespace Microsoft.VisualBasic.CompilerServices MyBase.New(t, True) End Sub - + Public Overrides Function FallbackConvert( ByVal target As DynamicMetaObject, diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs index 74feebf9a04936..e6e288602bf182 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs @@ -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", + 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 @@ -393,6 +391,9 @@ internal Attribute[] GetAttributesFromCollection(AttributeCollection collection) return attributes; } + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + 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() { @@ -419,6 +420,9 @@ private PropertyDescriptorCollection GetProperties() return propertyDescriptors; } + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + 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) { @@ -526,6 +530,9 @@ protected virtual void GetProperties(Hashtable propertyDescriptors) } } + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + 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) { diff --git a/src/libraries/System.Data.Common/src/System/Data/DataSet.cs b/src/libraries/System.Data.Common/src/System/Data/DataSet.cs index 962ba8131b8531..dbc676d06c50c0 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataSet.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataSet.cs @@ -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 { @@ -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", + 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", + 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; diff --git a/src/libraries/System.Data.Common/src/System/Data/DataTable.cs b/src/libraries/System.Data.Common/src/System/Data/DataTable.cs index ad9044bd4a9076..026d8edeb7ee30 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataTable.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataTable.cs @@ -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 { @@ -196,6 +192,8 @@ public DataTable(string? tableName, string? tableNamespace) : this(tableName) } // Deserialize the table from binary/xml stream. + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + 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() { diff --git a/src/libraries/System.Data.Common/src/System/Data/DataTableReader.cs b/src/libraries/System.Data.Common/src/System/Data/DataTableReader.cs index 2a14fa8f444764..997134b90b746d 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataTableReader.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataTableReader.cs @@ -737,7 +737,16 @@ 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", + Justification = "The problem is Type.TypeInitializer which requires constructors on the Type instance." + + "In this case the Type instance is about System.Type itself, so adding an explicit dependency on the same" + + "annotation here.")] + [DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors, typeof(Type))] + 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)); diff --git a/src/libraries/System.Data.Common/src/System/Data/TypedTableBase.cs b/src/libraries/System.Data.Common/src/System/Data/TypedTableBase.cs index 64fdf03878571a..96e80051ac8992 100644 --- a/src/libraries/System.Data.Common/src/System/Data/TypedTableBase.cs +++ b/src/libraries/System.Data.Common/src/System/Data/TypedTableBase.cs @@ -12,10 +12,6 @@ namespace System.Data /// This is the generic base class for TypedDataSet /// [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 : DataTable, IEnumerable where T : DataRow { @@ -32,6 +28,8 @@ protected TypedTableBase() : base() { } /// /// SerializationInfo containing data to construct the object. /// The streaming context for the object being deserialized. + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + 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) { } diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs index 31daa2a57eb5f9..9d695a10fbf1f4 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs @@ -160,12 +160,17 @@ namespace System.Diagnostics /// See the DiagnosticSourceEventSourceBridgeTest.cs for more explicit examples of using this bridge. /// [EventSource(Name = "Microsoft-Diagnostics-DiagnosticSource")] - // 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 = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves all members, so " + - "those that are marked with RequiresUnreferencedCode will warn. " + - "This method will not access any of these members and is safe to call.")] + // These suppressions can go away with https://github.com/mono/linker/issues/2175 + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113", + Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves methods on Delegate and MulticastDelegate " + + "because the nested type OverrideEventProvider's base type EventProvider defines a delegate. " + + "This includes Delegate and MulticastDelegate methods which require unreferenced code, but " + + "EnsureDescriptorsInitialized does not access these members and is safe to call.")] + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2115", + Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves methods on Delegate and MulticastDelegate " + + "because the nested type OverrideEventProvider's base type EventProvider defines a delegate. " + + "This includes Delegate and MulticastDelegate methods which have dynamically accessed members requirements, but " + + "EnsureDescriptorsInitialized does not access these members and is safe to call.")] internal sealed class DiagnosticSourceEventSource : EventSource { public static DiagnosticSourceEventSource Log = new DiagnosticSourceEventSource(); @@ -1019,6 +1024,9 @@ private void Dispose() } } + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which " + + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(DiagnosticSource.WriteRequiresUnreferencedCode)] public List> Morph(object? args) { @@ -1100,6 +1108,9 @@ private void Dispose() // Given a type generate all the implicit transforms for type (that is for every field // generate the spec that fetches it). + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which " + + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(DiagnosticSource.WriteRequiresUnreferencedCode)] private static TransformSpec? MakeImplicitTransforms(Type type) { @@ -1195,6 +1206,9 @@ public TransformSpec(string transformSpec, int startIdx, int endIdx, TransformSp /// if the spec is OUTSTR=EVENT_VALUE.PROP1.PROP2.PROP3 and the ultimate value of PROP3 is /// 10 then the return key value pair is KeyValuePair("OUTSTR","10") /// + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which " + + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(DiagnosticSource.WriteRequiresUnreferencedCode)] public KeyValuePair Morph(object? obj) { @@ -1246,6 +1260,9 @@ public PropertySpec(string propertyName, PropertySpec? next) /// Given an object fetch the property that this PropertySpec represents. /// obj may be null when IsStatic is true, otherwise it must be non-null. /// + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which " + + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(DiagnosticSource.WriteRequiresUnreferencedCode)] public object? Fetch(object? obj) { @@ -1289,6 +1306,9 @@ public PropertyFetch(Type? type) /// /// Create a property fetcher for a propertyName /// + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which " + + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(DiagnosticSource.WriteRequiresUnreferencedCode)] public static PropertyFetch FetcherForProperty(Type? type, string propertyName) { diff --git a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/AssemblyGen.cs b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/AssemblyGen.cs index bd6cfe7144b59b..e23af6d8853418 100644 --- a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/AssemblyGen.cs +++ b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/AssemblyGen.cs @@ -60,6 +60,9 @@ private TypeBuilder DefineType(string name, [DynamicallyAccessedMembers(Dynamica [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "MulticastDelegate has a ctor with RequiresUnreferencedCode, but the generated derived type doesn't reference this ctor, so this is trim compatible.")] + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111", + Justification = "MulticastDelegate and Delegate have multiple methods with DynamicallyAccessedMembers annotations. But the generated code" + + "in this case will not call any of them (it only defines a .ctor and Invoke method both of which are runtime implemented.")] internal static TypeBuilder DefineDelegateType(string name) { return Assembly.DefineType( diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs index 556e4e8df58fe2..d3f4efbfabcb0b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs @@ -233,12 +233,16 @@ internal sealed class EventSourceAutoGenerateAttribute : Attribute // The EnsureDescriptorsInitialized() method might need to access EventSource and its derived type // members and the trimmer ensures that these members are preserved. [DynamicallyAccessedMembers(ManifestMemberTypes)] - // 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 = "EnsureDescriptorsInitialized's use of GetType preserves all members, so " + - "those that are marked with RequiresUnreferencedCode will warn. " + - "This method will not access any of these members and is safe to call.")] + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113", + Justification = "EnsureDescriptorsInitialized's use of GetType preserves methods on Delegate and MulticastDelegate " + + "because the nested type OverrideEventProvider's base type EventProvider defines a delegate. " + + "This includes Delegate and MulticastDelegate methods which require unreferenced code, but " + + "EnsureDescriptorsInitialized does not access these members and is safe to call.")] + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2115", + Justification = "EnsureDescriptorsInitialized's use of GetType preserves methods on Delegate and MulticastDelegate " + + "because the nested type OverrideEventProvider's base type EventProvider defines a delegate. " + + "This includes Delegate and MulticastDelegate methods which have dynamically accessed members requirements, but " + + "EnsureDescriptorsInitialized does not access these members and is safe to call.")] #endif public partial class EventSource : IDisposable { @@ -367,6 +371,12 @@ public static string GetName(Type eventSourceType) /// The manifest XML fragment contains the string name of the DLL name in /// which it is embedded. This parameter specifies what name will be used /// The XML data string +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114", + Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + + "has dynamically accessed members requirements, but EnsureDescriptorsInitialized does not "+ + "access this member and is safe to call.")] +#endif public static string? GenerateManifest( #if !ES_BUILD_STANDALONE [DynamicallyAccessedMembers(ManifestMemberTypes)] @@ -388,6 +398,12 @@ public static string GetName(Type eventSourceType) /// The flags to customize manifest generation. If flags has bit OnlyIfNeededForRegistration specified /// this returns null when the eventSourceType does not require explicit registration /// The XML data string or null +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114", + Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + + "has dynamically accessed members requirements, but EnsureDescriptorsInitialized does not "+ + "access this member and is safe to call.")] +#endif public static string? GenerateManifest( #if !ES_BUILD_STANDALONE [DynamicallyAccessedMembers(ManifestMemberTypes)] @@ -1269,6 +1285,9 @@ internal unsafe void SetMetadata(byte* pointer, int size, int reserved) /// /// #if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] #endif [CLSCompliant(false)] @@ -1303,6 +1322,9 @@ protected unsafe void WriteEventCore(int eventId, int eventDataCount, EventSourc /// /// #if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] #endif [CLSCompliant(false)] @@ -1398,6 +1420,9 @@ protected unsafe void WriteEventWithRelatedActivityIdCore(int eventId, Guid* rel /// check so that the varargs call is not made when the EventSource is not active. /// #if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] #endif protected unsafe void WriteEvent(int eventId, params object?[] args) @@ -1414,6 +1439,9 @@ protected unsafe void WriteEvent(int eventId, params object?[] args) /// check so that the varargs call is not made when the EventSource is not active. /// #if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] #endif protected unsafe void WriteEventWithRelatedActivityId(int eventId, Guid relatedActivityId, params object?[] args) @@ -1894,6 +1922,9 @@ private static unsafe void AssertValidString(EventData* data) } #if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] #endif private unsafe void WriteEventVarargs(int eventId, Guid* childActivityID, object?[] args) @@ -2006,6 +2037,9 @@ private unsafe void WriteEventVarargs(int eventId, Guid* childActivityID, object } #if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] #endif private unsafe object?[] SerializeEventArgs(int eventId, object?[] args) @@ -2465,6 +2499,9 @@ internal partial struct EventMetadata public TraceLoggingEventTypes TraceLoggingEventTypes { #if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] #endif get @@ -2952,6 +2989,12 @@ internal static bool IsCustomAttributeDefinedHelper( // Helper to deal with the fact that the type we are reflecting over might be loaded in the ReflectionOnly context. // When that is the case, we have the build the custom assemblies on a member by hand. +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114", + Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + + "has dynamically accessed members requirements, but EnsureDescriptorsInitialized does not "+ + "access this member and is safe to call.")] +#endif internal static Attribute? GetCustomAttributeHelper( MemberInfo member, #if !ES_BUILD_STANDALONE @@ -3073,6 +3116,12 @@ private static bool AttributeTypeNamesMatch(Type attributeType, Type reflectedAt // return the UTF8 bytes. It also sets up the code:EventData structures needed to dispatch events // at run time. 'source' is the event source to place the descriptors. If it is null, // then the descriptors are not created, and just the manifest is generated. +#if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114", + Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + + "has dynamically accessed members requirements, but its use of this method satisfies " + + "these requirements because it passes in the result of GetType with the same annotations.")] +#endif private static byte[]? CreateManifestAndDescriptors( #if !ES_BUILD_STANDALONE [DynamicallyAccessedMembers(ManifestMemberTypes)] diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs index c51d731e0c61e8..8d2238ebb81960 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs @@ -163,6 +163,9 @@ public unsafe void Write(string? eventName, EventSourceOptions options) /// create the fields of the event. /// #if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] public unsafe void Write<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>( #else @@ -204,6 +207,9 @@ public unsafe void Write( /// create the fields of the event. /// #if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] public unsafe void Write<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>( #else @@ -247,6 +253,9 @@ public unsafe void Write( /// create the fields of the event. /// #if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] public unsafe void Write<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>( #else @@ -297,6 +306,9 @@ public unsafe void Write( /// create the fields of the event. /// #if !ES_BUILD_STANDALONE + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] public unsafe void Write<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>( #else diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/PrimitiveDataContract.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/PrimitiveDataContract.cs index 8793954253a002..51dcd1f89c9a0d 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/PrimitiveDataContract.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/PrimitiveDataContract.cs @@ -346,6 +346,9 @@ internal sealed class NullPrimitiveDataContract : PrimitiveDataContract [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "This warns because the call to Base has the type annotated with DynamicallyAccessedMembers so it warns" + "when looking into the methods of NullPrimitiveDataContract. Because this just represents null, we suppress.")] + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111", + Justification = "This warns because the call to Base has the type annotated with DynamicallyAccessedMembers so it warns" + + "when looking into the methods of NullPrimitiveDataContract. Because this just represents null, we suppress.")] public NullPrimitiveDataContract() : base(typeof(NullPrimitiveDataContract), DictionaryGlobals.EmptyString, DictionaryGlobals.EmptyString) { From 890bcb7ca5ad771df363150ca55e03ed340973cb Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Thu, 29 Jul 2021 13:23:06 -0700 Subject: [PATCH 2/9] Add windows-specific suppressions --- .../src/Internal/Runtime/InteropServices/ComActivator.cs | 9 ++++++--- .../System.Data.OleDb/src/ILLink/ILLink.Suppressions.xml | 7 ++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs index b8e21637d48510..31f09e7444b850 100644 --- a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs +++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs @@ -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; @@ -627,6 +627,9 @@ internal sealed class LicenseInteropProxy private object? _licContext; private Type? _targetRcwType; + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111", + 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)!; @@ -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; diff --git a/src/libraries/System.Data.OleDb/src/ILLink/ILLink.Suppressions.xml b/src/libraries/System.Data.OleDb/src/ILLink/ILLink.Suppressions.xml index 63d7bd6ef89fd9..d54caa4452859d 100644 --- a/src/libraries/System.Data.OleDb/src/ILLink/ILLink.Suppressions.xml +++ b/src/libraries/System.Data.OleDb/src/ILLink/ILLink.Suppressions.xml @@ -97,5 +97,10 @@ member M:System.Data.OleDb.OleDbDataReader.GetFieldType(System.Int32) - + + ILLink + IL2111 + member + M:System.Data.OleDb.OleDbDataReader.BuildSchemaTable(MetaData[]) + \ No newline at end of file From 43f29d7173b14a1f4ab1d42b7c60d8ccfcdd1354 Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" Date: Fri, 30 Jul 2021 00:21:10 +0000 Subject: [PATCH 3/9] 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 --- eng/Version.Details.xml | 4 ++-- eng/Versions.props | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 06065b062a6444..60e9b6fcaa672a 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -186,9 +186,9 @@ https://github.com/dotnet/runtime f7e4c261815c66fde2c1e750b744f193e236c17e - + https://github.com/mono/linker - 0cb9250a903cfc90cbac602ed79c0cbc588d8d3f + aec70d0ae5a5d304176bb9831f5ffdb6e13d3568 https://github.com/dotnet/xharness diff --git a/eng/Versions.props b/eng/Versions.props index 55b4a8cd92b07e..713ae1bb90ed02 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -166,7 +166,7 @@ 5.0.0-preview-20201009.2 - 6.0.100-preview.6.21378.1 + 6.0.100-preview.6.21379.2 $(MicrosoftNETILLinkTasksVersion) 6.0.0-rc.1.21369.1 From 06b421bc64452e23939cde8b5f733af3e9d5f8c9 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Fri, 30 Jul 2021 20:07:26 +0000 Subject: [PATCH 4/9] Fix failures and address feedback - Annotate mono's EnumBuilder and TypeBuilder - Add (non-unique) readable short names to the warning codes --- .../Runtime/InteropServices/ComActivator.cs | 2 +- .../VisualBasic/CompilerServices/IDOBinder.vb | 4 +-- .../Data/Common/DbConnectionStringBuilder.cs | 8 +++--- .../src/System/Data/DataSet.cs | 4 +-- .../src/System/Data/DataTable.cs | 2 +- .../src/System/Data/DataTableReader.cs | 2 +- .../src/System/Data/TypedTableBase.cs | 2 +- .../DiagnosticSourceEventSource.cs | 14 +++++----- .../TrimmingTests/EventSourceManifestTest.cs | 5 ++++ .../Linq/Expressions/Compiler/AssemblyGen.cs | 2 +- .../System/Diagnostics/Tracing/EventSource.cs | 26 +++++++++---------- .../TraceLogging/TraceLoggingEventSource.cs | 8 +++--- .../Serialization/PrimitiveDataContract.cs | 8 +++--- .../Reflection/Emit/EnumBuilder.Mono.cs | 4 +++ .../Reflection/Emit/TypeBuilder.Mono.cs | 4 +++ 15 files changed, 55 insertions(+), 40 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs index 31f09e7444b850..935825523c3e8c 100644 --- a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs +++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs @@ -627,7 +627,7 @@ internal sealed class LicenseInteropProxy private object? _licContext; private Type? _targetRcwType; - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:RequiresDynamicallyAccessedMembers", 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() diff --git a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/IDOBinder.vb b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/IDOBinder.vb index 9d5c5b8fa521e4..e1bf61c780a1a3 100644 --- a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/IDOBinder.vb +++ b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/IDOBinder.vb @@ -822,9 +822,9 @@ Namespace Microsoft.VisualBasic.CompilerServices MyBase.New(t, True) End Sub - - Public Overrides Function FallbackConvert( ByVal target As DynamicMetaObject, diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs index e6e288602bf182..14b3a3f4775e16 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs @@ -12,7 +12,7 @@ namespace System.Data.Common { - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113:RequiresUnreferencedCode", 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)] @@ -391,7 +391,7 @@ internal Attribute[] GetAttributesFromCollection(AttributeCollection collection) return attributes; } - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", 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.")] @@ -420,7 +420,7 @@ private PropertyDescriptorCollection GetProperties() return propertyDescriptors; } - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", 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.")] @@ -530,7 +530,7 @@ protected virtual void GetProperties(Hashtable propertyDescriptors) } } - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", 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.")] diff --git a/src/libraries/System.Data.Common/src/System/Data/DataSet.cs b/src/libraries/System.Data.Common/src/System/Data/DataSet.cs index dbc676d06c50c0..622c082b16af5d 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataSet.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataSet.cs @@ -227,14 +227,14 @@ 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", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112: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.")] protected DataSet(SerializationInfo info, StreamingContext context) : this(info, context, true) { } [RequiresUnreferencedCode(RequiresUnreferencedCodeMessage)] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112: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.")] protected DataSet(SerializationInfo info, StreamingContext context, bool ConstructSchema) : this() { diff --git a/src/libraries/System.Data.Common/src/System/Data/DataTable.cs b/src/libraries/System.Data.Common/src/System/Data/DataTable.cs index 026d8edeb7ee30..0e4535f2e36725 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataTable.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataTable.cs @@ -192,7 +192,7 @@ public DataTable(string? tableName, string? tableNamespace) : this(tableName) } // Deserialize the table from binary/xml stream. - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", 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() diff --git a/src/libraries/System.Data.Common/src/System/Data/DataTableReader.cs b/src/libraries/System.Data.Common/src/System/Data/DataTableReader.cs index 997134b90b746d..bb7eb7b2340863 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataTableReader.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataTableReader.cs @@ -739,7 +739,7 @@ internal static DataTable GetSchemaTableFromDataTable(DataTable table) DataColumn NumericScale = new DataColumn(SchemaTableColumn.NumericScale, typeof(short)); DataColumn DataType = GetSystemTypeDataColumn(); - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:RequiresDynamicallyAccessedMembers", Justification = "The problem is Type.TypeInitializer which requires constructors on the Type instance." + "In this case the Type instance is about System.Type itself, so adding an explicit dependency on the same" + "annotation here.")] diff --git a/src/libraries/System.Data.Common/src/System/Data/TypedTableBase.cs b/src/libraries/System.Data.Common/src/System/Data/TypedTableBase.cs index 96e80051ac8992..6820a0b7aeddbe 100644 --- a/src/libraries/System.Data.Common/src/System/Data/TypedTableBase.cs +++ b/src/libraries/System.Data.Common/src/System/Data/TypedTableBase.cs @@ -28,7 +28,7 @@ protected TypedTableBase() : base() { } /// /// SerializationInfo containing data to construct the object. /// The streaming context for the object being deserialized. - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", 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) diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs index 9d695a10fbf1f4..4fabe826e21878 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs @@ -161,12 +161,12 @@ namespace System.Diagnostics /// [EventSource(Name = "Microsoft-Diagnostics-DiagnosticSource")] // These suppressions can go away with https://github.com/mono/linker/issues/2175 - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113:RequiresUnreferencedCode", Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves methods on Delegate and MulticastDelegate " + "because the nested type OverrideEventProvider's base type EventProvider defines a delegate. " + "This includes Delegate and MulticastDelegate methods which require unreferenced code, but " + "EnsureDescriptorsInitialized does not access these members and is safe to call.")] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2115", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2115:RequiresDynamicallyAccessedMembers", Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves methods on Delegate and MulticastDelegate " + "because the nested type OverrideEventProvider's base type EventProvider defines a delegate. " + "This includes Delegate and MulticastDelegate methods which have dynamically accessed members requirements, but " + @@ -1024,7 +1024,7 @@ private void Dispose() } } - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(DiagnosticSource.WriteRequiresUnreferencedCode)] @@ -1108,7 +1108,7 @@ private void Dispose() // Given a type generate all the implicit transforms for type (that is for every field // generate the spec that fetches it). - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(DiagnosticSource.WriteRequiresUnreferencedCode)] @@ -1206,7 +1206,7 @@ public TransformSpec(string transformSpec, int startIdx, int endIdx, TransformSp /// if the spec is OUTSTR=EVENT_VALUE.PROP1.PROP2.PROP3 and the ultimate value of PROP3 is /// 10 then the return key value pair is KeyValuePair("OUTSTR","10") /// - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(DiagnosticSource.WriteRequiresUnreferencedCode)] @@ -1260,7 +1260,7 @@ public PropertySpec(string propertyName, PropertySpec? next) /// Given an object fetch the property that this PropertySpec represents. /// obj may be null when IsStatic is true, otherwise it must be non-null. /// - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(DiagnosticSource.WriteRequiresUnreferencedCode)] @@ -1306,7 +1306,7 @@ public PropertyFetch(Type? type) /// /// Create a property fetcher for a propertyName /// - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(DiagnosticSource.WriteRequiresUnreferencedCode)] diff --git a/src/libraries/System.Diagnostics.Tracing/tests/TrimmingTests/EventSourceManifestTest.cs b/src/libraries/System.Diagnostics.Tracing/tests/TrimmingTests/EventSourceManifestTest.cs index 91929da00c0463..c6b0372f6e4a83 100644 --- a/src/libraries/System.Diagnostics.Tracing/tests/TrimmingTests/EventSourceManifestTest.cs +++ b/src/libraries/System.Diagnostics.Tracing/tests/TrimmingTests/EventSourceManifestTest.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Tracing; using System.Linq; using System; @@ -34,6 +35,10 @@ void EventSourceTest_Method_4(){} int EventSourceTest_Method_7() => 5; } + [UnconditionalSuppressMessage ("TrimAnalysis", "IL2111:RequiresDynamicallyAccessedMembers", + Justification = "GenerateManifest requires all members of EventSourceTest, including members of the base type " + + "EventSource which are annotated with DynamicallyAccessedMembersAttribute. " + + "GenerateManifest does not access these members and is safe to call.")] public static int Main() { string manifest = EventSource.GenerateManifest(typeof(EventSourceTest), null); diff --git a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/AssemblyGen.cs b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/AssemblyGen.cs index e23af6d8853418..2236829aa59a69 100644 --- a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/AssemblyGen.cs +++ b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/AssemblyGen.cs @@ -60,7 +60,7 @@ private TypeBuilder DefineType(string name, [DynamicallyAccessedMembers(Dynamica [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "MulticastDelegate has a ctor with RequiresUnreferencedCode, but the generated derived type doesn't reference this ctor, so this is trim compatible.")] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:RequiresDynamicallyAccessedMembers", Justification = "MulticastDelegate and Delegate have multiple methods with DynamicallyAccessedMembers annotations. But the generated code" + "in this case will not call any of them (it only defines a .ctor and Invoke method both of which are runtime implemented.")] internal static TypeBuilder DefineDelegateType(string name) diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs index eed90a7a42a218..184d3f5c16e32b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs @@ -233,12 +233,12 @@ internal sealed class EventSourceAutoGenerateAttribute : Attribute // The EnsureDescriptorsInitialized() method might need to access EventSource and its derived type // members and the trimmer ensures that these members are preserved. [DynamicallyAccessedMembers(ManifestMemberTypes)] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113:RequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves methods on Delegate and MulticastDelegate " + "because the nested type OverrideEventProvider's base type EventProvider defines a delegate. " + "This includes Delegate and MulticastDelegate methods which require unreferenced code, but " + "EnsureDescriptorsInitialized does not access these members and is safe to call.")] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2115", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2115:RequiresDynamicallyAccessedMembers", Justification = "EnsureDescriptorsInitialized's use of GetType preserves methods on Delegate and MulticastDelegate " + "because the nested type OverrideEventProvider's base type EventProvider defines a delegate. " + "This includes Delegate and MulticastDelegate methods which have dynamically accessed members requirements, but " + @@ -372,7 +372,7 @@ public static string GetName(Type eventSourceType) /// which it is embedded. This parameter specifies what name will be used /// The XML data string #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114:RequiresDynamicallyAccessedMembers", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "has dynamically accessed members requirements, but EnsureDescriptorsInitialized does not "+ "access this member and is safe to call.")] @@ -399,7 +399,7 @@ public static string GetName(Type eventSourceType) /// this returns null when the eventSourceType does not require explicit registration /// The XML data string or null #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114:RequiresDynamicallyAccessedMembers", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "has dynamically accessed members requirements, but EnsureDescriptorsInitialized does not "+ "access this member and is safe to call.")] @@ -1285,7 +1285,7 @@ internal unsafe void SetMetadata(byte* pointer, int size, int reserved) /// /// #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] @@ -1322,7 +1322,7 @@ protected unsafe void WriteEventCore(int eventId, int eventDataCount, EventSourc /// /// #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] @@ -1420,7 +1420,7 @@ protected unsafe void WriteEventWithRelatedActivityIdCore(int eventId, Guid* rel /// check so that the varargs call is not made when the EventSource is not active. /// #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] @@ -1439,7 +1439,7 @@ protected unsafe void WriteEvent(int eventId, params object?[] args) /// check so that the varargs call is not made when the EventSource is not active. /// #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] @@ -1926,7 +1926,7 @@ private static unsafe void AssertValidString(EventData* data) } #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] @@ -2041,7 +2041,7 @@ private unsafe void WriteEventVarargs(int eventId, Guid* childActivityID, object } #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] @@ -2503,7 +2503,7 @@ internal partial struct EventMetadata public TraceLoggingEventTypes TraceLoggingEventTypes { #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] @@ -2994,7 +2994,7 @@ internal static bool IsCustomAttributeDefinedHelper( // Helper to deal with the fact that the type we are reflecting over might be loaded in the ReflectionOnly context. // When that is the case, we have the build the custom assemblies on a member by hand. #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114:RequiresDynamicallyAccessedMembers", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "has dynamically accessed members requirements, but EnsureDescriptorsInitialized does not "+ "access this member and is safe to call.")] @@ -3121,7 +3121,7 @@ private static bool AttributeTypeNamesMatch(Type attributeType, Type reflectedAt // at run time. 'source' is the event source to place the descriptors. If it is null, // then the descriptors are not created, and just the manifest is generated. #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114:RequiresDynamicallyAccessedMembers", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "has dynamically accessed members requirements, but its use of this method satisfies " + "these requirements because it passes in the result of GetType with the same annotations.")] diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs index 8d2238ebb81960..f56b86279142cf 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs @@ -163,7 +163,7 @@ public unsafe void Write(string? eventName, EventSourceOptions options) /// create the fields of the event. /// #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] @@ -207,7 +207,7 @@ public unsafe void Write( /// create the fields of the event. /// #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] @@ -253,7 +253,7 @@ public unsafe void Write( /// create the fields of the event. /// #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] @@ -306,7 +306,7 @@ public unsafe void Write( /// create the fields of the event. /// #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/PrimitiveDataContract.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/PrimitiveDataContract.cs index 51dcd1f89c9a0d..82318056a51bcb 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/PrimitiveDataContract.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/PrimitiveDataContract.cs @@ -345,10 +345,12 @@ internal sealed class NullPrimitiveDataContract : PrimitiveDataContract { [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "This warns because the call to Base has the type annotated with DynamicallyAccessedMembers so it warns" + - "when looking into the methods of NullPrimitiveDataContract. Because this just represents null, we suppress.")] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111", + "when looking into the methods of NullPrimitiveDataContract which are annotated with RequiresUnreferencedCodeAttribute. " + + "Because this just represents null, we suppress.")] + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:RequiresDynamicallyAccessedMembers", Justification = "This warns because the call to Base has the type annotated with DynamicallyAccessedMembers so it warns" + - "when looking into the methods of NullPrimitiveDataContract. Because this just represents null, we suppress.")] + "when looking into the methods of NullPrimitiveDataContract which are annotated with DynamicallyAccessedMembersAttribute. " + + "Because this just represents null, we suppress.")] public NullPrimitiveDataContract() : base(typeof(NullPrimitiveDataContract), DictionaryGlobals.EmptyString, DictionaryGlobals.EmptyString) { diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs index 39acd0deb5a9f1..627ff751fa01a3 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs @@ -209,6 +209,10 @@ public override Type GetEnumUnderlyingType() return _underlyingType; } + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2110:RequiresDynamicallyAccessedMembers", + Justification = "For instance member internal calls, the linker preserves all fields of the declaring type. " + + "The _tb field has DynamicallyAccessedMembersAttribute requirements, but the field access is safe because " + + "Reflection.Emit is not subject to trimming.")] [MethodImplAttribute(MethodImplOptions.InternalCall)] private extern void setup_enum_type(Type t); diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs index 26bca9f69f234c..1769f34b384102 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs @@ -752,6 +752,10 @@ public ConstructorBuilder DefineTypeInitializer() null); } + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2110:RequiresDynamicallyAccessedMembers", + Justification = "For instance member internal calls, the linker preserves all fields of the declaring type. " + + "The parent and created fields have DynamicallyAccessedMembersAttribute requirements, but creating the runtime class is safe " + + "because the annotations fully preserve the parent type, and the type created via Reflection.Emit is not subject to trimming.")] [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] [MethodImplAttribute(MethodImplOptions.InternalCall)] private extern TypeInfo create_runtime_class(); From a53d3d6157ffcd35f4a5b934d4e13a4250dd365f Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" Date: Sat, 31 Jul 2021 12:11:39 +0000 Subject: [PATCH 5/9] 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 --- eng/Version.Details.xml | 4 ++-- eng/Versions.props | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 60e9b6fcaa672a..07a7629bccd027 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -186,9 +186,9 @@ https://github.com/dotnet/runtime f7e4c261815c66fde2c1e750b744f193e236c17e - + https://github.com/mono/linker - aec70d0ae5a5d304176bb9831f5ffdb6e13d3568 + facfa57f355bfd0a8473f9572c561b9e84c5befe https://github.com/dotnet/xharness diff --git a/eng/Versions.props b/eng/Versions.props index 713ae1bb90ed02..1900399d10855c 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -166,7 +166,7 @@ 5.0.0-preview-20201009.2 - 6.0.100-preview.6.21379.2 + 6.0.100-preview.6.21380.2 $(MicrosoftNETILLinkTasksVersion) 6.0.0-rc.1.21369.1 From c3534684025245c091ab3e4247d6497e9e40b6be Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Mon, 2 Aug 2021 22:14:48 +0000 Subject: [PATCH 6/9] Suppress IL2111 --- eng/testing/tests.mobile.targets | 2 ++ 1 file changed, 2 insertions(+) diff --git a/eng/testing/tests.mobile.targets b/eng/testing/tests.mobile.targets index 6c01e8c8967420..3beee87d760495 100644 --- a/eng/testing/tests.mobile.targets +++ b/eng/testing/tests.mobile.targets @@ -17,6 +17,8 @@ true true + + $(NoWarn);IL2111 false From 1a111df5be0775eabfd062a646d15cc8679cf90a Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" Date: Tue, 3 Aug 2021 12:13:25 +0000 Subject: [PATCH 7/9] 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 --- eng/Version.Details.xml | 4 ++-- eng/Versions.props | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 07a7629bccd027..e23fafac09bb03 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -186,9 +186,9 @@ https://github.com/dotnet/runtime f7e4c261815c66fde2c1e750b744f193e236c17e - + https://github.com/mono/linker - facfa57f355bfd0a8473f9572c561b9e84c5befe + ae18468b8712503aee67911228dd921601bd423a https://github.com/dotnet/xharness diff --git a/eng/Versions.props b/eng/Versions.props index 1900399d10855c..84011548e924c9 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -166,7 +166,7 @@ 5.0.0-preview-20201009.2 - 6.0.100-preview.6.21380.2 + 6.0.100-preview.6.21402.2 $(MicrosoftNETILLinkTasksVersion) 6.0.0-rc.1.21369.1 From 03dc002dce7d9a90a780f94b4dcb826c53e7f581 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Tue, 3 Aug 2021 17:36:42 +0000 Subject: [PATCH 8/9] Feedback - Suppress IL2111 in trimming tests - Remove unnecessary DynamicDependency - Fix indentation --- .../linker/SupportFiles/Directory.Build.props | 2 ++ .../src/System/Data/DataTableReader.cs | 4 +--- .../TrimmingTests/EventSourceManifestTest.cs | 4 ---- .../System/Diagnostics/Tracing/EventSource.cs | 20 +++++++++---------- .../Reflection/Emit/EnumBuilder.Mono.cs | 2 +- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/eng/testing/linker/SupportFiles/Directory.Build.props b/eng/testing/linker/SupportFiles/Directory.Build.props index 760ff6d86e8102..458994a1822ebd 100644 --- a/eng/testing/linker/SupportFiles/Directory.Build.props +++ b/eng/testing/linker/SupportFiles/Directory.Build.props @@ -17,6 +17,8 @@ false true + + $(NoWarn);IL2111 diff --git a/src/libraries/System.Data.Common/src/System/Data/DataTableReader.cs b/src/libraries/System.Data.Common/src/System/Data/DataTableReader.cs index bb7eb7b2340863..821e5face17618 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataTableReader.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataTableReader.cs @@ -741,9 +741,7 @@ internal static DataTable GetSchemaTableFromDataTable(DataTable table) [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:RequiresDynamicallyAccessedMembers", Justification = "The problem is Type.TypeInitializer which requires constructors on the Type instance." + - "In this case the Type instance is about System.Type itself, so adding an explicit dependency on the same" + - "annotation here.")] - [DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors, typeof(Type))] + "In this case the TypeInitializer property is not accessed dynamically.")] static DataColumn GetSystemTypeDataColumn() => new DataColumn(SchemaTableColumn.DataType, typeof(Type)); diff --git a/src/libraries/System.Diagnostics.Tracing/tests/TrimmingTests/EventSourceManifestTest.cs b/src/libraries/System.Diagnostics.Tracing/tests/TrimmingTests/EventSourceManifestTest.cs index c6b0372f6e4a83..92dfa41915d144 100644 --- a/src/libraries/System.Diagnostics.Tracing/tests/TrimmingTests/EventSourceManifestTest.cs +++ b/src/libraries/System.Diagnostics.Tracing/tests/TrimmingTests/EventSourceManifestTest.cs @@ -35,10 +35,6 @@ void EventSourceTest_Method_4(){} int EventSourceTest_Method_7() => 5; } - [UnconditionalSuppressMessage ("TrimAnalysis", "IL2111:RequiresDynamicallyAccessedMembers", - Justification = "GenerateManifest requires all members of EventSourceTest, including members of the base type " + - "EventSource which are annotated with DynamicallyAccessedMembersAttribute. " + - "GenerateManifest does not access these members and is safe to call.")] public static int Main() { string manifest = EventSource.GenerateManifest(typeof(EventSourceTest), null); diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs index 184d3f5c16e32b..69e567d7d991b4 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs @@ -233,16 +233,16 @@ internal sealed class EventSourceAutoGenerateAttribute : Attribute // The EnsureDescriptorsInitialized() method might need to access EventSource and its derived type // members and the trimmer ensures that these members are preserved. [DynamicallyAccessedMembers(ManifestMemberTypes)] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113:RequiresUnreferencedCode", - Justification = "EnsureDescriptorsInitialized's use of GetType preserves methods on Delegate and MulticastDelegate " + - "because the nested type OverrideEventProvider's base type EventProvider defines a delegate. " + - "This includes Delegate and MulticastDelegate methods which require unreferenced code, but " + - "EnsureDescriptorsInitialized does not access these members and is safe to call.")] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2115:RequiresDynamicallyAccessedMembers", - Justification = "EnsureDescriptorsInitialized's use of GetType preserves methods on Delegate and MulticastDelegate " + - "because the nested type OverrideEventProvider's base type EventProvider defines a delegate. " + - "This includes Delegate and MulticastDelegate methods which have dynamically accessed members requirements, but " + - "EnsureDescriptorsInitialized does not access these members and is safe to call.")] + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113:RequiresUnreferencedCode", + Justification = "EnsureDescriptorsInitialized's use of GetType preserves methods on Delegate and MulticastDelegate " + + "because the nested type OverrideEventProvider's base type EventProvider defines a delegate. " + + "This includes Delegate and MulticastDelegate methods which require unreferenced code, but " + + "EnsureDescriptorsInitialized does not access these members and is safe to call.")] + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2115:RequiresDynamicallyAccessedMembers", + Justification = "EnsureDescriptorsInitialized's use of GetType preserves methods on Delegate and MulticastDelegate " + + "because the nested type OverrideEventProvider's base type EventProvider defines a delegate. " + + "This includes Delegate and MulticastDelegate methods which have dynamically accessed members requirements, but " + + "EnsureDescriptorsInitialized does not access these members and is safe to call.")] #endif public partial class EventSource : IDisposable { diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs index 627ff751fa01a3..97bf079fcaf3af 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs @@ -210,7 +210,7 @@ public override Type GetEnumUnderlyingType() } [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2110:RequiresDynamicallyAccessedMembers", - Justification = "For instance member internal calls, the linker preserves all fields of the declaring type. " + + Justification = "For instance members with MethodImplOptions.InternalCall, the linker preserves all fields of the declaring type. " + "The _tb field has DynamicallyAccessedMembersAttribute requirements, but the field access is safe because " + "Reflection.Emit is not subject to trimming.")] [MethodImplAttribute(MethodImplOptions.InternalCall)] From b96ed81b47427f22fa42512da0fd961b9ae30702 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Tue, 3 Aug 2021 17:48:39 +0000 Subject: [PATCH 9/9] Update readable warning names --- .../Runtime/InteropServices/ComActivator.cs | 2 +- .../VisualBasic/CompilerServices/IDOBinder.vb | 2 +- .../Data/Common/DbConnectionStringBuilder.cs | 8 +++--- .../src/System/Data/DataSet.cs | 4 +-- .../src/System/Data/DataTable.cs | 2 +- .../src/System/Data/DataTableReader.cs | 2 +- .../src/System/Data/TypedTableBase.cs | 2 +- .../DiagnosticSourceEventSource.cs | 14 +++++----- .../Linq/Expressions/Compiler/AssemblyGen.cs | 2 +- .../System/Diagnostics/Tracing/EventSource.cs | 26 +++++++++---------- .../TraceLogging/TraceLoggingEventSource.cs | 8 +++--- .../Serialization/PrimitiveDataContract.cs | 2 +- .../Reflection/Emit/EnumBuilder.Mono.cs | 2 +- .../Reflection/Emit/TypeBuilder.Mono.cs | 2 +- 14 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs index 935825523c3e8c..6fdf4b2e5c3116 100644 --- a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs +++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs @@ -627,7 +627,7 @@ internal sealed class LicenseInteropProxy private object? _licContext; private Type? _targetRcwType; - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:RequiresDynamicallyAccessedMembers", + [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() diff --git a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/IDOBinder.vb b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/IDOBinder.vb index e1bf61c780a1a3..cd20c961272056 100644 --- a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/IDOBinder.vb +++ b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/IDOBinder.vb @@ -824,7 +824,7 @@ Namespace Microsoft.VisualBasic.CompilerServices - Public Overrides Function FallbackConvert( ByVal target As DynamicMetaObject, diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs index 14b3a3f4775e16..13552bc01785ef 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs @@ -12,7 +12,7 @@ namespace System.Data.Common { - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113:RequiresUnreferencedCode", + [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)] @@ -391,7 +391,7 @@ internal Attribute[] GetAttributesFromCollection(AttributeCollection collection) return attributes; } - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", + [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.")] @@ -420,7 +420,7 @@ private PropertyDescriptorCollection GetProperties() return propertyDescriptors; } - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", + [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.")] @@ -530,7 +530,7 @@ protected virtual void GetProperties(Hashtable propertyDescriptors) } } - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", + [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.")] diff --git a/src/libraries/System.Data.Common/src/System/Data/DataSet.cs b/src/libraries/System.Data.Common/src/System/Data/DataSet.cs index 622c082b16af5d..b2a85e44b382eb 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataSet.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataSet.cs @@ -227,14 +227,14 @@ 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:RequiresUnreferencedCode", + [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:RequiresUnreferencedCode", + [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() { diff --git a/src/libraries/System.Data.Common/src/System/Data/DataTable.cs b/src/libraries/System.Data.Common/src/System/Data/DataTable.cs index 0e4535f2e36725..08648e6d29c26c 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataTable.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataTable.cs @@ -192,7 +192,7 @@ public DataTable(string? tableName, string? tableNamespace) : this(tableName) } // Deserialize the table from binary/xml stream. - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", + [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() diff --git a/src/libraries/System.Data.Common/src/System/Data/DataTableReader.cs b/src/libraries/System.Data.Common/src/System/Data/DataTableReader.cs index 821e5face17618..58d56a332c63a1 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataTableReader.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataTableReader.cs @@ -739,7 +739,7 @@ internal static DataTable GetSchemaTableFromDataTable(DataTable table) DataColumn NumericScale = new DataColumn(SchemaTableColumn.NumericScale, typeof(short)); DataColumn DataType = GetSystemTypeDataColumn(); - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:RequiresDynamicallyAccessedMembers", + [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() => diff --git a/src/libraries/System.Data.Common/src/System/Data/TypedTableBase.cs b/src/libraries/System.Data.Common/src/System/Data/TypedTableBase.cs index 6820a0b7aeddbe..de17c7d2d82e44 100644 --- a/src/libraries/System.Data.Common/src/System/Data/TypedTableBase.cs +++ b/src/libraries/System.Data.Common/src/System/Data/TypedTableBase.cs @@ -28,7 +28,7 @@ protected TypedTableBase() : base() { } /// /// SerializationInfo containing data to construct the object. /// The streaming context for the object being deserialized. - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", + [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) diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs index 4fabe826e21878..c7b92ad12ff2de 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs @@ -161,12 +161,12 @@ namespace System.Diagnostics /// [EventSource(Name = "Microsoft-Diagnostics-DiagnosticSource")] // These suppressions can go away with https://github.com/mono/linker/issues/2175 - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113:RequiresUnreferencedCode", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113:ReflectionToRequiresUnreferencedCode", Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves methods on Delegate and MulticastDelegate " + "because the nested type OverrideEventProvider's base type EventProvider defines a delegate. " + "This includes Delegate and MulticastDelegate methods which require unreferenced code, but " + "EnsureDescriptorsInitialized does not access these members and is safe to call.")] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2115:RequiresDynamicallyAccessedMembers", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2115:ReflectionToDynamicallyAccessedMembers", Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves methods on Delegate and MulticastDelegate " + "because the nested type OverrideEventProvider's base type EventProvider defines a delegate. " + "This includes Delegate and MulticastDelegate methods which have dynamically accessed members requirements, but " + @@ -1024,7 +1024,7 @@ private void Dispose() } } - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(DiagnosticSource.WriteRequiresUnreferencedCode)] @@ -1108,7 +1108,7 @@ private void Dispose() // Given a type generate all the implicit transforms for type (that is for every field // generate the spec that fetches it). - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(DiagnosticSource.WriteRequiresUnreferencedCode)] @@ -1206,7 +1206,7 @@ public TransformSpec(string transformSpec, int startIdx, int endIdx, TransformSp /// if the spec is OUTSTR=EVENT_VALUE.PROP1.PROP2.PROP3 and the ultimate value of PROP3 is /// 10 then the return key value pair is KeyValuePair("OUTSTR","10") /// - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(DiagnosticSource.WriteRequiresUnreferencedCode)] @@ -1260,7 +1260,7 @@ public PropertySpec(string propertyName, PropertySpec? next) /// Given an object fetch the property that this PropertySpec represents. /// obj may be null when IsStatic is true, otherwise it must be non-null. /// - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(DiagnosticSource.WriteRequiresUnreferencedCode)] @@ -1306,7 +1306,7 @@ public PropertyFetch(Type? type) /// /// Create a property fetcher for a propertyName /// - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(DiagnosticSource.WriteRequiresUnreferencedCode)] diff --git a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/AssemblyGen.cs b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/AssemblyGen.cs index 2236829aa59a69..4f0ed87b7132b2 100644 --- a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/AssemblyGen.cs +++ b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/AssemblyGen.cs @@ -60,7 +60,7 @@ private TypeBuilder DefineType(string name, [DynamicallyAccessedMembers(Dynamica [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "MulticastDelegate has a ctor with RequiresUnreferencedCode, but the generated derived type doesn't reference this ctor, so this is trim compatible.")] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:RequiresDynamicallyAccessedMembers", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:ReflectionToDynamicallyAccessedMembers", Justification = "MulticastDelegate and Delegate have multiple methods with DynamicallyAccessedMembers annotations. But the generated code" + "in this case will not call any of them (it only defines a .ctor and Invoke method both of which are runtime implemented.")] internal static TypeBuilder DefineDelegateType(string name) diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs index 69e567d7d991b4..789a510bece129 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs @@ -233,12 +233,12 @@ internal sealed class EventSourceAutoGenerateAttribute : Attribute // The EnsureDescriptorsInitialized() method might need to access EventSource and its derived type // members and the trimmer ensures that these members are preserved. [DynamicallyAccessedMembers(ManifestMemberTypes)] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113:RequiresUnreferencedCode", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves methods on Delegate and MulticastDelegate " + "because the nested type OverrideEventProvider's base type EventProvider defines a delegate. " + "This includes Delegate and MulticastDelegate methods which require unreferenced code, but " + "EnsureDescriptorsInitialized does not access these members and is safe to call.")] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2115:RequiresDynamicallyAccessedMembers", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2115:ReflectionToDynamicallyAccessedMembers", Justification = "EnsureDescriptorsInitialized's use of GetType preserves methods on Delegate and MulticastDelegate " + "because the nested type OverrideEventProvider's base type EventProvider defines a delegate. " + "This includes Delegate and MulticastDelegate methods which have dynamically accessed members requirements, but " + @@ -372,7 +372,7 @@ public static string GetName(Type eventSourceType) /// which it is embedded. This parameter specifies what name will be used /// The XML data string #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114:RequiresDynamicallyAccessedMembers", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114:ReflectionToDynamicallyAccessedMembers", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "has dynamically accessed members requirements, but EnsureDescriptorsInitialized does not "+ "access this member and is safe to call.")] @@ -399,7 +399,7 @@ public static string GetName(Type eventSourceType) /// this returns null when the eventSourceType does not require explicit registration /// The XML data string or null #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114:RequiresDynamicallyAccessedMembers", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114:ReflectionToDynamicallyAccessedMembers", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "has dynamically accessed members requirements, but EnsureDescriptorsInitialized does not "+ "access this member and is safe to call.")] @@ -1285,7 +1285,7 @@ internal unsafe void SetMetadata(byte* pointer, int size, int reserved) /// /// #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] @@ -1322,7 +1322,7 @@ protected unsafe void WriteEventCore(int eventId, int eventDataCount, EventSourc /// /// #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] @@ -1420,7 +1420,7 @@ protected unsafe void WriteEventWithRelatedActivityIdCore(int eventId, Guid* rel /// check so that the varargs call is not made when the EventSource is not active. /// #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] @@ -1439,7 +1439,7 @@ protected unsafe void WriteEvent(int eventId, params object?[] args) /// check so that the varargs call is not made when the EventSource is not active. /// #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] @@ -1926,7 +1926,7 @@ private static unsafe void AssertValidString(EventData* data) } #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] @@ -2041,7 +2041,7 @@ private unsafe void WriteEventVarargs(int eventId, Guid* childActivityID, object } #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] @@ -2503,7 +2503,7 @@ internal partial struct EventMetadata public TraceLoggingEventTypes TraceLoggingEventTypes { #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] @@ -2994,7 +2994,7 @@ internal static bool IsCustomAttributeDefinedHelper( // Helper to deal with the fact that the type we are reflecting over might be loaded in the ReflectionOnly context. // When that is the case, we have the build the custom assemblies on a member by hand. #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114:RequiresDynamicallyAccessedMembers", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114:ReflectionToDynamicallyAccessedMembers", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "has dynamically accessed members requirements, but EnsureDescriptorsInitialized does not "+ "access this member and is safe to call.")] @@ -3121,7 +3121,7 @@ private static bool AttributeTypeNamesMatch(Type attributeType, Type reflectedAt // at run time. 'source' is the event source to place the descriptors. If it is null, // then the descriptors are not created, and just the manifest is generated. #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114:RequiresDynamicallyAccessedMembers", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114:ReflectionToDynamicallyAccessedMembers", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "has dynamically accessed members requirements, but its use of this method satisfies " + "these requirements because it passes in the result of GetType with the same annotations.")] diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs index f56b86279142cf..b6b739f3eeeb50 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs @@ -163,7 +163,7 @@ public unsafe void Write(string? eventName, EventSourceOptions options) /// create the fields of the event. /// #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] @@ -207,7 +207,7 @@ public unsafe void Write( /// create the fields of the event. /// #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] @@ -253,7 +253,7 @@ public unsafe void Write( /// create the fields of the event. /// #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] @@ -306,7 +306,7 @@ public unsafe void Write( /// create the fields of the event. /// #if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " + "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")] [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/PrimitiveDataContract.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/PrimitiveDataContract.cs index 82318056a51bcb..f7513edfd6720b 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/PrimitiveDataContract.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/PrimitiveDataContract.cs @@ -347,7 +347,7 @@ internal sealed class NullPrimitiveDataContract : PrimitiveDataContract Justification = "This warns because the call to Base has the type annotated with DynamicallyAccessedMembers so it warns" + "when looking into the methods of NullPrimitiveDataContract which are annotated with RequiresUnreferencedCodeAttribute. " + "Because this just represents null, we suppress.")] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:RequiresDynamicallyAccessedMembers", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:ReflectionToDynamicallyAccessedMembers", Justification = "This warns because the call to Base has the type annotated with DynamicallyAccessedMembers so it warns" + "when looking into the methods of NullPrimitiveDataContract which are annotated with DynamicallyAccessedMembersAttribute. " + "Because this just represents null, we suppress.")] diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs index 97bf079fcaf3af..91dff62fa1fbc1 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs @@ -209,7 +209,7 @@ public override Type GetEnumUnderlyingType() return _underlyingType; } - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2110:RequiresDynamicallyAccessedMembers", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2110:ReflectionToDynamicallyAccessedMembers", Justification = "For instance members with MethodImplOptions.InternalCall, the linker preserves all fields of the declaring type. " + "The _tb field has DynamicallyAccessedMembersAttribute requirements, but the field access is safe because " + "Reflection.Emit is not subject to trimming.")] diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs index 1769f34b384102..f2b83fbc7684fc 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs @@ -752,7 +752,7 @@ public ConstructorBuilder DefineTypeInitializer() null); } - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2110:RequiresDynamicallyAccessedMembers", + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2110:ReflectionToDynamicallyAccessedMembers", Justification = "For instance member internal calls, the linker preserves all fields of the declaring type. " + "The parent and created fields have DynamicallyAccessedMembersAttribute requirements, but creating the runtime class is safe " + "because the annotations fully preserve the parent type, and the type created via Reflection.Emit is not subject to trimming.")]