diff --git a/src/Common/src/Interop/Unix/libdl/Interop.dlopen.cs b/src/Common/src/Interop/Unix/libdl/Interop.dlopen.cs index 4a4c31f0355c..71eabf006a74 100644 --- a/src/Common/src/Interop/Unix/libdl/Interop.dlopen.cs +++ b/src/Common/src/Interop/Unix/libdl/Interop.dlopen.cs @@ -9,7 +9,7 @@ internal partial class Interop { internal partial class Libdl { - public const int RTLD_NOW = 0x002; + public const int RTLD_LAZY = 0x001; [DllImport(Libraries.Libdl)] public static extern IntPtr dlopen(string fileName, int flag); diff --git a/src/CoreFx.Private.TestUtilities/src/System/PlatformDetection.Unix.cs b/src/CoreFx.Private.TestUtilities/src/System/PlatformDetection.Unix.cs index e36befbb8f26..ae47ae11106d 100644 --- a/src/CoreFx.Private.TestUtilities/src/System/PlatformDetection.Unix.cs +++ b/src/CoreFx.Private.TestUtilities/src/System/PlatformDetection.Unix.cs @@ -60,32 +60,21 @@ public static partial class PlatformDetection public static bool IsNetfx471OrNewer => false; public static bool IsNetfx472OrNewer => false; - public static bool IsDrawingSupported { get; } = GetGdiplusIsAvailable(); - public static bool IsSoundPlaySupported { get; } = false; + public static bool IsDrawingSupported { get; } = + RuntimeInformation.IsOSPlatform(OSPlatform.OSX) +#if netcoreapp30 + ? NativeLibrary.TryLoad("libgdiplus.dylib", out _) + : NativeLibrary.TryLoad("libgdiplus.so", out _) || NativeLibrary.TryLoad("libgdiplus.so.0", out _); +#else + ? dlopen("libgdiplus.dylib", RTLD_LAZY) != IntPtr.Zero + : dlopen("libgdiplus.so", RTLD_LAZY) != IntPtr.Zero || dlopen("libgdiplus.so.0", RTLD_LAZY) != IntPtr.Zero; [DllImport("libdl")] private static extern IntPtr dlopen(string libName, int flags); - public const int RTLD_NOW = 0x002; - - private static bool GetGdiplusIsAvailable() - { - IntPtr nativeLib; + private const int RTLD_LAZY = 0x001; +#endif - if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - { - nativeLib = dlopen("libgdiplus.dylib", RTLD_NOW); - } - else - { - nativeLib = dlopen("libgdiplus.so", RTLD_NOW); - if (nativeLib == IntPtr.Zero) - { - nativeLib = dlopen("libgdiplus.so.0", RTLD_NOW); - } - } - - return nativeLib != IntPtr.Zero; - } + public static bool IsSoundPlaySupported { get; } = false; public static Version OSXVersion { get; } = ToVersion(PlatformApis.GetOSVersion()); diff --git a/src/System.Data.Odbc/tests/Helpers.cs b/src/System.Data.Odbc/tests/Helpers.cs index 126b8657fc44..d245002bfaef 100644 --- a/src/System.Data.Odbc/tests/Helpers.cs +++ b/src/System.Data.Odbc/tests/Helpers.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Runtime.InteropServices; namespace System.Data.Odbc.Tests { @@ -16,7 +17,7 @@ private static bool CheckOdbcIsAvailable() => #if TargetsWindows !PlatformDetection.IsWindowsNanoServer && (!PlatformDetection.IsWindowsServerCore || Environment.Is64BitProcess); #else - Interop.Libdl.dlopen(Interop.Libraries.Odbc32, Interop.Libdl.RTLD_NOW) != IntPtr.Zero; + NativeLibrary.TryLoad(Interop.Libraries.Odbc32, out _); #endif } } diff --git a/src/System.Drawing.Common/src/System/Drawing/GdiplusNative.Unix.cs b/src/System.Drawing.Common/src/System/Drawing/GdiplusNative.Unix.cs index de791b304a8c..c0489becafd0 100644 --- a/src/System.Drawing.Common/src/System/Drawing/GdiplusNative.Unix.cs +++ b/src/System.Drawing.Common/src/System/Drawing/GdiplusNative.Unix.cs @@ -32,7 +32,7 @@ private static IntPtr LoadNativeLibrary() if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { libraryName = "libgdiplus.dylib"; - lib = Interop.Libdl.dlopen(libraryName, Interop.Libdl.RTLD_NOW); + lib = Interop.Libdl.dlopen(libraryName, Interop.Libdl.RTLD_LAZY); } else { @@ -41,10 +41,10 @@ private static IntPtr LoadNativeLibrary() // a global configuration setting. We prefer the "unversioned" shared object name, and fallback to // the name suffixed with ".0". libraryName = "libgdiplus.so"; - lib = Interop.Libdl.dlopen(libraryName, Interop.Libdl.RTLD_NOW); + lib = Interop.Libdl.dlopen(libraryName, Interop.Libdl.RTLD_LAZY); if (lib == IntPtr.Zero) { - lib = Interop.Libdl.dlopen("libgdiplus.so.0", Interop.Libdl.RTLD_NOW); + lib = Interop.Libdl.dlopen("libgdiplus.so.0", Interop.Libdl.RTLD_LAZY); } } @@ -58,7 +58,7 @@ private static IntPtr LoadNativeLibrary() { var searchPath = Path.Combine(searchDirectory, libraryName); - lib = Interop.Libdl.dlopen(searchPath, Interop.Libdl.RTLD_NOW); + lib = Interop.Libdl.dlopen(searchPath, Interop.Libdl.RTLD_LAZY); if (lib != IntPtr.Zero) { diff --git a/src/System.Drawing.Common/src/System/Drawing/Printing/LibcupsNative.cs b/src/System.Drawing.Common/src/System/Drawing/Printing/LibcupsNative.cs index 6d243f7021ea..cff2025fb49c 100644 --- a/src/System.Drawing.Common/src/System/Drawing/Printing/LibcupsNative.cs +++ b/src/System.Drawing.Common/src/System/Drawing/Printing/LibcupsNative.cs @@ -15,10 +15,10 @@ internal static class LibcupsNative private static IntPtr LoadLibcups() { // We allow both "libcups.so" and "libcups.so.2" to be loaded. - IntPtr lib = Interop.Libdl.dlopen("libcups.so", Interop.Libdl.RTLD_NOW); + IntPtr lib = Interop.Libdl.dlopen("libcups.so", Interop.Libdl.RTLD_LAZY); if (lib == IntPtr.Zero) { - lib = Interop.Libdl.dlopen("libcups.so.2", Interop.Libdl.RTLD_NOW); + lib = Interop.Libdl.dlopen("libcups.so.2", Interop.Libdl.RTLD_LAZY); } return lib;