Skip to content

Commit e76aff4

Browse files
committed
Update the OS runtime mapping for Apple OS versions.
Fixes the rest of rdar://84065193, makingn sure we don't link against compatibility libraries we don't need.
1 parent 0b4620f commit e76aff4

File tree

2 files changed

+50
-11
lines changed

2 files changed

+50
-11
lines changed

lib/Basic/Platform.cpp

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -395,32 +395,46 @@ swift::getSwiftRuntimeCompatibilityVersionForTarget(
395395
}
396396
}
397397
} else if (Major == 11) {
398-
return floorFor64(llvm::VersionTuple(5, 3));
398+
if (Minor <= 3)
399+
return floorFor64(llvm::VersionTuple(5, 3));
400+
401+
return floorFor64(llvm::VersionTuple(5, 4));
402+
} else if (Major == 12) {
403+
return floorFor64(llvm::VersionTuple(5, 5));
399404
}
400405
} else if (Triple.isiOS()) { // includes tvOS
401406
Triple.getiOSVersion(Major, Minor, Micro);
402407

403-
auto floorFor64e = [&Triple](llvm::VersionTuple v) {
408+
auto floorForArchitecture = [&Triple, Major](llvm::VersionTuple v) {
409+
// arm64 simulators and macCatalyst are introduced in iOS 14.0/tvOS 14.0
410+
// with Swift 5.3
411+
if (Triple.isAArch64() && Major <= 14 &&
412+
(Triple.isSimulatorEnvironment() ||
413+
Triple.isMacCatalystEnvironment()))
414+
return MAX(v, llvm::VersionTuple(5, 3));
415+
404416
if (Triple.getArchName() != "arm64e") return v;
417+
405418
// iOS got first arm64e support in 12.0, which has a Swift runtime version
406419
// older than 5.0, so let's floor at VersionTuple(5, 0) instead.
407420
return MAX(v, llvm::VersionTuple(5, 0));
408421
};
409422

410-
// arm64 simulators and macCatalyst are introduced in iOS 14.0/tvOS 14.0
411-
// with Swift 5.3
412-
if (Triple.isAArch64() && Major <= 14 &&
413-
(Triple.isSimulatorEnvironment() || Triple.isMacCatalystEnvironment()))
414-
return floorFor64e(llvm::VersionTuple(5, 3));
415-
416423
if (Major <= 12) {
417-
return floorFor64e(llvm::VersionTuple(5, 0));
424+
return floorForArchitecture(llvm::VersionTuple(5, 0));
418425
} else if (Major <= 13) {
419426
if (Minor <= 3) {
420-
return floorFor64e(llvm::VersionTuple(5, 1));
427+
return floorForArchitecture(llvm::VersionTuple(5, 1));
421428
} else {
422-
return floorFor64e(llvm::VersionTuple(5, 2));
429+
return floorForArchitecture(llvm::VersionTuple(5, 2));
423430
}
431+
} else if (Major <= 14) {
432+
if (Minor <= 4)
433+
return floorForArchitecture(llvm::VersionTuple(5, 3));
434+
435+
return floorForArchitecture(llvm::VersionTuple(5, 4));
436+
} else if (Major <= 15) {
437+
return floorForArchitecture(llvm::VersionTuple(5, 5));
424438
}
425439
} else if (Triple.isWatchOS()) {
426440
auto floorFor64bits = [&Triple](llvm::VersionTuple v) {
@@ -438,6 +452,13 @@ swift::getSwiftRuntimeCompatibilityVersionForTarget(
438452
} else {
439453
return floorFor64bits(llvm::VersionTuple(5, 2));
440454
}
455+
} else if (Major <= 7) {
456+
if (Minor <= 4)
457+
return floorFor64bits(llvm::VersionTuple(5, 3));
458+
459+
return floorFor64bits(llvm::VersionTuple(5, 4));
460+
} else if (Major <= 8) {
461+
return floorFor64bits(llvm::VersionTuple(5, 5));
441462
}
442463
}
443464

test/IRGen/autolink-runtime-compatibility.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
// Only autolinks 5.1 compatibility library because target OS has 5.1
1414
// RUN: %target-swift-frontend -target %target-cpu-apple-macosx10.15 -emit-ir -parse-stdlib %s | %FileCheck -check-prefix=FORCE-LOAD-51 %s
1515

16+
// Only autolinks concurrency compatibility library because target OS has 5.3
17+
// RUN: %target-swift-frontend -target %target-cpu-apple-macosx11 -emit-ir -parse-stdlib %s | %FileCheck -check-prefix=FORCE-LOAD-53 %s
18+
19+
// Only autolinks concurrency compatibility library because target OS has 5.4
20+
// RUN: %target-swift-frontend -target %target-cpu-apple-macosx11.3 -emit-ir -parse-stdlib %s | %FileCheck -check-prefix=FORCE-LOAD-54 %s
21+
1622
// Autolinks because compatibility library was explicitly asked for
1723
// RUN: %target-swift-frontend -runtime-compatibility-version 5.0 -emit-ir -parse-stdlib %s | %FileCheck -check-prefix=FORCE-LOAD %s
1824
// RUN: %target-swift-frontend -runtime-compatibility-version 5.1 -emit-ir -parse-stdlib %s | %FileCheck -check-prefix=FORCE-LOAD-51 %s
@@ -50,6 +56,18 @@ public func foo() {}
5056
// FORCE-LOAD-51-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility50"
5157
// FORCE-LOAD-51-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements"
5258

59+
// FORCE-LOAD-53-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility50"
60+
// FORCE-LOAD-53-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements"
61+
// FORCE-LOAD-53-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility51"
62+
// FORCE-LOAD-53-DAG: declare {{.*}} @"_swift_FORCE_LOAD_$_swiftCompatibilityConcurrency"
63+
// FORCE-LOAD-53-DAG: [[AUTOLINK_SWIFT_COMPAT_CONCURRENCY:![0-9]+]] = !{!"-lswiftCompatibilityConcurrency"}
64+
65+
// FORCE-LOAD-54-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility50"
66+
// FORCE-LOAD-54-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements"
67+
// FORCE-LOAD-54-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility51"
68+
// FORCE-LOAD-54-DAG: declare {{.*}} @"_swift_FORCE_LOAD_$_swiftCompatibilityConcurrency"
69+
// FORCE-LOAD-54-DAG: [[AUTOLINK_SWIFT_COMPAT_CONCURRENCY:![0-9]+]] = !{!"-lswiftCompatibilityConcurrency"}
70+
5371
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility51"
5472

5573
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility50"

0 commit comments

Comments
 (0)