Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions eng/illink.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Project>
<PropertyGroup>
<IsTrimmable Condition="'$(IsTrimmable)' == ''">true</IsTrimmable>
<PrepareResourcesDependsOn>
_EmbedILLinkXmls;
$(PrepareResourcesDependsOn)
Expand Down Expand Up @@ -35,6 +36,8 @@
<ILLinkSuppressionsXmlFile>$(ILLinkSuppressionsXmlFilePrefix).xml</ILLinkSuppressionsXmlFile>
<ILLinkSuppressionsConfigurationSpecificXmlFile>$(ILLinkSuppressionsXmlFilePrefix).$(Configuration).xml</ILLinkSuppressionsConfigurationSpecificXmlFile>
<ILLinkSuppressionsLibraryBuildXmlFile>$(ILLinkSuppressionsXmlFilePrefix).LibraryBuild.xml</ILLinkSuppressionsLibraryBuildXmlFile>
<!-- Only run the trim analyzer on libraries which have been annotated. -->
<EnableTrimAnalyzer Condition="'$(EnableTrimAnalyzer)' == '' And (Exists('$(ILLinkSuppressionsXmlFile)') Or Exists('$(ILLinkSuppressionsConfigurationSpecificXmlFile)'))">false</EnableTrimAnalyzer>

<!-- if building a PDB, tell illink to rewrite the symbols file -->
<ILLinkRewritePDBs Condition="'$(ILLinkRewritePDBs)' == '' and '$(DebugSymbols)' != 'false'">true</ILLinkRewritePDBs>
Expand Down
2 changes: 1 addition & 1 deletion eng/testing/tests.mobile.targets
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,5 @@
DependsOnTargets="InstallWorkloadUsingArtifacts"
Condition="'$(InstallWorkloadForTesting)' == 'true'" />

<Import Project="$(RepositoryEngineeringDir)illink.targets" Condition="'$(SkipImportRepoLinkerTargets)' != 'true'" />
<Import Project="$(RepositoryEngineeringDir)illink.targets" Condition="'$(EnableAggressiveTrimming)' == 'true' or '$(EnableSoftTrimming)' == 'true'" />
</Project>
5 changes: 0 additions & 5 deletions eng/versioning.targets
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
<_Parameter1>PreferInbox</_Parameter1>
<_Parameter2>True</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadata"
Condition="'$(SetIsTrimmable)' != 'false'">
<_Parameter1>IsTrimmable</_Parameter1>
<_Parameter2>True</_Parameter2>
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public static unsafe void LoadInMemoryAssembly(IntPtr moduleHandle, IntPtr assem

// We don't cache the ALCs here since each IJW assembly will call this method at most once
// (the load process rewrites the stubs that call here to call the actual methods they're supposed to)
#pragma warning disable IL2026 // suppressed in ILLink.Suppressions.LibraryBuild.xml
AssemblyLoadContext context = new IsolatedComponentLoadContext(assemblyPathString);
#pragma warning restore IL2026
context.LoadFromInMemoryModule(moduleHandle);
#else
throw new PlatformNotSupportedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1098,17 +1098,6 @@ private int GetTypeTokenWorkerNoLock(Type type!!, bool getGenericDefinition)
return GetTypeRefNested(type, refedModule, referencedModuleFileName);
}

internal int GetTypeToken(string name)
{
// Return a token for the class relative to the Module.
// Module.GetType() verifies name

// Unfortunately, we will need to load the Type and then call GetTypeToken in
// order to correctly track the assembly reference information.

return GetTypeToken(InternalModule.GetType(name, false, true)!);
}

