From 472430baf7c4ce4f508ade323447436e96d3b2d3 Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Fri, 1 Aug 2025 10:46:21 -0700 Subject: [PATCH 1/7] Handle 'lib' variants in ilc ModuleNameVariations for DirectPInvokes --- .../tools/aot/ILCompiler/ConfigurablePInvokePolicy.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/coreclr/tools/aot/ILCompiler/ConfigurablePInvokePolicy.cs b/src/coreclr/tools/aot/ILCompiler/ConfigurablePInvokePolicy.cs index 27d6108eb70e9e..063fab8f231c6a 100644 --- a/src/coreclr/tools/aot/ILCompiler/ConfigurablePInvokePolicy.cs +++ b/src/coreclr/tools/aot/ILCompiler/ConfigurablePInvokePolicy.cs @@ -92,9 +92,15 @@ private IEnumerable ModuleNameVariations(string name) else { string suffix = _target.IsApplePlatform ? ".dylib" : ".so"; + bool hasSharedLibraryExtension = name.EndsWith(suffix, StringComparison.Ordinal); + bool hasLibPrefix = name.StartsWith("lib"); - if (name.EndsWith(suffix, StringComparison.Ordinal)) + if (hasSharedLibraryExtension) yield return name.Substring(0, name.Length - suffix.Length); + if (hasLibPrefix) + yield return name.Substring(3); + if (hasLibPrefix && hasSharedLibraryExtension) + yield return name.Substring(3, name.Length - suffix.Length - 3); } } From 0cdc8a87f2e7f88ff07caabd8aea603522e8b602 Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Fri, 1 Aug 2025 10:58:06 -0700 Subject: [PATCH 2/7] Update src/coreclr/tools/aot/ILCompiler/ConfigurablePInvokePolicy.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/coreclr/tools/aot/ILCompiler/ConfigurablePInvokePolicy.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/tools/aot/ILCompiler/ConfigurablePInvokePolicy.cs b/src/coreclr/tools/aot/ILCompiler/ConfigurablePInvokePolicy.cs index 063fab8f231c6a..a38bcce51a3b8e 100644 --- a/src/coreclr/tools/aot/ILCompiler/ConfigurablePInvokePolicy.cs +++ b/src/coreclr/tools/aot/ILCompiler/ConfigurablePInvokePolicy.cs @@ -93,7 +93,7 @@ private IEnumerable ModuleNameVariations(string name) { string suffix = _target.IsApplePlatform ? ".dylib" : ".so"; bool hasSharedLibraryExtension = name.EndsWith(suffix, StringComparison.Ordinal); - bool hasLibPrefix = name.StartsWith("lib"); + bool hasLibPrefix = name.StartsWith("lib", StringComparison.Ordinal); if (hasSharedLibraryExtension) yield return name.Substring(0, name.Length - suffix.Length); From a4db9cddb8edee7210a8029b8b84c13a1b0fea04 Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Fri, 1 Aug 2025 14:33:13 -0700 Subject: [PATCH 3/7] Share DirectPInvoke ItemGroup for NativeAOT --- .../BuildIntegration/Microsoft.NETCore.Native.Unix.targets | 5 ++--- .../Microsoft.NETCore.Native.Windows.targets | 1 - .../BuildIntegration/Microsoft.NETCore.Native.targets | 4 ++++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index 3c997799362abd..ab0e44d56be4b4 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -148,7 +148,6 @@ The .NET Foundation licenses this file to you under the MIT license. - $(IlcFrameworkNativePath)lib%(Identity).a @@ -180,7 +179,7 @@ The .NET Foundation licenses this file to you under the MIT license. - + @@ -193,7 +192,7 @@ The .NET Foundation licenses this file to you under the MIT license. - + diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets index 8639c24343b883..bd32a1d88d3f22 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets @@ -58,7 +58,6 @@ The .NET Foundation licenses this file to you under the MIT license. - $(IlcSdkPath)%(Identity).Aot$(LibrarySuffix) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets index c1a3aee2d3c86a..569a416e490f2e 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets @@ -336,6 +336,10 @@ The .NET Foundation licenses this file to you under the MIT license. + + + + Date: Fri, 1 Aug 2025 15:36:41 -0700 Subject: [PATCH 4/7] Update src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets Co-authored-by: Jan Kotas --- .../nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets index 569a416e490f2e..786141a07b278f 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets @@ -337,7 +337,7 @@ The .NET Foundation licenses this file to you under the MIT license. - + Date: Fri, 1 Aug 2025 15:38:21 -0700 Subject: [PATCH 5/7] Use const string for "lib" literal --- .../tools/aot/ILCompiler/ConfigurablePInvokePolicy.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler/ConfigurablePInvokePolicy.cs b/src/coreclr/tools/aot/ILCompiler/ConfigurablePInvokePolicy.cs index a38bcce51a3b8e..ac6e0a66934ac7 100644 --- a/src/coreclr/tools/aot/ILCompiler/ConfigurablePInvokePolicy.cs +++ b/src/coreclr/tools/aot/ILCompiler/ConfigurablePInvokePolicy.cs @@ -93,14 +93,15 @@ private IEnumerable ModuleNameVariations(string name) { string suffix = _target.IsApplePlatform ? ".dylib" : ".so"; bool hasSharedLibraryExtension = name.EndsWith(suffix, StringComparison.Ordinal); - bool hasLibPrefix = name.StartsWith("lib", StringComparison.Ordinal); + const string LibPrefix = "lib"; + bool hasLibPrefix = name.StartsWith(LibPrefix, StringComparison.Ordinal); if (hasSharedLibraryExtension) yield return name.Substring(0, name.Length - suffix.Length); if (hasLibPrefix) - yield return name.Substring(3); + yield return name.Substring(LibPrefix.Length); if (hasLibPrefix && hasSharedLibraryExtension) - yield return name.Substring(3, name.Length - suffix.Length - 3); + yield return name.Substring(LibPrefix.Length, name.Length - suffix.Length - LibPrefix.Length); } } From 6565bba8b0c3b7153eddf1ee48499004a51103a4 Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Mon, 4 Aug 2025 14:56:00 -0700 Subject: [PATCH 6/7] DirectPInvoke still needs to be set in SetupOSSpecificProps target, not during evaluation --- .../BuildIntegration/Microsoft.NETCore.Native.Unix.targets | 7 ++++--- .../Microsoft.NETCore.Native.Windows.targets | 1 + .../BuildIntegration/Microsoft.NETCore.Native.targets | 4 ---- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index ab0e44d56be4b4..66a4c913fd5bcf 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -148,7 +148,8 @@ The .NET Foundation licenses this file to you under the MIT license. - + + $(IlcFrameworkNativePath)lib%(Identity).a @@ -179,7 +180,7 @@ The .NET Foundation licenses this file to you under the MIT license. - + @@ -192,7 +193,7 @@ The .NET Foundation licenses this file to you under the MIT license. - + diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets index bd32a1d88d3f22..eca4646c95b658 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets @@ -58,6 +58,7 @@ The .NET Foundation licenses this file to you under the MIT license. + $(IlcSdkPath)%(Identity).Aot$(LibrarySuffix) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets index 786141a07b278f..c1a3aee2d3c86a 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets @@ -336,10 +336,6 @@ The .NET Foundation licenses this file to you under the MIT license. - - - - Date: Mon, 4 Aug 2025 17:05:58 -0700 Subject: [PATCH 7/7] Remove 'lib' from other DirectPInvokes --- .../BuildIntegration/Microsoft.NETCore.Native.Unix.targets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index 66a4c913fd5bcf..9bbc58b0ccaff9 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -180,7 +180,7 @@ The .NET Foundation licenses this file to you under the MIT license. - + @@ -193,7 +193,7 @@ The .NET Foundation licenses this file to you under the MIT license. - +