[lld] 23233ad - [lld-macho] Check simulator platforms to avoid issuing false positive errors.

Vy Nguyen via llvm-commits llvm-commits at lists.llvm.org
Wed May 5 15:08:43 PDT 2021


Author: Vy Nguyen
Date: 2021-05-05T18:07:58-04:00
New Revision: 23233ad139f4b69ea4ed1cdbd22abc72c7a4cb93

URL: https://github.com/llvm/llvm-project/commit/23233ad139f4b69ea4ed1cdbd22abc72c7a4cb93
DIFF: https://github.com/llvm/llvm-project/commit/23233ad139f4b69ea4ed1cdbd22abc72c7a4cb93.diff

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

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

Differential Revision: https://reviews.llvm.org/D101855

Added: 
    

Modified: 
    lld/MachO/InputFiles.cpp
    lld/test/MachO/invalid/incompatible-arch.s

Removed: 
    


################################################################################
diff  --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index 5f1f772a2d7a0..adc1bb20a47cf 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -139,12 +139,26 @@ static Optional<PlatformInfo> getPlatformInfo(const InputFile *input) {
   return None;
 }
 
+static PlatformKind removeSimulator(PlatformKind platform) {
+  // Mapping of platform to simulator and vice-versa.
+  static const std::map<PlatformKind, PlatformKind> 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) {
   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 (removeSimulator(config->platform()) !=
+      removeSimulator(platformInfo->target.Platform)) {
     error(toString(input) + " has platform " +
           getPlatformName(platformInfo->target.Platform) +
           Twine(", which is 
diff erent from target platform ") +

diff  --git a/lld/test/MachO/invalid/incompatible-arch.s b/lld/test/MachO/invalid/incompatible-arch.s
index 9a776bf56219d..29bffebf350d4 100644
--- a/lld/test/MachO/invalid/incompatible-arch.s
+++ b/lld/test/MachO/invalid/incompatible-arch.s
@@ -30,6 +30,21 @@
 # RUN:  -o /dev/null 2>&1 | FileCheck %s --check-prefix=OBJ-VERSION
 # OBJ-VERSION: {{.*}}test_x86.o has version 10.15.0, which is newer than target minimum of 10.14.0
 
+## Test that simulators platforms are compat with their simulatees.		
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-ios14.0 %s -o %t/test_x86_ios.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-ios14.0-simulator %s -o %t/test_x86_ios_sim.o
+
+# RUN: %lld -dylib -platform_version ios-simulator 14.0.0 14.0.0 %t/test_x86_ios.o -o /dev/null
+# RUN: %lld -dylib -platform_version ios 14.0.0 14.0.0 %t/test_x86_ios_sim.o -o /dev/null
+
+# RUN: not %lld -dylib  -platform_version watchos-simulator 14.0.0 14.0.0 %t/test_x86_ios.o \
+# RUN:	-o /dev/null 2>&1 | FileCheck %s --check-prefix=CROSS-SIM
+# CROSS-SIM: {{.*}}test_x86_ios.o has platform iOS, which is 
diff erent from target platform watchOS Simulator
+# RUN: not %lld -dylib  -platform_version watchos-simulator 14.0.0 14.0.0 %t/test_x86_ios_sim.o \
+# RUN:	-o /dev/null 2>&1 | FileCheck %s --check-prefix=CROSS-SIM2
+# CROSS-SIM2: {{.*}}test_x86_ios_sim.o has platform iOS Simulator, which is 
diff erent from target platform watchOS Simulator
+	
+
 .globl _main
 _main:
   ret


        


More information about the llvm-commits mailing list