internal int GetMethodToken(MethodInfo method)
{
lock (SyncRoot)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ private static void ProcessStartupHooks()
// Call each hook in turn
foreach (StartupHookNameOrPath startupHook in startupHooks)
{
#pragma warning disable IL2026 // suppressed in ILLink.Suppressions.LibraryBuild.xml
CallStartupHook(startupHook);
#pragma warning restore IL2026
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Reflection.Runtime.TypeInfos;

namespace System.Reflection.Runtime.Dispensers
Expand All @@ -15,7 +16,7 @@ internal static class DispenserFactory
//
// Note: If your K is a valuetype, use CreateDispenserV() instead. Some algorithms will not be available for use.
//
public static Dispenser<K, V> CreateDispenser<K, V>(DispenserScenario scenario, Func<K, V> factory)
public static Dispenser<K, V> CreateDispenser<K, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]V>(DispenserScenario scenario, Func<K, V> factory)
where K : class, IEquatable<K>
where V : class
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace System.Reflection.Runtime.Dispensers
{
internal sealed class DispenserThatReusesAsLongAsKeyIsAlive<K, V> : Dispenser<K, V>
internal sealed class DispenserThatReusesAsLongAsKeyIsAlive<K, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] V> : Dispenser<K, V>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MichalStrehovsky I'm not familiar enough with nativeaot to know why this wasn't warning (in the use of ConditionalWeakTable<K, V> below) in nativeaot - do you have any ideas?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC warnings for generic dataflow are not implemented. I scoped out some of the warnings because it's not critical for functionality. One person working on dataflow part time on NativeAOT side is no match to several people working on this pretty much full time on the IL Linker side.

We'll be able to re-use the unit tests on the IL Linker side to bring this to parity once this becomes a priority.

where K : class, IEquatable<K>
where V : class
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,9 @@ private static RuntimeMethodInfo LookupMethodForCreateDelegate(RuntimeTypeInfo r
if (methodInfo != null && methodInfo.ReturnType.Equals(invokeMethod.ReturnType))
return (RuntimeMethodInfo)methodInfo; // This cast is safe since we already verified that containingType is runtime implemented.

#pragma warning disable IL2072 // https://github.com/dotnet/linker/issues/2673
containingType = (RuntimeTypeInfo)(containingType.BaseType);
#pragma warning restore
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Microsoft.Diagnostics.Tracing.EventSource</PackageDescription>
<PackageId>$(MSBuildProjectName)</PackageId>
<AssemblyName>Microsoft.Diagnostics.Tracing.EventSource</AssemblyName>
<DefineConstants>$(DefineConstants);NO_EVENTCOMMANDEXECUTED_SUPPORT;ES_BUILD_STANDALONE;FEATURE_MANAGED_ETW;TARGET_WINDOWS</DefineConstants>
<EnableTrimAnalyzer>false</EnableTrimAnalyzer>
<TargetFramework>$(NetFrameworkMinimum)</TargetFramework>
<Nullable>enable</Nullable>
<IncludePlatformAttributes>true</IncludePlatformAttributes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<DisableImplicitAssemblyReferences>false</DisableImplicitAssemblyReferences>
<CLSCompliant>false</CLSCompliant>
<IsPackable>true</IsPackable>
<IsTrimmable>false</IsTrimmable>
<PackageDescription>Suite of xUnit.net tests to check for container compatibility with Microsoft.Extensions.DependencyInjection.</PackageDescription>
<!-- this assembly doesn't need to be binplaced -->
<EnableBinPlacing>false</EnableBinPlacing>
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.CodeDom/src/System.CodeDom.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<DefineConstants>$(DefineConstants);CODEDOM</DefineConstants>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<Nullable>annotations</Nullable>
<SetIsTrimmable>false</SetIsTrimmable>
<IsTrimmable>false</IsTrimmable>
<IsPackable>true</IsPackable>
<PackageDescription>Provides types that can be used to model the structure of a source code document and to output source code for that model in a supported language.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.1</TargetFrameworks>
<SetIsTrimmable>false</SetIsTrimmable>
<IsTrimmable>false</IsTrimmable>
<IsPackable>true</IsPackable>
<AddNETFrameworkPlaceholderFileToPackage>true</AddNETFrameworkPlaceholderFileToPackage>
<AddNETFrameworkAssemblyReferenceToPackage>true</AddNETFrameworkAssemblyReferenceToPackage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0</TargetFrameworks>
<Nullable>enable</Nullable>
<SetIsTrimmable>false</SetIsTrimmable>
<IsTrimmable>false</IsTrimmable>
<IsPackable>true</IsPackable>
<AddNETFrameworkPlaceholderFileToPackage>true</AddNETFrameworkPlaceholderFileToPackage>
<AddNETFrameworkAssemblyReferenceToPackage>true</AddNETFrameworkAssemblyReferenceToPackage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ private static void SerializeWithBinaryFormatter(Stream o, string cryptoKey, Des
{
IFormatter formatter = new BinaryFormatter();
#pragma warning disable SYSLIB0011
#pragma warning disable IL2026 // suppressed in ILLink.Suppressions.LibraryBuild.xml
formatter.Serialize(o, new object[] { cryptoKey, context._savedLicenseKeys });
#pragma warning restore IL2026
#pragma warning restore SYSLIB0011
}

Expand Down Expand Up @@ -132,7 +134,9 @@ private static void DeserializeUsingBinaryFormatter(StreamWrapper wrappedStream,
#pragma warning disable SYSLIB0011
IFormatter formatter = new BinaryFormatter();

#pragma warning disable IL2026 // suppressed in ILLink.Suppressions.LibraryBuild.xml
object obj = formatter.Deserialize(wrappedStream);
#pragma warning restore IL2026
#pragma warning restore SYSLIB0011

if (obj is object[] value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<SetIsTrimmable>false</SetIsTrimmable>
<IsTrimmable>false</IsTrimmable>
<IsPackable>true</IsPackable>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<PackageDescription>Provides types that support using Managed Extensibility Framework with a convention-based configuration model.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<SetIsTrimmable>false</SetIsTrimmable>
<IsTrimmable>false</IsTrimmable>
<IsPackable>true</IsPackable>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<PackageDescription>Provides Managed Extensibility Framework types that are useful to developers of extensible applications, or hosts.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<RootNamespace>System.Composition</RootNamespace>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<SetIsTrimmable>false</SetIsTrimmable>
<IsTrimmable>false</IsTrimmable>
<IsPackable>true</IsPackable>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<PackageDescription>Provides some extension methods for the Managed Extensibility Framework.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<!-- opt-out of trimming until it works https://github.com/dotnet/runtime/issues/49062 -->
<SetIsTrimmable>false</SetIsTrimmable>
<IsTrimmable>false</IsTrimmable>
<NoWarn>$(NoWarn);CA1847</NoWarn>
<IsPackable>true</IsPackable>
<PackageDescription>Provides types that support using configuration files.
Expand Down
6 changes: 6 additions & 0 deletions src/libraries/System.Data.Common/src/System/Data/DataSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3474,7 +3474,9 @@ public static XmlSchemaComplexType GetDataSetSchema(XmlSchemaSet? schemaSet)
XmlWriter writer = new XmlTextWriter(stream, null);
if (writer != null)
{
#pragma warning disable IL2026 // suppressed in ILLink.Suppressions.LibraryBuild.xml
WriteXmlSchema(this, writer);
#pragma warning restore IL2026
}
stream.Position = 0;
return XmlSchema.Read(new XmlTextReader(stream), null);
Expand Down Expand Up @@ -3506,7 +3508,9 @@ void IXmlSerializable.ReadXml(XmlReader reader)
}
}

#pragma warning disable IL2026 // suppressed in ILLink.Suppressions.LibraryBuild.xml
ReadXmlSerializableInternal(reader);
#pragma warning restore IL2026

if (xmlTextParser != null)
{
Expand All @@ -3526,7 +3530,9 @@ private void ReadXmlSerializableInternal(XmlReader reader)

void IXmlSerializable.WriteXml(XmlWriter writer)
{
#pragma warning disable IL2026 // suppressed in ILLink.Suppressions.LibraryBuild.xml
WriteXmlInternal(writer);
#pragma warning restore IL2026
}

[RequiresUnreferencedCode("DataSet.WriteXml uses XmlSerialization underneath which is not trimming safe. Members from serialized types may be trimmed if not referenced directly.")]
Expand Down
6 changes: 6 additions & 0 deletions src/libraries/System.Data.Common/src/System/Data/DataTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6704,7 +6704,9 @@ public static XmlSchemaComplexType GetDataTableSchema(XmlSchemaSet? schemaSet)
return type;
}

#pragma warning disable IL2026 // suppressed in ILLink.Suppressions.LibraryBuild.xml
XmlSchema? IXmlSerializable.GetSchema() => GetXmlSchema();
#pragma warning restore IL2026

[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2046:UnrecognizedReflectionPattern",
Expand Down Expand Up @@ -6741,7 +6743,9 @@ void IXmlSerializable.ReadXml(XmlReader reader)
fNormalization = textReader.Normalized;
textReader.Normalized = false;
}
#pragma warning disable IL2026 // suppressed in ILLink.Suppressions.LibraryBuild.xml
ReadXmlSerializableInternal(reader);
#pragma warning restore IL2026

if (textReader != null)
{
Expand All @@ -6757,7 +6761,9 @@ private void ReadXmlSerializableInternal(XmlReader reader)

void IXmlSerializable.WriteXml(XmlWriter writer)
{
#pragma warning disable IL2026 // suppressed in ILLink.Suppressions.LibraryBuild.xml
WriteXmlInternal(writer);
#pragma warning restore IL2026
}

[RequiresUnreferencedCode("DataTable.WriteXml uses XmlSerialization underneath which is not trimming safe. Members from serialized types may be trimmed if not referenced directly.")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<NoWarn>$(NoWarn);SA1205;CA1845</NoWarn>
<Nullable>enable</Nullable>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<EnableTrimAnalyzer Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETFramework'">false</EnableTrimAnalyzer>
<IsPackable>true</IsPackable>
<PackageDescription>Provides Classes that allow you to decouple code logging rich (unserializable) diagnostics/telemetry (e.g. framework) from code that consumes it (e.g. tools)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ public static unsafe int GetFunctionPointer(IntPtr typeNameNative,

ArgumentNullException.ThrowIfNull(functionHandle);

#pragma warning disable IL2026 // suppressed in ILLink.Suppressions.LibraryBuild.xml
// Create the function pointer.
*(IntPtr*)functionHandle = InternalGetFunctionPointer(AssemblyLoadContext.Default, typeName, methodName, delegateTypeNative);
#pragma warning restore IL2026
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ internal ResourceSet CreateResourceSet(Stream store, Assembly assembly)
{
Debug.Assert(readerTypeName != null, "Reader Type name should be set");
Debug.Assert(resSetTypeName != null, "ResourceSet Type name should be set");
#pragma warning disable IL2026 // suppressed in ILLink.Suppressions.LibraryBuild.xml
return InternalGetResourceSetFromSerializedData(store, readerTypeName, resSetTypeName, _mediator);
#pragma warning restore IL2026
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Runtime.Serialization
Expand Down Expand Up @@ -48,7 +48,9 @@ public override void WriteXmlValue(XmlWriterDelegator xmlWriter, object obj, Xml
}

[MethodImpl(MethodImplOptions.NoInlining)]
private object GetUninitializedObject(Type objType)
private object GetUninitializedObject(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
Type objType)
{
return RuntimeHelpers.GetUninitializedObject(objType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ internal sealed class ReflectionXmlSerializationReader : XmlSerializationReader
{
private readonly XmlMapping _mapping;

// These UnconditionalSuppressMessage attributes are understood by the trim analyzer but not by the linker.
// The assembly-level suppression suppresses the same warnings for the linker.
// https://github.com/dotnet/linker/issues/2648
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode")]
internal static TypeDesc StringTypeDesc { get; set; } = (new TypeScope()).GetTypeDesc(typeof(string));
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode")]
internal static TypeDesc QnameTypeDesc { get; set; } = (new TypeScope()).GetTypeDesc(typeof(XmlQualifiedName));

public ReflectionXmlSerializationReader(XmlMapping mapping, XmlReader xmlReader, XmlDeserializationEvents events, string? encodingStyle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ internal static class CryptoConfigForwarder
{
internal const string CreateFromNameUnreferencedCodeMessage = "The default algorithm implementations might be removed, use strong type references like 'RSA.Create()' instead.";

// This UnconditionalSuppressMessage attribute is understood by the trim analyzer but not by the linker.
// The assembly-level suppression suppresses the same warning for the linker.
// https://github.com/dotnet/linker/issues/2648
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode")]
private static readonly Func<string, object?> s_createFromName = BindCreateFromName();

[RequiresUnreferencedCode(CreateFromNameUnreferencedCodeMessage)]
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Speech/src/System.Speech.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- CA1846: Prefer 'AsSpan' over 'Substring' when span-based overloads are available -->
<NoWarn>$(NoWarn);CS0649;SA1129;CA1846;CA1847;IDE0059</NoWarn>
<Nullable>annotations</Nullable>
<SetIsTrimmable>false</SetIsTrimmable>
<IsTrimmable>false</IsTrimmable>
<IsPackable>true</IsPackable>
<AddNETFrameworkPlaceholderFileToPackage>true</AddNETFrameworkPlaceholderFileToPackage>
<AddNETFrameworkAssemblyReferenceToPackage>true</AddNETFrameworkAssemblyReferenceToPackage>
Expand Down
Loading