Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp =================================================================== --- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -5024,7 +5024,18 @@ auto triple = base_triple; triple.setOSName(os.str()); - os_name.clear(); + + // Disambiguate legacy simulator platforms. + if (base_triple.getArch() == llvm::Triple::x86_64 || + base_triple.getArch() == llvm::Triple::x86) { + // The combination of legacy LC_VERSION_MIN load command and + // x86 architecture always indicates a simulator environment. + // The combination of LC_VERSION_MIN and arm architecture only + // appears for native binaries. Back-deploying simulator + // binaries on Apple Silicon Macs use the modern unambigous + // LC_BUILD_VERSION load commands; no special handling required. + triple.setEnvironment(llvm::Triple::Simulator); + } add_triple(triple); break; } Index: lldb/source/Utility/ArchSpec.cpp =================================================================== --- lldb/source/Utility/ArchSpec.cpp +++ lldb/source/Utility/ArchSpec.cpp @@ -1057,20 +1057,6 @@ return true; } - if (lhs_triple_os != rhs_triple_os) { - const bool rhs_os_specified = rhs.TripleOSWasSpecified(); - const bool lhs_os_specified = TripleOSWasSpecified(); - // Both architectures had the OS specified, so if they aren't equal then - // we return false - if (rhs_os_specified && lhs_os_specified) - return false; - - // Only fail if both os types are not unknown - if (lhs_triple_os != llvm::Triple::UnknownOS && - rhs_triple_os != llvm::Triple::UnknownOS) - return false; - } - // x86_64-apple-ios-macabi and x86_64-apple-ios are not compatible. if (lhs_triple_os == llvm::Triple::IOS && rhs_triple_os == llvm::Triple::IOS && @@ -1079,6 +1065,19 @@ lhs_triple_env != rhs_triple_env) return false; + if (lhs_triple_os != rhs_triple_os) { + const bool lhs_os_specified = TripleOSWasSpecified(); + const bool rhs_os_specified = rhs.TripleOSWasSpecified(); + // If both OS types are specified and different, fail. + if (lhs_os_specified && rhs_os_specified) + return false; + + // If the pair of os+env is both unspecified, match any other os+env combo. + if (!exact_match && ((!lhs_os_specified && !lhs_triple.hasEnvironment()) || + (!rhs_os_specified && !rhs_triple.hasEnvironment()))) + return true; + } + return IsCompatibleEnvironment(lhs_triple_env, rhs_triple_env); } Index: lldb/test/API/macosx/simulator/TestSimulatorPlatform.py =================================================================== --- lldb/test/API/macosx/simulator/TestSimulatorPlatform.py +++ lldb/test/API/macosx/simulator/TestSimulatorPlatform.py @@ -6,7 +6,6 @@ import unittest2 -@skipIfDarwin # rdar://problem/64552748 class TestSimulatorPlatformLaunching(TestBase): mydir = TestBase.compute_mydir(__file__) Index: lldb/unittests/Utility/ArchSpecTest.cpp =================================================================== --- lldb/unittests/Utility/ArchSpecTest.cpp +++ lldb/unittests/Utility/ArchSpecTest.cpp @@ -305,6 +305,25 @@ ArchSpec B("x86_64-apple-ios-simulator"); ASSERT_FALSE(A.IsExactMatch(B)); ASSERT_FALSE(A.IsCompatibleMatch(B)); + ASSERT_FALSE(B.IsExactMatch(A)); + ASSERT_FALSE(B.IsCompatibleMatch(A)); + } + { + ArchSpec A("x86_64-apple-ios"); + ArchSpec B("x86_64-apple-ios-simulator"); + ASSERT_FALSE(A.IsExactMatch(B)); + ASSERT_FALSE(A.IsCompatibleMatch(B)); + ASSERT_FALSE(B.IsExactMatch(A)); + ASSERT_FALSE(B.IsCompatibleMatch(A)); + } + { + // FIXME: This is surprisingly not equivalent to "x86_64-*-*". + ArchSpec A("x86_64"); + ArchSpec B("x86_64-apple-ios-simulator"); + ASSERT_FALSE(A.IsExactMatch(B)); + ASSERT_TRUE(A.IsCompatibleMatch(B)); + ASSERT_FALSE(B.IsExactMatch(A)); + ASSERT_TRUE(B.IsCompatibleMatch(A)); } { ArchSpec A("arm64-apple-ios");