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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#nullable disable
#nullable enable

using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -53,7 +53,7 @@ public override string GetComment (object data, string fieldName)
sealed class DSOCacheEntry
{
[NativeAssembler (Ignore = true)]
public string HashedName;
public string? HashedName;

[NativeAssembler (UsesDataProvider = true, NumberFormat = LlvmIrVariableNumberFormat.Hexadecimal)]
public ulong hash;
Expand All @@ -63,7 +63,7 @@ sealed class DSOCacheEntry
public bool ignore;

[NativeAssembler (UsesDataProvider = true)]
public string name;
public string? name;
public IntPtr handle = IntPtr.Zero;
}

Expand Down Expand Up @@ -102,7 +102,7 @@ sealed class AssemblyStoreSingleAssemblyRuntimeData
public byte config_data;

[NativePointer]
public AssemblyStoreAssemblyDescriptor descriptor;
public AssemblyStoreAssemblyDescriptor? descriptor;
}

// Order of fields and their type must correspond *exactly* to that in
Expand All @@ -115,7 +115,7 @@ sealed class AssemblyStoreRuntimeData
public uint index_entry_count;

[NativePointer (IsNull = true)]
public AssemblyStoreAssemblyDescriptor assemblies;
public AssemblyStoreAssemblyDescriptor? assemblies;
}

sealed class XamarinAndroidBundledAssemblyContextDataProvider : NativeAssemblerStructContextDataProvider
Expand Down Expand Up @@ -143,7 +143,7 @@ sealed class XamarinAndroidBundledAssembly
public int file_fd;

[NativeAssembler (UsesDataProvider = true), NativePointer (PointsToPreAllocatedBuffer = true)]
public string file_name;
public string? file_name;
public uint data_offset;
public uint data_size;

Expand All @@ -152,7 +152,7 @@ sealed class XamarinAndroidBundledAssembly
public uint name_length;

[NativeAssembler (UsesDataProvider = true), NativePointer (PointsToPreAllocatedBuffer = true)]
public string name;
public string? name;
}
#pragma warning restore CS0649

Expand All @@ -176,9 +176,9 @@ sealed class XamarinAndroidBundledAssembly
public bool UsesMonoAOT { get; set; }
public bool UsesMonoLLVM { get; set; }
public bool UsesAssemblyPreload { get; set; }
public string MonoAOTMode { get; set; }
public string MonoAOTMode { get; set; } = "";
public bool AotEnableLazyLoad { get; set; }
public string AndroidPackageName { get; set; }
public string AndroidPackageName { get; set; } = "";
public bool BrokenExceptionTransitions { get; set; }
public global::Android.Runtime.BoundExceptionType BoundExceptionType { get; set; }
public bool JniAddNativeMethodRegistrationAttributePresent { get; set; }
Expand All @@ -193,7 +193,7 @@ sealed class XamarinAndroidBundledAssembly
public int JniRemappingReplacementMethodIndexEntryCount { get; set; }
public MonoComponent MonoComponents { get; set; }
public PackageNamingPolicy PackageNamingPolicy { get; set; }
public List<ITaskItem> NativeLibraries { get; set; }
public List<ITaskItem> NativeLibraries { get; set; } = [];
public bool MarshalMethodsEnabled { get; set; }
public bool ManagedMarshalMethodsLookupEnabled { get; set; }
public bool IgnoreSplitConfigs { get; set; }
Expand All @@ -219,12 +219,12 @@ protected override void Construct (LlvmIrModule module)
module.AddGlobalVariable ("format_tag", FORMAT_TAG, comment: $" 0x{FORMAT_TAG:x}");
module.AddGlobalVariable ("mono_aot_mode_name", MonoAOTMode);

