diff --git a/src/coreclr/tools/Common/CommandLineHelpers.cs b/src/coreclr/tools/Common/CommandLineHelpers.cs index d1282b416f779..39161e2c753b0 100644 --- a/src/coreclr/tools/Common/CommandLineHelpers.cs +++ b/src/coreclr/tools/Common/CommandLineHelpers.cs @@ -69,17 +69,19 @@ public static TargetOS GetTargetOS(string token) throw new NotImplementedException(); } - - if (token.Equals("windows", StringComparison.OrdinalIgnoreCase)) - return TargetOS.Windows; - else if (token.Equals("linux", StringComparison.OrdinalIgnoreCase)) - return TargetOS.Linux; - else if (token.Equals("osx", StringComparison.OrdinalIgnoreCase)) - return TargetOS.OSX; - else if (token.Equals("freebsd", StringComparison.OrdinalIgnoreCase)) - return TargetOS.FreeBSD; - - throw new CommandLineException($"Target OS '{token}' is not supported"); + else + { + return token.ToLowerInvariant() switch + { + "windows" => TargetOS.Windows, + "linux" => TargetOS.Linux, + "freebsd" => TargetOS.FreeBSD, + "osx" => TargetOS.OSX, + "ios" => TargetOS.iOS, + "iossimulator" => TargetOS.iOSSimulator, + _ => throw new CommandLineException($"Target OS '{token}' is not supported") + }; + } } public static TargetArchitecture GetTargetArchitecture(string token) @@ -96,19 +98,18 @@ public static TargetArchitecture GetTargetArchitecture(string token) _ => throw new NotImplementedException() }; } - - if (token.Equals("x86", StringComparison.OrdinalIgnoreCase)) - return TargetArchitecture.X86; - else if (token.Equals("x64", StringComparison.OrdinalIgnoreCase)) - return TargetArchitecture.X64; - else if (token.Equals("arm", StringComparison.OrdinalIgnoreCase) || token.Equals("armel", StringComparison.OrdinalIgnoreCase)) - return TargetArchitecture.ARM; - else if (token.Equals("arm64", StringComparison.OrdinalIgnoreCase)) - return TargetArchitecture.ARM64; - else if (token.Equals("loongarch64", StringComparison.OrdinalIgnoreCase)) - return TargetArchitecture.LoongArch64; - - throw new CommandLineException($"Target architecture '{token}' is not supported"); + else + { + return token.ToLowerInvariant() switch + { + "x86" => TargetArchitecture.X86, + "x64" => TargetArchitecture.X64, + "arm" or "armel" => TargetArchitecture.ARM, + "arm64" => TargetArchitecture.ARM64, + "loongarch64" => TargetArchitecture.LoongArch64, + _ => throw new CommandLineException($"Target architecture '{token}' is not supported") + }; + } } public static void MakeReproPackage(string makeReproPath, string outputFilePath, string[] args, ParseResult res, IEnumerable inputOptions, IEnumerable outputOptions = null) diff --git a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_X64/TargetRegisterMap.cs b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_X64/TargetRegisterMap.cs index f377441b0d486..3d87424ae9863 100644 --- a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_X64/TargetRegisterMap.cs +++ b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_X64/TargetRegisterMap.cs @@ -29,20 +29,13 @@ public TargetRegisterMap(TargetOS os) Arg3 = Register.R9; Result = Register.RAX; break; - - case TargetOS.Linux: - case TargetOS.OSX: - case TargetOS.FreeBSD: - case TargetOS.SunOS: - case TargetOS.NetBSD: + default: Arg0 = Register.RDI; Arg1 = Register.RSI; Arg2 = Register.RDX; Arg3 = Register.RCX; Result = Register.RAX; break; - default: - throw new NotImplementedException(); } } } diff --git a/src/coreclr/tools/Common/Internal/Runtime/EETypeBuilderHelpers.cs b/src/coreclr/tools/Common/Internal/Runtime/EETypeBuilderHelpers.cs index 34aa52ae43c81..ca426c113d28c 100644 --- a/src/coreclr/tools/Common/Internal/Runtime/EETypeBuilderHelpers.cs +++ b/src/coreclr/tools/Common/Internal/Runtime/EETypeBuilderHelpers.cs @@ -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; } diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index df7d878490116..c092df8c478c1 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -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) diff --git a/src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs b/src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs index ef77bfa5d10df..39a3c20f45a20 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs @@ -19,6 +19,8 @@ public enum TargetOS NetBSD, SunOS, WebAssembly, + iOS, + iOSSimulator } public enum TargetAbi @@ -303,13 +305,16 @@ public bool IsWindows } /// - /// Returns True if compiling for OSX + /// Returns True if compiling for OSX family of operating systems. + /// Currently including OSX, iOS and iOSSimulator /// - public bool IsOSX + public bool IsOSXLike { get { - return OperatingSystem == TargetOS.OSX; + return OperatingSystem == TargetOS.OSX || + OperatingSystem == TargetOS.iOS || + OperatingSystem == TargetOS.iOSSimulator; } } diff --git a/src/coreclr/tools/Common/TypeSystem/Interop/IL/MarshalHelpers.cs b/src/coreclr/tools/Common/TypeSystem/Interop/IL/MarshalHelpers.cs index 6402d5e535a2a..cb80143d94250 100644 --- a/src/coreclr/tools/Common/TypeSystem/Interop/IL/MarshalHelpers.cs +++ b/src/coreclr/tools/Common/TypeSystem/Interop/IL/MarshalHelpers.cs @@ -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"; @@ -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 diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ObjectWriter.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ObjectWriter.cs index 6b728ccb3405a..120e9a81692ca 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ObjectWriter.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ObjectWriter.cs @@ -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 // linker bug which would produce DWARF with incorrect pcStart offsets for @@ -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('_'); } @@ -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)) @@ -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"; diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ExportsFileWriter.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ExportsFileWriter.cs index 4a0929729b47f..9937ecacc986c 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ExportsFileWriter.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ExportsFileWriter.cs @@ -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()}"); diff --git a/src/coreclr/tools/aot/ILCompiler/ConfigurablePInvokePolicy.cs b/src/coreclr/tools/aot/ILCompiler/ConfigurablePInvokePolicy.cs index f5f634c06f12d..78f218a61be47 100644 --- a/src/coreclr/tools/aot/ILCompiler/ConfigurablePInvokePolicy.cs +++ b/src/coreclr/tools/aot/ILCompiler/ConfigurablePInvokePolicy.cs @@ -91,7 +91,7 @@ private IEnumerable 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); diff --git a/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs b/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs index bfbb1fed9c509..235b7443e5548 100644 --- a/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs +++ b/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs @@ -306,7 +306,7 @@ public static IEnumerable> GetExtendedHelp(HelpContext _) "considered to be input files. If no input files begin with '--' then this option is not necessary.\n"); string[] ValidArchitectures = new string[] { "arm", "arm64", "x86", "x64" }; - string[] ValidOS = new string[] { "windows", "linux", "osx", "freebsd" }; + string[] ValidOS = new string[] { "windows", "linux", "freebsd", "osx", "ios", "iossimulator" }; Console.WriteLine("Valid switches for {0} are: '{1}'. The default value is '{2}'\n", "--targetos", string.Join("', '", ValidOS), Helpers.GetTargetOS(null).ToString().ToLowerInvariant());