From a79634117c0cac43459bd6c8e0c9e91a48bda35c Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Thu, 15 Oct 2020 17:19:59 +0200 Subject: [PATCH 1/4] Add the ability to remove COM support using ILLinker Fixes #36659 --- .../InteropServices/Marshal.CoreCLR.cs | 2 ++ .../src/ILLink/ILLinkTrim.xml | 2 +- .../ILLink/ILLink.LinkAttributes.Shared.xml | 31 +++++++++++++++++++ .../ILLink/ILLink.Substitutions.Shared.xml | 3 ++ .../Runtime/InteropServices/Marshal.NoCom.cs | 19 ++---------- 5 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs index 22a918584a5679..72e6aaaffd62e0 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs @@ -445,6 +445,8 @@ public static IntPtr CreateAggregatedObject(IntPtr pOuter, T o) where T : not [MethodImpl(MethodImplOptions.InternalCall)] public static extern bool IsComObject(object o); + internal static bool IsComSupported => true; + /// /// Release the COM component and if the reference hits 0 zombie this object. /// Further usage of this Object might throw an exception diff --git a/src/libraries/Microsoft.CSharp/src/ILLink/ILLinkTrim.xml b/src/libraries/Microsoft.CSharp/src/ILLink/ILLinkTrim.xml index 25a8429f396d3f..1c82caac1cef6b 100644 --- a/src/libraries/Microsoft.CSharp/src/ILLink/ILLinkTrim.xml +++ b/src/libraries/Microsoft.CSharp/src/ILLink/ILLinkTrim.xml @@ -1,5 +1,5 @@ - + diff --git a/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.Shared.xml b/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.Shared.xml index 8df05e609708b6..bc37cb9e16bcd8 100644 --- a/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.Shared.xml +++ b/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.Shared.xml @@ -51,4 +51,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml b/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml index 9831ce9b6e2d2b..eb127e8f49e687 100644 --- a/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml +++ b/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml @@ -18,5 +18,8 @@ + + + diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.NoCom.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.NoCom.cs index 3fa9d56f5fd560..7118ddbc6689d0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.NoCom.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.NoCom.cs @@ -195,24 +195,11 @@ public static object GetUniqueObjectForIUnknown(IntPtr unknown) throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop); } - public static bool IsComObject(object o) - { - if (o is null) - { - throw new ArgumentNullException(nameof(o)); - } + public static bool IsComObject(object o) => false; - return false; - } + public static bool IsTypeVisibleFromCom(Type t) => false; - public static bool IsTypeVisibleFromCom(Type t) - { - if (t is null) - { - throw new ArgumentNullException(nameof(t)); - } - return false; - } + internal static bool IsComSupported => false; [SupportedOSPlatform("windows")] public static int QueryInterface(IntPtr pUnk, ref Guid iid, out IntPtr ppv) From 4ca605aec040f3e6391070332be588ae4fa9d44f Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Fri, 16 Oct 2020 11:33:39 +0200 Subject: [PATCH 2/4] PR feedback --- .../ILLink/ILLink.Substitutions.Shared.xml | 8 +++++++- .../Runtime/InteropServices/Marshal.NoCom.cs | 19 +++++++++++++++++-- .../src/System/RuntimeType.Mono.cs | 3 +++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml b/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml index eb127e8f49e687..1ea12c462f3f7b 100644 --- a/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml +++ b/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml @@ -18,8 +18,14 @@ - + + + + + + + diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.NoCom.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.NoCom.cs index 7118ddbc6689d0..5253ac5b0544c2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.NoCom.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.NoCom.cs @@ -195,9 +195,24 @@ public static object GetUniqueObjectForIUnknown(IntPtr unknown) throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop); } - public static bool IsComObject(object o) => false; + public static bool IsComObject(object o) + { + if (o is null) + { + throw new ArgumentNullException(nameof(o)); + } + + return false; + } - public static bool IsTypeVisibleFromCom(Type t) => false; + public static bool IsTypeVisibleFromCom(Type t) + { + if (t is null) + { + throw new ArgumentNullException(nameof(t)); + } + return false; + } internal static bool IsComSupported => false; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeType.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeType.Mono.cs index f3f18653d97e2c..b2e272f765914f 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeType.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeType.Mono.cs @@ -2377,6 +2377,9 @@ public override Guid GUID { get { + if (!Marshal.IsComSupported) + return Guid.Empty; + object[] att = GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), true); if (att.Length == 0) return Guid.Empty; From 7f819376f60f96d517f1065dd651c04b426e65ba Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Fri, 16 Oct 2020 11:44:43 +0200 Subject: [PATCH 3/4] Remove STA/MTA attributes exclusion --- .../src/ILLink/ILLink.LinkAttributes.Shared.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.Shared.xml b/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.Shared.xml index bc37cb9e16bcd8..5238c2c61ab14e 100644 --- a/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.Shared.xml +++ b/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.LinkAttributes.Shared.xml @@ -54,12 +54,6 @@ - - - - - - From 5d658220b561eb2337ef3f6813fd0341b65c4f7b Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Fri, 16 Oct 2020 13:11:42 +0200 Subject: [PATCH 4/4] Undo mono change --- .../System.Private.CoreLib/src/System/RuntimeType.Mono.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeType.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeType.Mono.cs index b2e272f765914f..f3f18653d97e2c 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeType.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeType.Mono.cs @@ -2377,9 +2377,6 @@ public override Guid GUID { get { - if (!Marshal.IsComSupported) - return Guid.Empty; - object[] att = GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), true); if (att.Length == 0) return Guid.Empty;