var envVars = new LlvmIrGlobalVariable (environmentVariables, "app_environment_variables") {
var envVars = new LlvmIrGlobalVariable (environmentVariables ?? new SortedDictionary<string, string>(), "app_environment_variables") {
Comment = " Application environment variables array, name:value",
};
module.Add (envVars, stringGroupName: "env.var", stringGroupComment: " Application environment variables name:value pairs");

var sysProps = new LlvmIrGlobalVariable (systemProperties, "app_system_properties") {
var sysProps = new LlvmIrGlobalVariable (systemProperties ?? new SortedDictionary<string, string>(), "app_system_properties") {
Comment = " System properties defined by the application",
};
module.Add (sysProps, stringGroupName: "sysprop", stringGroupComment: " System properties name:value pairs");
Expand Down Expand Up @@ -348,11 +348,14 @@ void HashAndSortDSOCache (LlvmIrVariable variable, LlvmIrModuleTarget target, ob
throw new InvalidOperationException ($"Internal error: DSO cache entry has unexpected type {instance.Obj.GetType ()}");
}

entry.hash = MonoAndroidHelper.GetXxHash (entry.HashedName, is64Bit);
entry.real_name_hash = MonoAndroidHelper.GetXxHash (entry.name, is64Bit);
entry.hash = MonoAndroidHelper.GetXxHash (entry.HashedName ?? "", is64Bit);
entry.real_name_hash = MonoAndroidHelper.GetXxHash (entry.name ?? "", is64Bit);
}

cache.Sort ((StructureInstance<DSOCacheEntry> a, StructureInstance<DSOCacheEntry> b) => a.Instance.hash.CompareTo (b.Instance.hash));
cache.Sort ((StructureInstance<DSOCacheEntry> a, StructureInstance<DSOCacheEntry> b) => {
if (a.Instance == null || b.Instance == null) return 0;
return a.Instance.hash.CompareTo (b.Instance.hash);
});
}

(List<StructureInstance<DSOCacheEntry>> dsoCache, List<StructureInstance<DSOCacheEntry>> aotDsoCache) InitDSOCache ()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#nullable disable
#nullable enable

using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -48,10 +48,10 @@ public override string GetComment (object data, string fieldName)
sealed class DSOCacheEntry
{
[NativeAssembler (Ignore = true)]
public string HashedName;
public string? HashedName;

[NativeAssembler (Ignore = true)]
public string RealName;
public string? RealName;

[NativeAssembler (UsesDataProvider = true, NumberFormat = LlvmIrVariableNumberFormat.Hexadecimal)]
public ulong hash;
Expand Down Expand Up @@ -100,7 +100,7 @@ sealed class AssemblyStoreSingleAssemblyRuntimeData
public byte config_data;

[NativePointer]
public AssemblyStoreAssemblyDescriptor descriptor;
public AssemblyStoreAssemblyDescriptor? descriptor;
}

// Order of fields and their type must correspond *exactly* to that in
Expand All @@ -113,7 +113,7 @@ sealed class AssemblyStoreRuntimeData
public uint index_entry_count;

[NativePointer (IsNull = true)]
public AssemblyStoreAssemblyDescriptor assemblies;
public AssemblyStoreAssemblyDescriptor? assemblies;
}

