diff --git a/src/ILLink.Substitutions.ios.xml b/src/ILLink.Substitutions.ios.xml index b14bda1595..fc0689edbd 100644 --- a/src/ILLink.Substitutions.ios.xml +++ b/src/ILLink.Substitutions.ios.xml @@ -1,5 +1,8 @@ + + + diff --git a/src/ILLink.Substitutions.tvos.xml b/src/ILLink.Substitutions.tvos.xml index 2212cc5448..c74fa9685e 100644 --- a/src/ILLink.Substitutions.tvos.xml +++ b/src/ILLink.Substitutions.tvos.xml @@ -1,5 +1,8 @@ + + + diff --git a/src/ObjCRuntime/Dlfcn.cs b/src/ObjCRuntime/Dlfcn.cs index 9826b2d450..4a96172152 100644 --- a/src/ObjCRuntime/Dlfcn.cs +++ b/src/ObjCRuntime/Dlfcn.cs @@ -49,20 +49,20 @@ namespace ObjCRuntime { static partial class Libraries { #if !COREBUILD static public class System { - static public readonly IntPtr Handle = Dlfcn.dlopen (Constants.libSystemLibrary, 0); + static public readonly IntPtr Handle = Dlfcn._dlopen (Constants.libSystemLibrary, 0); } static public class LibC { - static public readonly IntPtr Handle = Dlfcn.dlopen (Constants.libcLibrary, 0); + static public readonly IntPtr Handle = Dlfcn._dlopen (Constants.libcLibrary, 0); } #if HAS_OPENGLES static public class OpenGLES { - static public readonly IntPtr Handle = Dlfcn.dlopen (Constants.OpenGLESLibrary, 0); + static public readonly IntPtr Handle = Dlfcn._dlopen (Constants.OpenGLESLibrary, 0); } #endif #if !WATCH static public class AudioToolbox { - static public readonly IntPtr Handle = Dlfcn.dlopen (Constants.AudioToolboxLibrary, 0); + static public readonly IntPtr Handle = Dlfcn._dlopen (Constants.AudioToolboxLibrary, 0); } #endif #endif @@ -98,10 +98,18 @@ namespace ObjCRuntime { public static IntPtr dlopen (string path, int mode) { - return dlopen (path, mode, true); + return dlopen (path, mode, showWarning: true); } static bool warningShown; + // the linker can eliminate the body of this method (and the above static variable) on release builds + static void WarnOnce () + { + if (!warningShown) + Runtime.NSLog ("You are using dlopen without a full path, retrying by prepending /usr/lib"); + warningShown = true; + } + internal static IntPtr dlopen (string path, int mode, bool showWarning) { var x = _dlopen (path, mode); @@ -112,14 +120,9 @@ namespace ObjCRuntime { // In iOS >= 9, this fails with: // "no cache image with name ()" if (path.IndexOf ('/') == -1){ - if (!warningShown && showWarning) { - Runtime.NSLog ("You are using dlopen without a full path, retrying by prepending /usr/lib"); - warningShown = true; - } - - x = _dlopen ("/usr/lib/" + path, mode); - if (x != IntPtr.Zero) - return x; + if (showWarning) + WarnOnce (); + return dlopen ("/usr/lib/" + path, mode, false); } return IntPtr.Zero; } diff --git a/src/generator.cs b/src/generator.cs index 61291bea58..4517b6d2b8 100644 --- a/src/generator.cs +++ b/src/generator.cs @@ -2745,8 +2745,12 @@ public partial class Generator : IMemberGatherer { print ("static public readonly IntPtr Handle = Dlfcn.dlopen (null, 0);"); } else if (BindThirdPartyLibrary && library_path != null && IsNotSystemLibrary (library_name)) { print ($"static public readonly IntPtr Handle = Dlfcn.dlopen (\"{library_path}\", 0);"); - } else { + } else if (BindThirdPartyLibrary) { print ("static public readonly IntPtr Handle = Dlfcn.dlopen (Constants.{0}Library, 0);", library_name); + } else { + // Skip the path check that our managed `dlopen` method does + // This is not required since the path is checked by `IsNotSystemLibrary` + print ("static public readonly IntPtr Handle = Dlfcn._dlopen (Constants.{0}Library, 0);", library_name); } indent--; print ("}"); }