Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support targeting iOS platforms with ILCompiler #81476

Merged
merged 6 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions src/coreclr/tools/Common/CommandLineHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public static TargetOS GetTargetOS(string token)
return TargetOS.OSX;
else if (token.Equals("freebsd", StringComparison.OrdinalIgnoreCase))
return TargetOS.FreeBSD;
else if (token.Equals("ios", StringComparison.OrdinalIgnoreCase))
ivanpovazan marked this conversation as resolved.
Show resolved Hide resolved
return TargetOS.iOS;
else if (token.Equals("iossimulator", StringComparison.OrdinalIgnoreCase))
ivanpovazan marked this conversation as resolved.
Show resolved Hide resolved
return TargetOS.iOSSimulator;

throw new CommandLineException($"Target OS '{token}' is not supported");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,11 @@ public struct TargetRegisterMap

public TargetRegisterMap(TargetOS os)
{
switch (os)
{
case TargetOS.Windows:
Arg0 = Register.RCX;
Arg1 = Register.RDX;
Arg2 = Register.R8;
Arg3 = Register.R9;
Result = Register.RAX;
break;

case TargetOS.Linux:
case TargetOS.OSX:
case TargetOS.FreeBSD:
case TargetOS.SunOS:
case TargetOS.NetBSD:
Arg0 = Register.RDI;
Arg1 = Register.RSI;
Arg2 = Register.RDX;
Arg3 = Register.RCX;
Result = Register.RAX;
break;
default:
throw new NotImplementedException();
}
Arg0 = os == TargetOS.Windows ? Register.RCX : Register.RDI;
ivanpovazan marked this conversation as resolved.
Show resolved Hide resolved
Arg1 = os == TargetOS.Windows ? Register.RDX : Register.RSI;
Arg2 = os == TargetOS.Windows ? Register.R8 : Register.RDX;
Arg3 = os == TargetOS.Windows ? Register.R9 : Register.RCX;
Result = Register.RAX;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ mdType.Name is "WeakReference" or "WeakReference`1" &&
flagsEx |= (ushort)EETypeFlagsEx.HasCriticalFinalizerFlag;
}

if (type.Context.Target.IsOSX && IsTrackedReferenceWithFinalizer(type))
if (type.Context.Target.IsOSXLike && IsTrackedReferenceWithFinalizer(type))
{
flagsEx |= (ushort)EETypeFlagsEx.IsTrackedReferenceWithFinalizerFlag;
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3073,7 +3073,7 @@ private void ThrowExceptionForHelper(ref CORINFO_HELPER_DESC throwHelper)
public static CORINFO_OS TargetToOs(TargetDetails target)
{
return target.IsWindows ? CORINFO_OS.CORINFO_WINNT :
target.IsOSX ? CORINFO_OS.CORINFO_MACOS : CORINFO_OS.CORINFO_UNIX;
target.IsOSXLike ? CORINFO_OS.CORINFO_MACOS : CORINFO_OS.CORINFO_UNIX;
}

private void getEEInfo(ref CORINFO_EE_INFO pEEInfoOut)
Expand Down
11 changes: 8 additions & 3 deletions src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public enum TargetOS
NetBSD,
SunOS,
WebAssembly,
iOS,
iOSSimulator
}

public enum TargetAbi
Expand Down Expand Up @@ -303,13 +305,16 @@ public bool IsWindows
}

/// <summary>
/// Returns True if compiling for OSX
/// Returns True if compiling for OSX family of operating systems.
/// Currently including OSX, iOS and iOSSimulator
/// </summary>
public bool IsOSX
public bool IsOSXLike
{
get
{
return OperatingSystem == TargetOS.OSX;
return OperatingSystem == TargetOS.OSX ||
OperatingSystem == TargetOS.iOS ||
OperatingSystem == TargetOS.iOSSimulator;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ internal static MarshallerKind GetDisabledMarshallerKind(

internal static bool ShouldCheckForPendingException(TargetDetails target, PInvokeMetadata metadata)
{
if (!target.IsOSX)
if (!target.IsOSXLike)
return false;

const string ObjectiveCMsgSend = "objc_msgSend";
Expand All @@ -944,7 +944,7 @@ internal static bool ShouldCheckForPendingException(TargetDetails target, PInvok

internal static int? GetObjectiveCMessageSendFunction(TargetDetails target, string pinvokeModule, string pinvokeFunction)
{
if (!target.IsOSX || pinvokeModule != ObjectiveCLibrary)
if (!target.IsOSXLike || pinvokeModule != ObjectiveCLibrary)
return null;

#pragma warning disable CA1416
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ public void EmitCFICodes(int offset)
Debug.Assert(false);
}

if (_targetPlatform.OperatingSystem == TargetOS.OSX)
if (_targetPlatform.IsOSXLike)
{
// Emit a symbol for beginning of the frame. This is workaround for ld64
ivanpovazan marked this conversation as resolved.
Show resolved Hide resolved
// linker bug which would produce DWARF with incorrect pcStart offsets for
Expand Down Expand Up @@ -792,9 +792,9 @@ public void BuildSymbolDefinitionMap(ObjectNode node, ISymbolDefinitionNode[] de

private void AppendExternCPrefix(Utf8StringBuilder sb)
{
if (_targetPlatform.OperatingSystem == TargetOS.OSX)
if (_targetPlatform.IsOSXLike)
{
// On OSX, we need to prefix an extra underscore to account for correct linkage of
// On OSX-like systems, we need to prefix an extra underscore to account for correct linkage of
// extern "C" functions.
sb.Append('_');
}
Expand Down Expand Up @@ -908,7 +908,7 @@ private bool ShouldShareSymbol(ObjectNode node)
if (_isSingleFileCompilation)
return false;

if (_targetPlatform.OperatingSystem == TargetOS.OSX)
if (_targetPlatform.IsOSXLike)
return false;

if (!(node is ISymbolNode))
Expand Down Expand Up @@ -1250,6 +1250,16 @@ private static string GetLLVMTripleFromTarget(TargetDetails target)
sys = "darwin16";
abi = "macho";
break;
case TargetOS.iOS:
vendor = "apple";
sys = "ios11.0";
abi = "macho";
break;
case TargetOS.iOSSimulator:
vendor = "apple";
sys = "ios11.0";
abi = "simulator";
break;
case TargetOS.WebAssembly:
vendor = "unknown";
sys = "unknown";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void EmitExportedMethods()
foreach (var method in _methods)
streamWriter.WriteLine($" {method.GetUnmanagedCallersOnlyExportName()}");
}
else if(_context.Target.IsOSX)
else if(_context.Target.IsOSXLike)
{
foreach (var method in _methods)
streamWriter.WriteLine($"_{method.GetUnmanagedCallersOnlyExportName()}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ internal record struct PerfmapTokensForTarget(PerfMapOSToken OperatingSystem, Pe

private static PerfmapTokensForTarget TranslateTargetDetailsToPerfmapConstants(TargetDetails details)
{
// TODO: What about ios and iossimulator
ivanpovazan marked this conversation as resolved.
Show resolved Hide resolved
PerfMapOSToken osToken = details.OperatingSystem switch
{
TargetOS.Unknown => PerfMapOSToken.Unknown,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private IEnumerable<string> ModuleNameVariations(string name)
}
else
{
string suffix = _target.IsOSX ? ".dylib" : ".so";
string suffix = _target.IsOSXLike ? ".dylib" : ".so";

if (name.EndsWith(suffix, StringComparison.Ordinal))
yield return name.Substring(0, name.Length - suffix.Length);
Expand Down