[PATCH] D101855: [lld-macho] Check simulator platforms to avoid issuing false positive errors.

Vy Nguyen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 4 13:25:10 PDT 2021


oontvoo created this revision.
Herald added a reviewer: int3.
Herald added a project: lld-macho.
Herald added a reviewer: lld-macho.
oontvoo requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Current the linker causes unnecessary errors when either the target or the config's platform is a simulator.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101855

Files:
  lld/MachO/InputFiles.cpp


Index: lld/MachO/InputFiles.cpp
===================================================================
--- lld/MachO/InputFiles.cpp
+++ lld/MachO/InputFiles.cpp
@@ -139,12 +139,35 @@
   return None;
 }
 
+static bool checkSimulatedPlatform(PlatformKind lhs, PlatformKind rhs) {
+  // Mapping of platform to simulator and vice-versa.
+  static std::map<PlatformKind, PlatformKind> *platformMap = []() {
+    auto *ret = new std::map<PlatformKind, PlatformKind>();
+
+    ret->insert({PlatformKind::iOS, PlatformKind::iOSSimulator});
+    ret->insert({PlatformKind::iOSSimulator, PlatformKind::iOS});
+
+    ret->insert({PlatformKind::tvOS, PlatformKind::tvOSSimulator});
+    ret->insert({PlatformKind::tvOSSimulator, PlatformKind::tvOS});
+
+    ret->insert({PlatformKind::watchOS, PlatformKind::watchOSSimulator});
+    ret->insert({PlatformKind::watchOSSimulator, PlatformKind::watchOS});
+
+    return ret;
+  }();
+
+  auto iter = platformMap->find(lhs);
+  return iter != platformMap->end() && iter->second == rhs;
+}
+
 static bool checkCompatibility(const InputFile *input) {
   Optional<PlatformInfo> platformInfo = getPlatformInfo(input);
   if (!platformInfo)
     return true;
   // TODO: Correctly detect simulator platforms or relax this check.
-  if (config->platform() != platformInfo->target.Platform) {
+  if (config->platform() != platformInfo->target.Platform &&
+      !checkSimulatedPlatform(config->platform(),
+                              platformInfo->target.Platform)) {
     error(toString(input) + " has platform " +
           getPlatformName(platformInfo->target.Platform) +
           Twine(", which is different from target platform ") +


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101855.342848.patch
Type: text/x-patch
Size: 1668 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210504/7efb1026/attachment.bin>


More information about the llvm-commits mailing list