Cleanup IL linker heuristic usage (#25547)
authorJan Kotas <jkotas@microsoft.com>
Wed, 3 Jul 2019 15:59:25 +0000 (08:59 -0700)
committerGitHub <noreply@github.com>
Wed, 3 Jul 2019 15:59:25 +0000 (08:59 -0700)
Prep-work for using mainstream IL linker

src/System.Private.CoreLib/ILLink.targets
src/System.Private.CoreLib/ILLinkTrim.xml
src/System.Private.CoreLib/Resources/Strings.resx
src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs
src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/FieldMetadata.cs
src/System.Private.CoreLib/shared/System/Runtime/Serialization/SafeSerializationEventArgs.cs
src/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs
src/vm/mscorlib.h
src/vm/typeparse.cpp

index e5ede35..7fa64fe 100644 (file)
@@ -62,8 +62,6 @@
       <ILLinkArgs>$(ILLinkArgs) -v true</ILLinkArgs>
       <!-- don't remove the embedded root xml resource since ILLink may run again on the assembly -->
       <ILLinkArgs>$(ILLinkArgs) --strip-resources false</ILLinkArgs>
-      <!-- reflection heuristics to apply -->
-      <ILLinkArgs>$(ILLinkArgs) -h LdtokenTypeMethods,InstanceConstructors</ILLinkArgs>
     </PropertyGroup>
 
     <MakeDir Directories="$(ILLinkTrimInputPath)" />
index d88232b..5fbd0a9 100644 (file)
       <!-- Methods is used by VS Tasks Window. -->
       <method name="GetActiveTaskFromId" />
     </type>
+    <type fullname="System.Collections.Generic.GenericArraySortHelper`1">
+      <!-- Instantiated via reflection -->
+      <method name=".ctor" />
+    </type>
+    <type fullname="System.Collections.Generic.GenericArraySortHelper`2">
+      <!-- Instantiated via reflection -->
+      <method name=".ctor" />
+    </type>
     <!-- Accessed via private reflection by tracing controller. -->
     <type fullname="System.Diagnostics.Tracing.EventPipe*" />
     <!-- Accessed via private reflection and by native code. -->
     <type fullname="System.Diagnostics.Tracing.RuntimeEventSource" />
+    <type fullname="System.Diagnostics.Tracing.NativeRuntimeEventSource" />
     <!-- Accessed via reflection in TraceLogging-style EventSource events. -->
     <type fullname="*f__AnonymousType*" />
+    <type fullname="System.Diagnostics.Tracing.PropertyValue/ReferenceTypeHelper`1">
+      <!-- Instantiated via reflection -->
+      <method name=".ctor" />
+    </type>
     <!-- Accessed via native code. -->
     <type fullname="System.Runtime.InteropServices.ComTypes.IEnumerable" />
     <type fullname="System.Runtime.InteropServices.CustomMarshalers.*" />
     <!-- Accessed by the WinRT Host -->
     <type fullname="Internal.Runtime.InteropServices.WindowsRuntime.ActivationFactoryLoader" />
+    <!-- Workaround for https://github.com/mono/linker/issues/378 -->
+    <type fullname="System.Runtime.InteropServices.IDispatch" />
+    <type fullname="Internal.Runtime.InteropServices.IClassFactory2" />
   </assembly>
 </linker>
index 653c1d3..e8bc952 100644 (file)
   <data name="Serialization_MissingValues" xml:space="preserve">
     <value>The values for this dictionary are missing.</value>
   </data>
-  <data name="Serialization_NonSerType" xml:space="preserve">
-    <value>Type '{0}' in Assembly '{1}' is not marked as serializable.</value>
-  </data>
   <data name="Serialization_NoParameterInfo" xml:space="preserve">
     <value>Serialized member does not have a ParameterInfo.</value>
   </data>
index 90edaed..bf25248 100644 (file)
@@ -3836,18 +3836,6 @@ namespace System.Diagnostics.Tracing
             return -1;
         }
 
-#if false // This routine is not needed at all, it was used for unit test debugging. 
-        [Conditional("DEBUG")]
-        private static void OutputDebugString(string msg)
-        {
-#if !ES_BUILD_PCL
-            msg = msg.TrimEnd('\r', '\n') +
-                    string.Format(CultureInfo.InvariantCulture, ", Thrd({0})" + Environment.NewLine, Environment.CurrentManagedThreadId);
-            System.Diagnostics.Debugger.Log(0, null, msg);
-#endif
-        }
-#endif
-
         /// <summary>
         /// Sends an error message to the debugger (outputDebugString), as well as the EventListeners 
         /// It will do this even if the EventSource is not enabled.  
@@ -3898,11 +3886,6 @@ namespace System.Diagnostics.Tracing
         private bool ThrowOnEventWriteErrors
         {
             get { return (m_config & EventSourceSettings.ThrowOnEventWriteErrors) != 0; }
-            set
-            {
-                if (value) m_config |= EventSourceSettings.ThrowOnEventWriteErrors;
-                else m_config &= ~EventSourceSettings.ThrowOnEventWriteErrors;
-            }
         }
 
         private bool SelfDescribingEvents
