diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp index 86e9f4de0d479f..6737ad1b57f43b 100644 --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -849,17 +849,29 @@ static std::vector parseSectAlign(const opt::InputArgList &args) { return sectAligns; } +PlatformKind macho::removeSimulator(PlatformKind platform) { + switch (platform) { + case PlatformKind::iOSSimulator: + return PlatformKind::iOS; + case PlatformKind::tvOSSimulator: + return PlatformKind::tvOS; + case PlatformKind::watchOSSimulator: + return PlatformKind::watchOS; + default: + return platform; + } +} + static bool dataConstDefault(const InputArgList &args) { - static const std::map minVersion = { + static const std::vector> minVersion = { {PlatformKind::macOS, VersionTuple(10, 15)}, {PlatformKind::iOS, VersionTuple(13, 0)}, - {PlatformKind::iOSSimulator, VersionTuple(13, 0)}, {PlatformKind::tvOS, VersionTuple(13, 0)}, - {PlatformKind::tvOSSimulator, VersionTuple(13, 0)}, {PlatformKind::watchOS, VersionTuple(6, 0)}, - {PlatformKind::watchOSSimulator, VersionTuple(6, 0)}, {PlatformKind::bridgeOS, VersionTuple(4, 0)}}; - auto it = minVersion.find(config->platformInfo.target.Platform); + PlatformKind platform = removeSimulator(config->platformInfo.target.Platform); + auto it = llvm::find_if(minVersion, + [&](const auto &p) { return p.first == platform; }); if (it != minVersion.end()) if (config->platformInfo.minimum < it->second) return false; diff --git a/lld/MachO/Driver.h b/lld/MachO/Driver.h index 148c309b52d578..1006cc1ac6eaec 100644 --- a/lld/MachO/Driver.h +++ b/lld/MachO/Driver.h @@ -22,6 +22,7 @@ namespace llvm { namespace MachO { class InterfaceFile; +enum class PlatformKind : unsigned; } // namespace MachO } // namespace llvm @@ -75,6 +76,9 @@ uint32_t getModTime(llvm::StringRef path); void printArchiveMemberLoad(StringRef reason, const InputFile *); +// Map simulator platforms to their underlying device platform. +llvm::MachO::PlatformKind removeSimulator(llvm::MachO::PlatformKind platform); + // Helper class to export dependency info. class DependencyTracker { public: diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp index 57773bff7253c8..523125ccb97d9b 100644 --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -141,19 +141,6 @@ static std::vector getPlatformInfos(const InputFile *input) { return platformInfos; } -static PlatformKind removeSimulator(PlatformKind platform) { - // Mapping of platform to simulator and vice-versa. - static const std::map platformMap = { - {PlatformKind::iOSSimulator, PlatformKind::iOS}, - {PlatformKind::tvOSSimulator, PlatformKind::tvOS}, - {PlatformKind::watchOSSimulator, PlatformKind::watchOS}}; - - auto iter = platformMap.find(platform); - if (iter == platformMap.end()) - return platform; - return iter->second; -} - static bool checkCompatibility(const InputFile *input) { std::vector platformInfos = getPlatformInfos(input); if (platformInfos.empty()) diff --git a/lld/MachO/InputFiles.h b/lld/MachO/InputFiles.h index fa34dbeb6fc95b..c57f24ae2cc195 100644 --- a/lld/MachO/InputFiles.h +++ b/lld/MachO/InputFiles.h @@ -22,7 +22,6 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/TextAPI/TextAPIReader.h" -#include #include namespace llvm { diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp index 3bd0daf7902f7e..a6e1b8be657921 100644 --- a/lld/MachO/Writer.cpp +++ b/lld/MachO/Writer.cpp @@ -666,15 +666,17 @@ void Writer::scanSymbols() { // TODO: ld64 enforces the old load commands in a few other cases. static bool useLCBuildVersion(const PlatformInfo &platformInfo) { - static const std::map minVersion = { - {PlatformKind::macOS, llvm::VersionTuple(10, 14)}, - {PlatformKind::iOS, llvm::VersionTuple(12, 0)}, - {PlatformKind::iOSSimulator, llvm::VersionTuple(13, 0)}, - {PlatformKind::tvOS, llvm::VersionTuple(12, 0)}, - {PlatformKind::tvOSSimulator, llvm::VersionTuple(13, 0)}, - {PlatformKind::watchOS, llvm::VersionTuple(5, 0)}, - {PlatformKind::watchOSSimulator, llvm::VersionTuple(6, 0)}}; - auto it = minVersion.find(platformInfo.target.Platform); + static const std::vector> + minVersion = {{PlatformKind::macOS, llvm::VersionTuple(10, 14)}, + {PlatformKind::iOS, llvm::VersionTuple(12, 0)}, + {PlatformKind::iOSSimulator, llvm::VersionTuple(13, 0)}, + {PlatformKind::tvOS, llvm::VersionTuple(12, 0)}, + {PlatformKind::tvOSSimulator, llvm::VersionTuple(13, 0)}, + {PlatformKind::watchOS, llvm::VersionTuple(5, 0)}, + {PlatformKind::watchOSSimulator, llvm::VersionTuple(6, 0)}}; + auto it = llvm::find_if(minVersion, [&](const auto &p) { + return p.first == platformInfo.target.Platform; + }); return it == minVersion.end() ? true : platformInfo.minimum >= it->second; }