Skip to content

Commit

Permalink
EventSource linker warnings fix (#46510)
Browse files Browse the repository at this point in the history
* eh fix

* First set of changes for EventSource trim warnings
This is WIP that  fixes EventSource.cs warnings with other fixes to come

* incorporating fb

* incorporating feedback

* Missed removing annotation in the earlier checkin

* Incorporating feedback

* Incorporating feedback

* Incorporating feedback

* merging suppresion file with master

* fix build break

* removing a suppression for linker update
  • Loading branch information
LakshanF committed Jan 7, 2021
1 parent 1cd5e42 commit 9538bee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@
<property name="Scope">member</property>
<property name="Target">M:System.__ComObject.CreateEventProvider(System.RuntimeType)</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2070</argument>
<property name="Scope">member</property>
<property name="Target">M:System.Diagnostics.Tracing.ManifestBuilder.GetTypeName(System.Type)</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2070</argument>
Expand Down Expand Up @@ -121,18 +115,6 @@
<property name="Scope">member</property>
<property name="Target">M:Internal.Runtime.InteropServices.ComponentActivator.InternalGetFunctionPointer(System.Runtime.Loader.AssemblyLoadContext,System.String,System.String,System.IntPtr)</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2075</argument>
<property name="Scope">member</property>
<property name="Target">M:System.Diagnostics.Tracing.EventSource.CreateManifestAndDescriptors(System.Type,System.String,System.Diagnostics.Tracing.EventSource,System.Diagnostics.Tracing.EventManifestOptions)</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2075</argument>
<property name="Scope">member</property>
<property name="Target">M:System.Diagnostics.Tracing.ManifestBuilder.CreateManifestString</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2077</argument>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,7 @@ public static string GetName(Type eventSourceType)
}

#if !ES_BUILD_STANDALONE
private const DynamicallyAccessedMemberTypes ManifestMemberTypes = DynamicallyAccessedMemberTypes.PublicNestedTypes
| DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods;
private const DynamicallyAccessedMemberTypes ManifestMemberTypes = DynamicallyAccessedMemberTypes.All;
#endif

/// <summary>
Expand Down Expand Up @@ -2876,7 +2875,7 @@ private static bool AttributeTypeNamesMatch(Type attributeType, Type reflectedAt
// Use reflection to look at the attributes of a class, and generate a manifest for it (as UTF8) and
// 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 creaed, and just the manifest is generated.
// then the descriptors are not created, and just the manifest is generated.
private static byte[]? CreateManifestAndDescriptors(
#if !ES_BUILD_STANDALONE
[DynamicallyAccessedMembers(ManifestMemberTypes)]
Expand Down Expand Up @@ -5451,6 +5450,18 @@ private string CreateManifestString()
}

// Write out the maps

// Scoping the call to enum GetFields to a local function to limit the linker suppression
#if !ES_BUILD_STANDALONE
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern",
Justification = "Trimmer does not trim enums")]
#endif
static FieldInfo[] GetEnumFields(Type localEnumType)
{
Debug.Assert(localEnumType.IsEnum);
return localEnumType.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Static);
}

if (mapsTab != null)
{
sb.AppendLine(" <maps>");
Expand All @@ -5461,7 +5472,7 @@ private string CreateManifestString()
sb.Append(" <").Append(mapKind).Append(" name=\"").Append(enumType.Name).AppendLine("\">");

// write out each enum value
FieldInfo[] staticFields = enumType.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Static);
FieldInfo[] staticFields = GetEnumFields(enumType);
bool anyValuesWritten = false;
foreach (FieldInfo staticField in staticFields)
{
Expand Down Expand Up @@ -5780,8 +5791,7 @@ private string GetTypeName(Type type)
{
if (type.IsEnum)
{
FieldInfo[] fields = type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
string typeName = GetTypeName(fields[0].FieldType);
string typeName = GetTypeName(type.GetEnumUnderlyingType());
return typeName.Replace("win:Int", "win:UInt"); // ETW requires enums to be unsigned.
}

Expand Down

0 comments on commit 9538bee

Please sign in to comment.