Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions tools/common/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public bool IsDefaultMarshalManagedExceptionMode {
public bool SkipMarkingNSObjectsInUserAssemblies { get; set; }

// How Mono should be embedded into the app.
#if !LEGACY_TOOLS
AssemblyBuildTarget? libmono_link_mode;
public AssemblyBuildTarget LibMonoLinkMode {
get {
Expand Down Expand Up @@ -192,6 +193,7 @@ public AssemblyBuildTarget LibMonoNativeLinkMode {
return libmono_link_mode.Value;
}
}
#endif // !LEGACY_TOOLS

bool RequiresXcodeHeaders {
get {
Expand Down Expand Up @@ -278,17 +280,20 @@ public Application (LinkerConfiguration configuration)
this.StaticRegistrar = new StaticRegistrar (this);
}

#if !LEGACY_TOOLS
public void CreateCache (string [] arguments)
{
Cache = new Cache (arguments);
}
#endif // !LEGACY_TOOLS

public bool DynamicRegistrationSupported {
get {
return Optimizations.RemoveDynamicRegistrar != true;
}
}

#if !LEGACY_TOOLS
public void ParseCustomLinkFlags (string value, string value_name)
{
if (!StringUtils.TryParseArguments (value, out var lf, out var ex))
Expand All @@ -310,7 +315,9 @@ public void UnsetInterpreter ()
UseInterpreter = false;
InterpretedAssemblies.Clear ();
}
#endif // !LEGACY_TOOLS

#if !LEGACY_TOOLS
public bool IsTodayExtension {
get {
return ExtensionIdentifier == "com.apple.widget-extension";
Expand Down Expand Up @@ -359,12 +366,14 @@ public string InfoPListPath {
info_plistpath = value;
}
}
#endif // !LEGACY_TOOLS

// This is just a name for this app to show in log/error messages, etc.
public string Name {
get { return Path.GetFileNameWithoutExtension (AppDirectory); }
}

#if !LEGACY_TOOLS
bool? requires_pinvoke_wrappers;
public bool RequiresPInvokeWrappers {
get {
Expand All @@ -377,6 +386,7 @@ public bool RequiresPInvokeWrappers {
requires_pinvoke_wrappers = value;
}
}
#endif // !LEGACY_TOOLS

#if !LEGACY_TOOLS
public bool RequireLinkWithAttributeForObjectiveCClassSearch;
Expand Down Expand Up @@ -625,6 +635,7 @@ public static bool IsArchEnabled (Abi abi, Abi arch)
return (abi & arch) != 0;
}

#if !LEGACY_TOOLS
public void ValidateAbi ()
{
var validAbis = new List<Abi> ();
Expand Down Expand Up @@ -662,6 +673,7 @@ public void ClearAbi ()
{
abi = default;
}
#endif // !LEGACY_TOOLS

public void ParseAbi (string abi)
{
Expand Down Expand Up @@ -730,16 +742,7 @@ public void ParseRegistrar (string v)
}
#endif // !LEGACY_TOOLS

public static string GetArchitectures (IEnumerable<Abi> abis)
{
var res = new List<string> ();

foreach (var abi in abis)
res.Add (abi.AsArchString ());

return string.Join (", ", res.ToArray ());
}

#if !LEGACY_TOOLS
public string MonoGCParams {
get {
switch (Platform) {
Expand All @@ -766,6 +769,7 @@ public string MonoGCParams {
}
}
}
#endif // !LEGACY_TOOLS

public bool IsFrameworkAvailableInSimulator (string framework)
{
Expand All @@ -775,6 +779,7 @@ public bool IsFrameworkAvailableInSimulator (string framework)
return fw.IsFrameworkAvailableInSimulator (this);
}

#if !LEGACY_TOOLS
public static bool TryParseManagedExceptionMode (string value, out MarshalManagedExceptionMode mode)
{
mode = MarshalManagedExceptionMode.Default;
Expand Down Expand Up @@ -830,6 +835,7 @@ public static bool TryParseObjectiveCExceptionMode (string value, out MarshalObj
}
return true;
}
#endif // !LEGACY_TOOLS

public void SetManagedExceptionMode ()
{
Expand Down Expand Up @@ -1164,6 +1170,7 @@ public bool UseDlsym (string assembly)
}
#endif // !LEGACY_TOOLS

#if !LEGACY_TOOLS
public bool VerifyDynamicFramework (string framework_path)
{
var framework_filename = Path.Combine (framework_path, Path.GetFileNameWithoutExtension (framework_path));
Expand All @@ -1180,6 +1187,7 @@ public bool VerifyDynamicFramework (string framework_path)

return dynamic;
}
#endif // !LEGACY_TOOLS

static Application ()
{
Expand Down
32 changes: 0 additions & 32 deletions tools/common/Assembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,38 +178,6 @@ public void ExtractNativeLinkInfo ()
}
}

IEnumerable<NativeReferenceMetadata> ReadManifest (string manifestPath)
{
var document = new XmlDocument ();
document.LoadWithoutNetworkAccess (manifestPath);

foreach (XmlNode referenceNode in document.GetElementsByTagName ("NativeReference")) {

var metadata = new NativeReferenceMetadata ();
metadata.LibraryName = Path.Combine (Path.GetDirectoryName (manifestPath)!, referenceNode.Attributes? ["Name"]?.Value!);

var attributes = new Dictionary<string, string> ();
foreach (XmlNode attribute in referenceNode.ChildNodes)
attributes [attribute.Name] = attribute.InnerText;

metadata.ForceLoad = ParseAttributeWithDefault (attributes ["ForceLoad"], false);
metadata.Frameworks = attributes ["Frameworks"];
metadata.WeakFrameworks = attributes ["WeakFrameworks"];
metadata.LinkerFlags = attributes ["LinkerFlags"];
metadata.NeedsGccExceptionHandling = ParseAttributeWithDefault (attributes ["NeedsGccExceptionHandling"], false);
metadata.IsCxx = ParseAttributeWithDefault (attributes ["IsCxx"], false);
metadata.LinkWithSwiftSystemLibraries = ParseAttributeWithDefault (attributes ["LinkWithSwiftSystemLibraries"], false);
metadata.SmartLink = ParseAttributeWithDefault (attributes ["SmartLink"], true);

// TODO - The project attributes do not contain these bits, is that OK?
//metadata.LinkTarget = (LinkTarget) Enum.Parse (typeof (LinkTarget), attributes ["LinkTarget"]);
//metadata.Dlsym = (DlsymOption)Enum.Parse (typeof (DlsymOption), attributes ["Dlsym"]);
yield return metadata;
}
}

static bool ParseAttributeWithDefault (string attribute, bool defaultValue) => string.IsNullOrEmpty (attribute) ? defaultValue : bool.Parse (attribute);

void ProcessLinkWithAttributes (AssemblyDefinition assembly)
{
//
Expand Down
4 changes: 3 additions & 1 deletion tools/common/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public static void Watch (string msg, int level)
}

static string? sdk_root;
static string? developer_directory;
static string? developer_directory = null;

public static string? SdkRoot {
get => sdk_root;
Expand Down Expand Up @@ -507,6 +507,7 @@ internal static bool ParseBool (string value, string name, bool show_error = tru
return result;
}

#if !LEGACY_TOOLS
static readonly Dictionary<string, string?> tools = new Dictionary<string, string?> ();
static string FindTool (Application app, string tool)
{
Expand Down Expand Up @@ -708,6 +709,7 @@ public static void RunStrip (Application app, IList<string> options)
{
RunXcodeTool (app, "strip", options);
}
#endif // !LEGACY_TOOLS

public static string CorlibName {
get {
Expand Down
115 changes: 0 additions & 115 deletions tools/common/MachO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,121 +269,6 @@ public static IEnumerable<MachOFile> Read (string filename)
}
}

#if MTOUCH
// Removes all architectures from the target file, except for those in 'architectures'.
// This method doesn't do anything if the target file is a thin mach-o file.
// Also it doesn't do anything if the result is an empty file (i.e. none of the
// selected architectures match any of the architectures in the file) - this is
// only because I haven't investigated what would be needed elsewhere in the link
// process when the entire file is removed. FIXME <--.
public static void SelectArchitectures (string filename, ICollection<Abi> abis)
{
var architectures = GetArchitectures (abis);
var tmpfile = filename + ".tmp";

if (abis.Count == 0)
return;

using (var fsr = new FileStream (filename, FileMode.Open, FileAccess.Read)) {
using (var reader = new BinaryReader (fsr)) {
var file = ReadFile (filename);
if (file is MachOFile) {
Driver.Log (2, "Skipping architecture selecting of '{0}', since it only contains 1 architecture.", filename);
return;
}

var fatfile = (FatFile) file;
bool any_removed = false;

// remove architectures we don't want
for (int i = fatfile.entries!.Count - 1; i >= 0; i--) {
var ff = fatfile.entries [i];
if (!architectures.Contains (ff.entry!.Architecture)) {
any_removed = true;
fatfile.entries.RemoveAt (i);
fatfile.nfat_arch--;
Driver.Log (2, "Removing architecture {0} from {1}", ff.entry.Architecture, filename);
}
}

if (!any_removed) {
Driver.Log (2, "Architecture selection of '{0}' didn't find any architectures to remove.", filename);
return;
}

if (fatfile.nfat_arch == 0) {
Driver.Log (2, "Skipping architecture selection of '{0}', none of the selected architectures match any of the architectures in the archive.", filename, architectures [0]);
return;
}

if (fatfile.nfat_arch == 1) {
// Thin file
var entry = fatfile.entries [0];
using (var fsw = new FileStream (tmpfile, FileMode.Create, FileAccess.Write)) {
using (var writer = new BinaryWriter (fsw)) {
entry.WriteFile (writer, reader, entry.offset);
}
}
} else {
// Fat file
// Re-calculate header data
var read_offset = new List<uint> (fatfile.entries.Count);
read_offset.Add (fatfile.entries [0].offset);
fatfile.entries [0].offset = (uint) (1 << (int) fatfile.entries [0].align);
for (int i = 1; i < fatfile.entries.Count; i++) {
read_offset.Add (fatfile.entries [i].offset);
fatfile.entries [i].offset = fatfile.entries [i - 1].offset + fatfile.entries [i - 1].size;
var alignSize = (1 << (int) fatfile.entries [i].align);
var align = (int) fatfile.entries [i].offset % alignSize;
if (align != 0)
fatfile.entries [i].offset += (uint) (alignSize - align);
}
// Write out the fat file
using (var fsw = new FileStream (tmpfile, FileMode.Create, FileAccess.Write)) {
using (var writer = new BinaryWriter (fsw)) {
// write headers
fatfile.WriteHeaders (writer);
// write data
for (int i = 0; i < fatfile.entries.Count; i++) {
fatfile.entries [i].Write (writer, reader, read_offset [i]);
}
}
}
}
}
}

File.Delete (filename);
File.Move (tmpfile, filename);
}
#endif

static Dictionary<string, IEnumerable<string>> native_dependencies = new Dictionary<string, IEnumerable<string>> ();

public static IEnumerable<string> GetNativeDependencies (string libraryName)
{
IEnumerable<string>? result;
lock (native_dependencies) {
if (native_dependencies.TryGetValue (libraryName, out result))
return result;
}

var macho_files = Read (libraryName);
var dependencies = new HashSet<string> ();
foreach (var macho_file in macho_files) {
foreach (var lc in macho_file.load_commands) {
var dyld_lc = lc as Xamarin.DylibLoadCommand;
if (dyld_lc?.name is not null) {
dependencies.Add (dyld_lc.name);
}
}
}
result = dependencies;
lock (native_dependencies)
native_dependencies.Add (libraryName, result);
return result;
}

public static List<Abi> GetArchitectures (string file)
{
var result = new List<Abi> ();
Expand Down
Loading
Loading