From f6da6163e9d3fef41721ace8841f57a0a0dcb01f Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Tue, 22 Aug 2023 23:14:05 +0200 Subject: [PATCH 1/5] Fix UseManagedNtlm linker Substitutions - Specify the default value (false) for the feature on Linux so the linker runs the substitution when no value was specified by the user. - Make the `UseManagedNtlm` property public because the linker and IL compiler doesn't support substitution of private properties. - Add `--ignore-substitutions` switch to ILLink during library build to prevent the substitution with default value taking place. --- .../src/ILLink/ILLink.Substitutions.Linux.xml | 7 +++++++ ....Substitutions.xml => ILLink.Substitutions.OSXLike.xml} | 0 .../System.Net.Security/src/System.Net.Security.csproj | 4 +++- .../src/System/Net/NegotiateAuthenticationPal.Unix.cs | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 src/libraries/System.Net.Security/src/ILLink/ILLink.Substitutions.Linux.xml rename src/libraries/System.Net.Security/src/ILLink/{ILLink.Substitutions.xml => ILLink.Substitutions.OSXLike.xml} (100%) diff --git a/src/libraries/System.Net.Security/src/ILLink/ILLink.Substitutions.Linux.xml b/src/libraries/System.Net.Security/src/ILLink/ILLink.Substitutions.Linux.xml new file mode 100644 index 0000000000000..d6e9ee7dbfe9d --- /dev/null +++ b/src/libraries/System.Net.Security/src/ILLink/ILLink.Substitutions.Linux.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/libraries/System.Net.Security/src/ILLink/ILLink.Substitutions.xml b/src/libraries/System.Net.Security/src/ILLink/ILLink.Substitutions.OSXLike.xml similarity index 100% rename from src/libraries/System.Net.Security/src/ILLink/ILLink.Substitutions.xml rename to src/libraries/System.Net.Security/src/ILLink/ILLink.Substitutions.OSXLike.xml diff --git a/src/libraries/System.Net.Security/src/System.Net.Security.csproj b/src/libraries/System.Net.Security/src/System.Net.Security.csproj index a06dbd79b8f67..0bb4acc8503b3 100644 --- a/src/libraries/System.Net.Security/src/System.Net.Security.csproj +++ b/src/libraries/System.Net.Security/src/System.Net.Security.csproj @@ -17,6 +17,7 @@ true $(DefineConstants);SYSNETSECURITY_NO_OPENSSL ReferenceAssemblyExclusions.txt + $(ILLinkArgs) --ignore-substitutions @@ -284,7 +285,8 @@ - + + diff --git a/src/libraries/System.Net.Security/src/System/Net/NegotiateAuthenticationPal.Unix.cs b/src/libraries/System.Net.Security/src/System/Net/NegotiateAuthenticationPal.Unix.cs index 776a50901411b..06ee163e0c775 100644 --- a/src/libraries/System.Net.Security/src/System/Net/NegotiateAuthenticationPal.Unix.cs +++ b/src/libraries/System.Net.Security/src/System/Net/NegotiateAuthenticationPal.Unix.cs @@ -19,7 +19,7 @@ namespace System.Net { internal partial class NegotiateAuthenticationPal { - private static bool UseManagedNtlm { get; } = + public static bool UseManagedNtlm { get; } = AppContext.TryGetSwitch("System.Net.Security.UseManagedNtlm", out bool useManagedNtlm) ? useManagedNtlm : OperatingSystem.IsMacOS() || OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst(); From 2107cc45ad1856af39471d77ff82f72f3553ef77 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Thu, 24 Aug 2023 15:54:48 +0200 Subject: [PATCH 2/5] Revert unnecessary changes, document _UseManagedNtlm switch --- docs/workflow/trimming/feature-switches.md | 1 + .../src/ILLink/ILLink.Substitutions.Linux.xml | 7 ------- ....Substitutions.OSXLike.xml => ILLink.Substitutions.xml} | 0 .../System.Net.Security/src/System.Net.Security.csproj | 4 +--- 4 files changed, 2 insertions(+), 10 deletions(-) delete mode 100644 src/libraries/System.Net.Security/src/ILLink/ILLink.Substitutions.Linux.xml rename src/libraries/System.Net.Security/src/ILLink/{ILLink.Substitutions.OSXLike.xml => ILLink.Substitutions.xml} (100%) diff --git a/docs/workflow/trimming/feature-switches.md b/docs/workflow/trimming/feature-switches.md index 87d8fa4c5ec42..0c4d266cf5047 100644 --- a/docs/workflow/trimming/feature-switches.md +++ b/docs/workflow/trimming/feature-switches.md @@ -32,6 +32,7 @@ configurations but their defaults might vary as any SDK can set the defaults dif | _AggressiveAttributeTrimming | System.AggressiveAttributeTrimming | When set to true, aggressively trims attributes to allow for the most size savings possible, even if it could result in runtime behavior changes | | JsonSerializerIsReflectionEnabledByDefault | System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault | When set to false, disables using reflection as the default contract resolver in System.Text.Json | | EnableGeneratedComInterfaceComImportInterop | System.Runtime.InteropServices.Marshalling.EnableGeneratedComInterfaceComImportInterop | When set to true, enables casting source-generated COM object wrappers to built-in COM-based COM interfaces. | +| _UseManagedNtlm | System.Net.Security.UseManagedNtlm | When set to true, uses built-in managed implementation of NTLM and SPNEGO algorithm for HTTP, SMTP authentication, and NegotiateAuthentication API instead of system provided GSSAPI implementation. | Any feature-switch which defines property can be set in csproj file or on the command line as any other MSBuild property. Those without predefined property name diff --git a/src/libraries/System.Net.Security/src/ILLink/ILLink.Substitutions.Linux.xml b/src/libraries/System.Net.Security/src/ILLink/ILLink.Substitutions.Linux.xml deleted file mode 100644 index d6e9ee7dbfe9d..0000000000000 --- a/src/libraries/System.Net.Security/src/ILLink/ILLink.Substitutions.Linux.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/src/libraries/System.Net.Security/src/ILLink/ILLink.Substitutions.OSXLike.xml b/src/libraries/System.Net.Security/src/ILLink/ILLink.Substitutions.xml similarity index 100% rename from src/libraries/System.Net.Security/src/ILLink/ILLink.Substitutions.OSXLike.xml rename to src/libraries/System.Net.Security/src/ILLink/ILLink.Substitutions.xml diff --git a/src/libraries/System.Net.Security/src/System.Net.Security.csproj b/src/libraries/System.Net.Security/src/System.Net.Security.csproj index 0bb4acc8503b3..a06dbd79b8f67 100644 --- a/src/libraries/System.Net.Security/src/System.Net.Security.csproj +++ b/src/libraries/System.Net.Security/src/System.Net.Security.csproj @@ -17,7 +17,6 @@ true $(DefineConstants);SYSNETSECURITY_NO_OPENSSL ReferenceAssemblyExclusions.txt - $(ILLinkArgs) --ignore-substitutions @@ -285,8 +284,7 @@ - - + From 4fd3c9fcaaee00ee1c00e454837b485d3f4d4f96 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Thu, 24 Aug 2023 16:00:45 +0200 Subject: [PATCH 3/5] Set _UseManagedNtlm in NativeAOT integration --- .../BuildIntegration/Microsoft.NETCore.Native.targets | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets index b73da221f44b0..99cb86a62d228 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets @@ -39,6 +39,10 @@ The .NET Foundation licenses this file to you under the MIT license. false true false + + <_UseManagedNtlm Condition="'$(_UseManagedNtlm)' == '' and '$(_linuxLibcFlavor)' == 'bionic'">true + + <_UseManagedNtlm Condition="'$(_UseManagedNtlm)' == '' and '$(_targetOS)' == 'linux'">false @@ -280,9 +284,6 @@ The .NET Foundation licenses this file to you under the MIT license. - - - From 07149378b5d2fef40193a9f83d2d8256546a94a9 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Thu, 24 Aug 2023 19:43:31 +0200 Subject: [PATCH 4/5] Revert unnecessary change, move default values for trimming properties from NativeAOT targets to ILLink ones --- .../BuildIntegration/Microsoft.NETCore.Native.targets | 4 ---- .../src/System/Net/NegotiateAuthenticationPal.Unix.cs | 2 +- .../src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets | 4 ++++ 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets index 99cb86a62d228..81b952c9e3f8c 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets @@ -39,10 +39,6 @@ The .NET Foundation licenses this file to you under the MIT license. false true false - - <_UseManagedNtlm Condition="'$(_UseManagedNtlm)' == '' and '$(_linuxLibcFlavor)' == 'bionic'">true - - <_UseManagedNtlm Condition="'$(_UseManagedNtlm)' == '' and '$(_targetOS)' == 'linux'">false diff --git a/src/libraries/System.Net.Security/src/System/Net/NegotiateAuthenticationPal.Unix.cs b/src/libraries/System.Net.Security/src/System/Net/NegotiateAuthenticationPal.Unix.cs index 06ee163e0c775..776a50901411b 100644 --- a/src/libraries/System.Net.Security/src/System/Net/NegotiateAuthenticationPal.Unix.cs +++ b/src/libraries/System.Net.Security/src/System/Net/NegotiateAuthenticationPal.Unix.cs @@ -19,7 +19,7 @@ namespace System.Net { internal partial class NegotiateAuthenticationPal { - public static bool UseManagedNtlm { get; } = + private static bool UseManagedNtlm { get; } = AppContext.TryGetSwitch("System.Net.Security.UseManagedNtlm", out bool useManagedNtlm) ? useManagedNtlm : OperatingSystem.IsMacOS() || OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst(); diff --git a/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets b/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets index 8f009acd7862d..a4442e1212fdd 100644 --- a/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets +++ b/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets @@ -48,6 +48,10 @@ Copyright (c) .NET Foundation. All rights reserved. <_EnableConsumingManagedCodeFromNativeHosting Condition="'$(_EnableConsumingManagedCodeFromNativeHosting)' == ''">false true false + + <_UseManagedNtlm Condition="'$(_UseManagedNtlm)' == '' and $(RuntimeIdentifier.StartsWith('linux-bionic')">true + + <_UseManagedNtlm Condition="'$(_UseManagedNtlm)' == '' and $(RuntimeIdentifier.StartsWith('linux')">false From 367cd8d4ac24074c55d93d193b2a4f05223ff938 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Thu, 24 Aug 2023 20:31:38 +0200 Subject: [PATCH 5/5] Fix build --- .../src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets b/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets index a4442e1212fdd..2968851f83401 100644 --- a/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets +++ b/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets @@ -49,9 +49,9 @@ Copyright (c) .NET Foundation. All rights reserved. true false - <_UseManagedNtlm Condition="'$(_UseManagedNtlm)' == '' and $(RuntimeIdentifier.StartsWith('linux-bionic')">true + <_UseManagedNtlm Condition="'$(_UseManagedNtlm)' == '' and $(RuntimeIdentifier.StartsWith('linux-bionic'))">true - <_UseManagedNtlm Condition="'$(_UseManagedNtlm)' == '' and $(RuntimeIdentifier.StartsWith('linux')">false + <_UseManagedNtlm Condition="'$(_UseManagedNtlm)' == '' and $(RuntimeIdentifier.StartsWith('linux'))">false