[Lldb-commits] [PATCH] D89428: Add support for more OS types to AddClangModuleCompilationOptionsForSDKType()

Adrian Prantl via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 14 14:33:40 PDT 2020


aprantl created this revision.
aprantl added reviewers: JDevlieghere, teemperor.
aprantl requested review of this revision.

[This is upstreaming an Apple Silicon support patch rdar://problem/66927829]

This patch also avoids hardcoding the clang options, which makes it less likely for them to become out-of-date.

      

rdar://problem/63791367


https://reviews.llvm.org/D89428

Files:
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp


Index: lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
===================================================================
--- lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -1521,25 +1521,20 @@
 
   StreamString minimum_version_option;
   bool use_current_os_version = false;
+  // If the SDK type is for the host OS, use its version number.
+  auto get_host_os = []() { return HostInfo::GetTargetTriple().getOS(); };
   switch (sdk_type) {
+  case XcodeSDK::Type::MacOSX:
+    use_current_os_version = get_host_os() == llvm::Triple::MacOSX;
+    break;
   case XcodeSDK::Type::iPhoneOS:
-#if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
-    use_current_os_version = true;
-#else
-    use_current_os_version = false;
-#endif
+    use_current_os_version = get_host_os() == llvm::Triple::IOS;
     break;
-
-  case XcodeSDK::Type::iPhoneSimulator:
-    use_current_os_version = false;
+  case XcodeSDK::Type::AppleTVOS:
+    use_current_os_version = get_host_os() == llvm::Triple::TvOS;
     break;
-
-  case XcodeSDK::Type::MacOSX:
-#if defined(__i386__) || defined(__x86_64__)
-    use_current_os_version = true;
-#else
-    use_current_os_version = false;
-#endif
+  case XcodeSDK::Type::watchOS:
+    use_current_os_version = get_host_os() == llvm::Triple::WatchOS;
     break;
   default:
     break;
@@ -1559,31 +1554,40 @@
     }
   }
   // Only add the version-min options if we got a version from somewhere
-  if (!version.empty()) {
+  if (!version.empty() && sdk_type != XcodeSDK::Type::Linux) {
+#define OPTION(PREFIX, NAME, VAR, ...) const char *opt_##VAR = NAME;
+#include "clang/Driver/Options.inc"
+#undef OPTION
+    minimum_version_option.PutCString("-");
     switch (sdk_type) {
-    case XcodeSDK::Type::iPhoneOS:
-      minimum_version_option.PutCString("-mios-version-min=");
-      minimum_version_option.PutCString(version.getAsString());
+    case XcodeSDK::Type::MacOSX:
+      minimum_version_option.PutCString(opt_mmacosx_version_min_EQ);
       break;
     case XcodeSDK::Type::iPhoneSimulator:
-      minimum_version_option.PutCString("-mios-simulator-version-min=");
-      minimum_version_option.PutCString(version.getAsString());
+      minimum_version_option.PutCString(opt_mios_simulator_version_min_EQ);
       break;
-    case XcodeSDK::Type::MacOSX:
-      minimum_version_option.PutCString("-mmacosx-version-min=");
-      minimum_version_option.PutCString(version.getAsString());
+    case XcodeSDK::Type::iPhoneOS:
+      minimum_version_option.PutCString(opt_mios_version_min_EQ);
+      break;
+    case XcodeSDK::Type::AppleTVSimulator:
+      minimum_version_option.PutCString(opt_mtvos_simulator_version_min_EQ);
+      break;
+    case XcodeSDK::Type::AppleTVOS:
+      minimum_version_option.PutCString(opt_mtvos_simulator_version_min_EQ);
       break;
     case XcodeSDK::Type::WatchSimulator:
-      minimum_version_option.PutCString("-mwatchos-simulator-version-min=");
-      minimum_version_option.PutCString(version.getAsString());
+      minimum_version_option.PutCString(opt_mwatchos_simulator_version_min_EQ);
       break;
-    case XcodeSDK::Type::AppleTVSimulator:
-      minimum_version_option.PutCString("-mtvos-version-min=");
-      minimum_version_option.PutCString(version.getAsString());
+    case XcodeSDK::Type::watchOS:
+      minimum_version_option.PutCString(opt_mwatchos_version_min_EQ);
       break;
-    default:
+    case XcodeSDK::Type::bridgeOS:
+      minimum_version_option.PutCString(opt_mwatchos_version_min_EQ);
+      break;
+    case XcodeSDK::Type::Linux:
       llvm_unreachable("unsupported sdk");
     }
+    minimum_version_option.PutCString(version.getAsString());
     options.push_back(std::string(minimum_version_option.GetString()));
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89428.298239.patch
Type: text/x-patch
Size: 3834 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20201014/88256695/attachment-0001.bin>


More information about the lldb-commits mailing list