public static IEnumerable <AssemblyDefinition> GetAssemblies(this LinkContext context) { return(LinkerConfiguration.GetInstance(context).Assemblies); }
void ProcessMethod(MethodDefinition method) { if (method.IsPInvokeImpl && method.HasPInvokeInfo && method.PInvokeInfo != null) { var pinfo = method.PInvokeInfo; bool addPInvokeSymbol = false; if (state != null) { switch (pinfo.EntryPoint) { case "objc_msgSend": case "objc_msgSendSuper": case "objc_msgSend_stret": case "objc_msgSendSuper_stret": case "objc_msgSend_fpret": state.ProcessMethod(method); break; default: break; } } #if NET // Create a list of all the libraries from Mono that we'll link with // We add 4 different variations for each library: // * with and without a "lib" prefix // * with and without the ".dylib" extension var app = LinkerConfiguration.GetInstance(Context).Application; var monoLibraryVariations = app.MonoLibraries. Where(v => v.EndsWith(".dylib", StringComparison.OrdinalIgnoreCase) || v.EndsWith(".a", StringComparison.OrdinalIgnoreCase)). Select(v => Path.GetFileNameWithoutExtension(v)). Select(v => v.StartsWith("lib", StringComparison.OrdinalIgnoreCase) ? v.Substring(3) : v).ToHashSet(); monoLibraryVariations.UnionWith(monoLibraryVariations.Select(v => "lib" + v).ToArray()); monoLibraryVariations.UnionWith(monoLibraryVariations.Select(v => v + ".dylib").ToArray()); // If the P/Invoke points to any of those libraries, then we add it as a P/Invoke symbol. if (monoLibraryVariations.Contains(pinfo.Module.Name)) { addPInvokeSymbol = true; } #endif switch (pinfo.Module.Name) { case "__Internal": Driver.Log(4, "Adding native reference to {0} in {1} because it's referenced by {2} in {3}.", pinfo.EntryPoint, pinfo.Module.Name, method.FullName, method.Module.Name); DerivedLinkContext.RequiredSymbols.AddFunction(pinfo.EntryPoint).AddMember(method); break; #if !NET case "System.Net.Security.Native": case "System.Security.Cryptography.Native.Apple": case "System.Native": addPInvokeSymbol = true; break; #endif default: if (!addPInvokeSymbol) { Driver.Log(4, "Did not add native reference to {0} in {1} referenced by {2} in {3}.", pinfo.EntryPoint, pinfo.Module.Name, method.FullName, method.Module.Name); } break; } if (addPInvokeSymbol) { Driver.Log(4, "Adding native reference to {0} in {1} because it's referenced by {2} in {3}.", pinfo.EntryPoint, pinfo.Module.Name, method.FullName, method.Module.Name); DerivedLinkContext.RequireMonoNative = true; if (DerivedLinkContext.App.Platform != ApplePlatform.MacOSX && DerivedLinkContext.App.LibMonoNativeLinkMode == AssemblyBuildTarget.StaticObject) { DerivedLinkContext.RequiredSymbols.AddFunction(pinfo.EntryPoint).AddMember(method); } } } if (method.IsPropertyMethod()) { var property = method.GetProperty(); object symbol; // The Field attribute may have been linked away, but we've stored it in an annotation. if (property != null && Annotations.GetCustomAnnotations("ExportedFields").TryGetValue(property, out symbol)) { DerivedLinkContext.RequiredSymbols.AddField((string)symbol).AddMember(property); } } }