@@ -3913,19 +3896,6 @@ namespace System.Diagnostics.Tracing
                                 ((m_config & EventSourceSettings.EtwSelfDescribingEventFormat) != 0));
                 return (m_config & EventSourceSettings.EtwSelfDescribingEventFormat) != 0;
             }
-            set
-            {
-                if (!value)
-                {
-                    m_config |= EventSourceSettings.EtwManifestEventFormat;
-                    m_config &= ~EventSourceSettings.EtwSelfDescribingEventFormat;
-                }
-                else
-                {
-                    m_config |= EventSourceSettings.EtwSelfDescribingEventFormat;
-                    m_config &= ~EventSourceSettings.EtwManifestEventFormat;
-                }
-            }
         }
 
         // private instance state 
index 2c50266..06084f4 100644 (file)
@@ -76,7 +76,6 @@ namespace System.Diagnostics.Tracing
                 fixedCount,
                 null)
         {
-            return;
         }
 
         /// <summary>
@@ -95,7 +94,6 @@ namespace System.Diagnostics.Tracing
                 checked((ushort)(custom == null ? 0 : custom.Length)),
                 custom)
         {
-            return;
         }
 
         private FieldMetadata(
index 896b91f..ccc518f 100644 (file)
@@ -6,24 +6,13 @@ using System.Collections.Generic;
 
 namespace System.Runtime.Serialization
 {
-    // SafeSerializationEventArgs are provided to the delegates which do safe serialization.  Each delegate
-    // serializes its own state into an IDeserializationCallback instance which must, itself, be serializable.
-    // These indivdiual states are then added to the SafeSerializationEventArgs in order to be saved away when
-    // the original ISerializable type is serialized.
+    // This type exists for public surface compatibility only.
     public sealed class SafeSerializationEventArgs : EventArgs
     {
-        private readonly List<object> _serializedStates = new List<object>();
-
-        internal SafeSerializationEventArgs() { }
+        private SafeSerializationEventArgs() { }
 
         public void AddSerializedState(ISafeSerializationData serializedState)
         {
-            if (serializedState == null)
-                throw new ArgumentNullException(nameof(serializedState));
-            if (!serializedState.GetType().IsSerializable)
-                throw new ArgumentException(SR.Format(SR.Serialization_NonSerType, serializedState.GetType(), serializedState.GetType().Assembly.FullName));
-
-            _serializedStates.Add(serializedState);
         }
 
         public StreamingContext StreamingContext { get; }
index 072b360..b63a167 100644 (file)
@@ -262,7 +262,7 @@ namespace System.Reflection.Emit
                                                               ref StackCrawlMark stackMark,
                                                               AssemblyBuilderAccess access);
 
-        private class AssemblyBuilderLock { }
+        private static readonly object s_assemblyBuilderLock = new object();
 
         internal static AssemblyBuilder InternalDefineDynamicAssembly(
             AssemblyName name,
@@ -270,7 +270,7 @@ namespace System.Reflection.Emit
             ref StackCrawlMark stackMark,
             IEnumerable<CustomAttributeBuilder>? unsafeAssemblyAttributes)
         {
-            lock (typeof(AssemblyBuilderLock))
+            lock (s_assemblyBuilderLock)
             {
                 // We can only create dynamic assemblies in the current domain
                 return new AssemblyBuilder(name,
index 403b27b..90e4441 100644 (file)
@@ -752,6 +752,7 @@ DEFINE_METHOD(SAFE_HANDLE,          DISPOSE_BOOL,           Dispose,
 
 
 DEFINE_CLASS(SAFE_TYPENAMEPARSER_HANDLE,    System,         SafeTypeNameParserHandle)
+DEFINE_METHOD(SAFE_TYPENAMEPARSER_HANDLE,   CTOR,   .ctor,  IM_RetVoid)
 
 DEFINE_CLASS(SECURITY_EXCEPTION,    Security,               SecurityException)
 
index 9f8f733..0827d92 100644 (file)
@@ -93,7 +93,15 @@ SAFEHANDLE TypeName::GetSafeHandle()
     GCPROTECT_BEGIN(objSafeHandle);
 
     objSafeHandle = (SAFEHANDLE)AllocateObject(MscorlibBinder::GetClass(CLASS__SAFE_TYPENAMEPARSER_HANDLE));
-    CallDefaultConstructor(objSafeHandle);
+
+    MethodDescCallSite strCtor(METHOD__SAFE_TYPENAMEPARSER_HANDLE__CTOR);
+
+    ARG_SLOT args[1] =
+    {
+        ObjToArgSlot(objSafeHandle)
+    };
+
+    strCtor.Call(args);
 
     this->AddRef();
     objSafeHandle->SetHandle(this);