diff options
8 files changed, 69 insertions, 30 deletions
diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h index 8b14cc2a0ec..9a91c79feac 100644 --- a/lldb/include/lldb/Target/Platform.h +++ b/lldb/include/lldb/Target/Platform.h @@ -569,7 +569,7 @@ namespace lldb_private { // Appends the platform-specific options required to find the modules for the current platform. virtual void - AddClangModuleCompilationOptions (std::vector<std::string> &options); + AddClangModuleCompilationOptions (Target *target, std::vector<std::string> &options); ConstString GetWorkingDirectory (); diff --git a/lldb/source/Expression/ClangModulesDeclVendor.cpp b/lldb/source/Expression/ClangModulesDeclVendor.cpp index 46adaaff33c..b1ce44a847d 100644 --- a/lldb/source/Expression/ClangModulesDeclVendor.cpp +++ b/lldb/source/Expression/ClangModulesDeclVendor.cpp @@ -289,7 +289,7 @@ ClangModulesDeclVendor::Create(Target &target) "-Werror=non-modular-include-in-framework-module" }; - target.GetPlatform()->AddClangModuleCompilationOptions(compiler_invocation_arguments); + target.GetPlatform()->AddClangModuleCompilationOptions(&target, compiler_invocation_arguments); compiler_invocation_arguments.push_back(ModuleImportBufferName); diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index cf1d1529f2e..5fb43c6d4c1 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1419,7 +1419,7 @@ PlatformDarwin::GetSDKDirectoryForModules (SDKType sdk_type) } void -PlatformDarwin::AddClangModuleCompilationOptionsForSDKType (std::vector<std::string> &options, SDKType sdk_type) +PlatformDarwin::AddClangModuleCompilationOptionsForSDKType (Target *target, std::vector<std::string> &options, SDKType sdk_type) { const std::vector<std::string> apple_arguments = { @@ -1435,28 +1435,67 @@ PlatformDarwin::AddClangModuleCompilationOptionsForSDKType (std::vector<std::str apple_arguments.end()); StreamString minimum_version_option; - unsigned int major = 0, minor = 0, micro = 0; - GetOSVersion(major, minor, micro); - if (micro == UINT32_MAX) - micro = 0; // FIXME who actually likes this behavior? - + uint32_t versions[3] = { 0, 0, 0 }; + bool use_current_os_version = false; switch (sdk_type) { - case SDKType::iPhoneOS: - minimum_version_option.PutCString("-mios-version-min="); - minimum_version_option.PutCString(clang::VersionTuple(major, minor, micro).getAsString().c_str()); - break; - case SDKType::iPhoneSimulator: - minimum_version_option.PutCString("-mios-simulator-version-min="); - minimum_version_option.PutCString(clang::VersionTuple(major, minor, micro).getAsString().c_str()); - break; - case SDKType::MacOSX: - minimum_version_option.PutCString("-mmacosx-version-min="); - minimum_version_option.PutCString(clang::VersionTuple(major, minor, micro).getAsString().c_str()); + case SDKType::iPhoneOS: +#if defined (__arm__) || defined (__arm64__) || defined (__aarch64__) + use_current_os_version = true; +#else + use_current_os_version = false; +#endif + break; + + case SDKType::iPhoneSimulator: + use_current_os_version = false; + break; + + case SDKType::MacOSX: +#if defined (__i386__) || defined (__x86_64__) + use_current_os_version = true; +#else + use_current_os_version = false; +#endif + break; } - - options.push_back(minimum_version_option.GetString()); - + + if (use_current_os_version) + GetOSVersion(versions[0], versions[1], versions[2]); + else if (target) + { + // Our OS doesn't match our executable so we need to get the min OS version from the object file + ModuleSP exe_module_sp = target->GetExecutableModule(); + if (exe_module_sp) + { + ObjectFile *object_file = exe_module_sp->GetObjectFile(); + if (object_file) + object_file->GetMinimumOSVersion(versions, 3); + } + } + // Only add the version-min options if we got a version from somewhere + if (versions[0]) + { + if (versions[2] == UINT32_MAX) + versions[2] = 0; // FIXME who actually likes this behavior? + + switch (sdk_type) + { + case SDKType::iPhoneOS: + minimum_version_option.PutCString("-mios-version-min="); + minimum_version_option.PutCString(clang::VersionTuple(versions[0], versions[1], versions[2]).getAsString().c_str()); + break; + case SDKType::iPhoneSimulator: + minimum_version_option.PutCString("-mios-simulator-version-min="); + minimum_version_option.PutCString(clang::VersionTuple(versions[0], versions[1], versions[2]).getAsString().c_str()); + break; + case SDKType::MacOSX: + minimum_version_option.PutCString("-mmacosx-version-min="); + minimum_version_option.PutCString(clang::VersionTuple(versions[0], versions[1], versions[2]).getAsString().c_str()); + } + options.push_back(minimum_version_option.GetString()); + } + FileSpec sysroot_spec = GetSDKDirectoryForModules(sdk_type); if (sysroot_spec.IsDirectory()) diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h index 980d8a8d280..cdc69a64448 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h @@ -130,7 +130,7 @@ protected: GetSDKDirectoryForModules (PlatformDarwin::SDKType sdk_type); void - AddClangModuleCompilationOptionsForSDKType (std::vector<std::string> &options, SDKType sdk_type); + AddClangModuleCompilationOptionsForSDKType (lldb_private::Target *target, std::vector<std::string> &options, SDKType sdk_type); std::string m_developer_directory; diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.h b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.h index 37768bc924d..bef8e98a922 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.h @@ -99,9 +99,9 @@ public: GetSDKDirectory (lldb_private::Target &target) override; void - AddClangModuleCompilationOptions (std::vector<std::string> &options) override + AddClangModuleCompilationOptions (lldb_private::Target *target, std::vector<std::string> &options) override { - return PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(options, PlatformDarwin::SDKType::MacOSX); + return PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(target, options, PlatformDarwin::SDKType::MacOSX); } private: diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h index ba8c0af8a55..2911b7fc42f 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h @@ -97,9 +97,9 @@ public: lldb_private::ArchSpec &arch) override; void - AddClangModuleCompilationOptions (std::vector<std::string> &options) override + AddClangModuleCompilationOptions (lldb_private::Target *target, std::vector<std::string> &options) override { - return PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(options, PlatformDarwin::SDKType::iPhoneOS); + return PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(target, options, PlatformDarwin::SDKType::iPhoneOS); } protected: diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h b/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h index 9b24e3370c8..4cb336a2322 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h @@ -99,9 +99,9 @@ public: lldb_private::ArchSpec &arch) override; void - AddClangModuleCompilationOptions (std::vector<std::string> &options) override + AddClangModuleCompilationOptions (lldb_private::Target *target, std::vector<std::string> &options) override { - return PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(options, PlatformDarwin::SDKType::iPhoneSimulator); + return PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(target, options, PlatformDarwin::SDKType::iPhoneSimulator); } protected: diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp index f9f289e9d06..83a8769953f 100644 --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -463,7 +463,7 @@ Platform::GetOSKernelDescription (std::string &s) } void -Platform::AddClangModuleCompilationOptions (std::vector<std::string> &options) +Platform::AddClangModuleCompilationOptions (Target *target, std::vector<std::string> &options) { std::vector<std::string> default_compilation_options = { |