sealed class RuntimePropertyContextDataProvider : NativeAssemblerStructContextDataProvider
Expand All @@ -139,10 +139,10 @@ public override string GetComment (object data, string fieldName)
sealed class RuntimeProperty
{
[NativeAssembler (Ignore = true)]
public string Key;
public string? Key;

[NativeAssembler (Ignore = true)]
public string Value;
public string? Value;

[NativeAssembler (UsesDataProvider = true)]
public uint key_index;
Expand All @@ -157,7 +157,7 @@ sealed class RuntimeProperty
sealed class RuntimePropertyIndexEntry
{
[NativeAssembler (Ignore = true)]
public string HashedKey;
public string? HashedKey;

[NativeAssembler (NumberFormat = LlvmIrVariableNumberFormat.Hexadecimal)]
public ulong key_hash;
Expand Down Expand Up @@ -188,10 +188,10 @@ public override string GetComment (object data, string fieldName)
sealed class AppEnvironmentVariable
{
[NativeAssembler (Ignore = true)]
public string Name;
public string? Name;

[NativeAssembler (Ignore = true)]
public string Value;
public string? Value;

[NativeAssembler (UsesDataProvider = true)]
public uint name_index;
Expand Down Expand Up @@ -225,7 +225,7 @@ sealed class XamarinAndroidBundledAssembly
public int file_fd;

[NativeAssembler (UsesDataProvider = true), NativePointer (PointsToPreAllocatedBuffer = true)]
public string file_name;
public string? file_name;
public uint data_offset;
public uint data_size;

Expand All @@ -234,7 +234,7 @@ sealed class XamarinAndroidBundledAssembly
public uint name_length;

[NativeAssembler (UsesDataProvider = true), NativePointer (PointsToPreAllocatedBuffer = true)]
public string name;
public string? name;
}
#pragma warning restore CS0649

Expand Down Expand Up @@ -270,7 +270,7 @@ sealed class XamarinAndroidBundledAssembly
StructureInfo? appEnvironmentVariableStructureInfo;

public bool UsesAssemblyPreload { get; set; }
public string AndroidPackageName { get; set; }
public string AndroidPackageName { get; set; } = "";
public bool JniAddNativeMethodRegistrationAttributePresent { get; set; }
public int NumberOfAssembliesInApk { get; set; }
public int BundledAssemblyNameWidth { get; set; } // including the trailing NUL
Expand All @@ -280,7 +280,7 @@ sealed class XamarinAndroidBundledAssembly
public int JniRemappingReplacementTypeCount { get; set; }
public int JniRemappingReplacementMethodIndexEntryCount { get; set; }
public PackageNamingPolicy PackageNamingPolicy { get; set; }
public List<ITaskItem> NativeLibraries { get; set; }
public List<ITaskItem> NativeLibraries { get; set; } = [];
public bool MarshalMethodsEnabled { get; set; }
public bool ManagedMarshalMethodsLookupEnabled { get; set; }
public bool IgnoreSplitConfigs { get; set; }
Expand Down Expand Up @@ -344,7 +344,7 @@ protected override void Construct (LlvmIrModule module)
module.Add (envVars);
module.AddGlobalVariable ("app_environment_variable_contents", envVarsBlob, LlvmIrVariableOptions.GlobalConstant);

var sysProps = new LlvmIrGlobalVariable (systemProperties, "app_system_properties") {
var sysProps = new LlvmIrGlobalVariable (systemProperties ?? new SortedDictionary<string, string>(), "app_system_properties") {
Comment = " System properties defined by the application",
};
module.Add (sysProps, stringGroupName: "sysprop", stringGroupComment: " System properties name:value pairs");
Expand Down Expand Up @@ -429,12 +429,14 @@ protected override void Construct (LlvmIrModule module)
null,
};

foreach (var kvp in runtimeProperties) {
if (MonoAndroidHelper.StringEquals (kvp.Key, HOST_PROPERTY_RUNTIME_CONTRACT)) {
continue;
if (runtimeProperties != null) {
foreach (var kvp in runtimeProperties) {
if (MonoAndroidHelper.StringEquals (kvp.Key, HOST_PROPERTY_RUNTIME_CONTRACT)) {
continue;
}
runtime_property_names.Add (kvp.Key);
runtime_property_values.Add (kvp.Value);
}
runtime_property_names.Add (kvp.Key);
runtime_property_values.Add (kvp.Value);
}

var init_runtime_property_names = new LlvmIrGlobalVariable (runtime_property_names, "init_runtime_property_names", LlvmIrVariableOptions.GlobalConstant) {
Expand Down Expand Up @@ -468,10 +470,13 @@ void HashAndSortRuntimePropertiesIndex (LlvmIrVariable variable, LlvmIrModuleTar
throw new InvalidOperationException ($"Internal error: runtime property index entry has unexpected type {instance.Obj.GetType ()}");
}

entry.key_hash = MonoAndroidHelper.GetXxHash (entry.HashedKey, is64Bit);
entry.key_hash = MonoAndroidHelper.GetXxHash (entry.HashedKey ?? "", is64Bit);
};

index.Sort ((StructureInstance<RuntimePropertyIndexEntry> a, StructureInstance<RuntimePropertyIndexEntry> b) => a.Instance.key_hash.CompareTo (b.Instance.key_hash));
index.Sort ((StructureInstance<RuntimePropertyIndexEntry> a, StructureInstance<RuntimePropertyIndexEntry> b) => {
if (a.Instance == null || b.Instance == null) return 0;
return a.Instance.key_hash.CompareTo (b.Instance.key_hash);
});
}

(
Expand Down Expand Up @@ -556,11 +561,14 @@ void HashAndSortDSOCache (LlvmIrVariable variable, LlvmIrModuleTarget target, ob
throw new InvalidOperationException ($"Internal error: DSO cache entry has unexpected type {instance.Obj.GetType ()}");
}

entry.hash = MonoAndroidHelper.GetXxHash (entry.HashedName, is64Bit);
entry.real_name_hash = MonoAndroidHelper.GetXxHash (entry.RealName, is64Bit);
entry.hash = MonoAndroidHelper.GetXxHash (entry.HashedName ?? "", is64Bit);
entry.real_name_hash = MonoAndroidHelper.GetXxHash (entry.RealName ?? "", is64Bit);
}

cache.Sort ((StructureInstance<DSOCacheEntry> a, StructureInstance<DSOCacheEntry> b) => a.Instance.hash.CompareTo (b.Instance.hash));
cache.Sort ((StructureInstance<DSOCacheEntry> a, StructureInstance<DSOCacheEntry> b) => {
if (a.Instance == null || b.Instance == null) return 0;
return a.Instance.hash.CompareTo (b.Instance.hash);
});
}

(List<StructureInstance<DSOCacheEntry>> dsoCache, List<StructureInstance<DSOCacheEntry>> aotDsoCache, LlvmIrStringBlob namesBlob)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#nullable disable
#nullable enable

using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -29,15 +29,15 @@ sealed class CompressedAssemblyDescriptor
public uint Index;

[NativeAssembler (Ignore = true)]
public string AssemblyName;
public string? AssemblyName;

public uint uncompressed_file_size;
public bool loaded;
public uint buffer_offset;
};

IDictionary<AndroidTargetArch, Dictionary<string, CompressedAssemblyInfo>>? archAssemblies;
StructureInfo compressedAssemblyDescriptorStructureInfo;
StructureInfo? compressedAssemblyDescriptorStructureInfo;
Dictionary<AndroidTargetArch, List<StructureInstance<CompressedAssemblyDescriptor>>> archData = new Dictionary<AndroidTargetArch, List<StructureInstance<CompressedAssemblyDescriptor>>> ();

public CompressedAssembliesNativeAssemblyGenerator (TaskLoggingHelper log, IDictionary<AndroidTargetArch, Dictionary<string, CompressedAssemblyInfo>>? archAssemblies)
Expand Down Expand Up @@ -99,7 +99,10 @@ void InitCompressedAssemblies (out List<LlvmIrGlobalVariable>? compressedAssembl
compressedAssemblyDescriptors = new List<LlvmIrGlobalVariable> ();
foreach (var kvp in archData) {
List<StructureInstance<CompressedAssemblyDescriptor>> descriptors = kvp.Value;
descriptors.Sort ((StructureInstance<CompressedAssemblyDescriptor> a, StructureInstance<CompressedAssemblyDescriptor> b) => a.Instance.Index.CompareTo (b.Instance.Index));
descriptors.Sort ((StructureInstance<CompressedAssemblyDescriptor> a, StructureInstance<CompressedAssemblyDescriptor> b) => {
if (a.Instance == null || b.Instance == null) return 0;
return a.Instance.Index.CompareTo (b.Instance.Index);
});

var variable = new LlvmIrGlobalVariable (typeof(uint), CompressedAssemblyCountSymbolName) {
Options = LlvmIrVariableOptions.GlobalConstant,
Expand Down Expand Up @@ -139,9 +142,15 @@ out List<LlvmIrGlobalVariable>? buffers
return;
}

module.Add (compressedAssemblies);
module.Add (compressedAssemblyDescriptors);
module.Add (buffers);
if (compressedAssemblies != null) {
module.Add (compressedAssemblies);
}
if (compressedAssemblyDescriptors != null) {
module.Add (compressedAssemblyDescriptors);
}
if (buffers != null) {
module.Add (buffers);
}
}

string? GetCompressedAssemblyDescriptorsItemComment (LlvmIrVariable v, LlvmIrModuleTarget target, ulong index, object? value, object? callerState)
Expand All @@ -152,7 +161,7 @@ out List<LlvmIrGlobalVariable>? buffers
}
StructureInstance<CompressedAssemblyDescriptor> desc = descriptors[(int)index];

return $" {index}: {desc.Instance.AssemblyName}";
return $" {index}: {desc.Instance?.AssemblyName ?? ""}";
}

List<StructureInstance<CompressedAssemblyDescriptor>> GetArchDescriptors (LlvmIrModuleTarget target)
Expand Down
Loading