Skip to content

Commit 963c679

Browse files
authored
Merge pull request #39738 from DougGregor/no-link-back-compat-incorrectly-5.5
Ensure that we link the right set of compatibility libraries on Apple OS's
2 parents 209cda7 + e21296b commit 963c679

File tree

4 files changed

+56
-16
lines changed

4 files changed

+56
-16
lines changed

include/swift/Frontend/BackDeploymentLibs.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
BACK_DEPLOYMENT_LIB((5, 0), all, "swiftCompatibility50")
2828
BACK_DEPLOYMENT_LIB((5, 1), all, "swiftCompatibility51")
2929
BACK_DEPLOYMENT_LIB((5, 0), executable, "swiftCompatibilityDynamicReplacements")
30-
BACK_DEPLOYMENT_LIB((5, 5), all, "swiftCompatibilityConcurrency")
30+
BACK_DEPLOYMENT_LIB((5, 4), all, "swiftCompatibilityConcurrency")
3131

3232
#undef BACK_DEPLOYMENT_LIB

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

stdlib/public/BackDeployConcurrency/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ add_compile_definitions(SWIFT_CONCURRENCY_BACK_DEPLOYMENT)
4444
set(swift_concurrency_install_component back-deployment)
4545
set(swift_concurrency_options
4646
BACK_DEPLOYMENT_LIBRARY 5.5
47-
DARWIN_INSTALL_NAME_DIR "@rpath")
47+
DARWIN_INSTALL_NAME_DIR "@rpath"
48+
LINK_FLAGS -lobjc)
4849
set(swift_concurrency_extra_sources
4950
"../BackDeployConcurrency/Exclusivity.cpp"
5051
"../BackDeployConcurrency/Metadata.cpp"

test/IRGen/autolink-runtime-compatibility.swift

Lines changed: 21 additions & 3 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,15 +56,27 @@ 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+
71+
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility51"
72+
5373
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility50"
5474
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements"
5575
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility51"
56-
// FORCE-LOAD-55-DAG: declare {{.*}} @"_swift_FORCE_LOAD_$_swiftCompatibilityConcurrency"
76+
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibilityConcurrency"
5777
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility50"
5878
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements"
5979
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility51"
60-
// FORCE-LOAD-55-DAG: [[AUTOLINK_SWIFT_COMPAT_CONCURRENCY:![0-9]+]] = !{!"-lswiftCompatibilityConcurrency"}
61-
// FORCE-LOAD-55-DAG: !llvm.linker.options = !{{{.*}}[[AUTOLINK_SWIFT_COMPAT_CONCURRENCY]]{{[,}]}}
6280
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility50"
6381
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements"
6482
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility51"

0 commit comments

Comments
 (0)