Skip to content

Commit

Permalink
Fix EventSource trimmer warning (dotnet#51237)
Browse files Browse the repository at this point in the history
* eh fix

* test change that inadvertently got checked in earlier

* Suppresses the trimmer warning on TypeAnalysis ctor

* Incorporating FB

* Update src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs

Co-authored-by: Eric Erhardt <[email protected]>

* Update src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs

Co-authored-by: Eric Erhardt <[email protected]>

* Update src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs

Co-authored-by: Eric Erhardt <[email protected]>

* Fix DynamicDependency as per PR feedback

* an earlier change got reverted

* fixed proj file netcore app condition check

* fixed NETCORE_ENGINEERING_TELEMETRY build failures

* fixeing another NETCORE_ENGINEERING_TELEMETRY build failures

* Adding RequiresUnreferencedCode to TypeAnalysis ctor instead of suppressing the warning to get FB, not fully fixed

* PR FB and suppressing warnings for safe calls

* propagated the warning all the way up

* CI build break fix for one file

* excluding NativeRTEventSrc from being build in a project

* Missed couple of supppressions on NativeRTEventSrc

* build break fixes

* Trimmer warning fix related to EventSource manifest creation

* incorporate fb

* fix build break in some configs

* comment feedback

* build break

Co-authored-by: Eric Erhardt <[email protected]>
  • Loading branch information
LakshanF and eerhardt authored Apr 20, 2021
1 parent f9ce10f commit ddaa1c3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public enum EventOpcode
Send = 9,
Receive = 240,
}
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)]
public partial class EventSource : System.IDisposable
{
protected EventSource() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,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>IL2072</argument>
<property name="Scope">member</property>
<property name="Target">M:System.Diagnostics.Tracing.EventSource.EnsureDescriptorsInitialized</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2075</argument>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ internal sealed class EventSourceAutoGenerateAttribute : Attribute
/// }
/// </code>
/// </remarks>
#if !ES_BUILD_STANDALONE
// The EnsureDescriptorsInitialized() method might need to access EventSource and its derived type
// members and the trimmer ensures that these members are preserved.
[DynamicallyAccessedMembers(ManifestMemberTypes)]
#endif
public partial class EventSource : IDisposable
{

Expand Down Expand Up @@ -2765,7 +2770,16 @@ private void EnsureDescriptorsInitialized()
{
// get the metadata via reflection.
Debug.Assert(m_rawManifest == null);
#if !ES_BUILD_STANDALONE
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "Based on the annotation on EventSource class, Trimmer will see from its analysis members " +
"that are marked with RequiresUnreferencedCode and will warn." +
"This method will not access any of these members and is safe to call.")]
byte[]? GetCreateManifestAndDescriptorsViaLocalMethod(string name) => CreateManifestAndDescriptors(this.GetType(), name, this);
m_rawManifest = GetCreateManifestAndDescriptorsViaLocalMethod(Name);
#else
m_rawManifest = CreateManifestAndDescriptors(this.GetType(), Name, this);
#endif
Debug.Assert(m_eventData != null);

// TODO Enforce singleton pattern
Expand Down

0 comments on commit ddaa1c3

Please sign in to comment.