Skip to content

Commit fa13d29

Browse files
authored
Merge pull request #63757 from apple/105181824
2 parents bfd140f + b3dd80f commit fa13d29

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/IRGen/TBDGen.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,18 @@ getInnermostIntroVersion(ArrayRef<Decl*> DeclStack, PlatformKind Platform) {
277277
return None;
278278
}
279279

280+
/// Using the introducing version of a symbol as the start version to redirect
281+
/// linkage path isn't sufficient. This is because the executable can be deployed
282+
/// to OS versions that were before the symbol was introduced. When that happens,
283+
/// strictly using the introductory version can lead to NOT redirecting.
284+
static llvm::VersionTuple calculateLdPreviousVersionStart(ASTContext &ctx,
285+
llvm::VersionTuple introVer) {
286+
auto minDep = ctx.LangOpts.getMinPlatformVersion();
287+
if (minDep < introVer)
288+
return llvm::VersionTuple(1, 0);
289+
return introVer;
290+
}
291+
280292
void TBDGenVisitor::addLinkerDirectiveSymbolsLdPrevious(StringRef name,
281293
llvm::MachO::SymbolKind kind) {
282294
if (kind != llvm::MachO::SymbolKind::GlobalSymbol)
@@ -323,7 +335,8 @@ void TBDGenVisitor::addLinkerDirectiveSymbolsLdPrevious(StringRef name,
323335
static auto getMinor = [](Optional<unsigned> Minor) {
324336
return Minor.has_value() ? *Minor : 0;
325337
};
326-
OS << IntroVer->getMajor() << "." << getMinor(IntroVer->getMinor()) << "$";
338+
auto verStart = calculateLdPreviousVersionStart(Ctx, *IntroVer);
339+
OS << verStart.getMajor() << "." << getMinor(verStart.getMinor()) << "$";
327340
OS << Ver.Version.getMajor() << "." << getMinor(Ver.Version.getMinor()) << "$";
328341
OS << name << "$";
329342
addSymbolInternal(OS.str(), SymbolKind::GlobalSymbol,

test/IRGen/original-defined-attr-linker-directives-fail.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// RUN: not %target-swift-frontend -swift-version 4 -enforce-exclusivity=checked %s -emit-ir -module-name CurrentModule -D CURRENT_MODULE -previous-module-installname-map-file %t/nil.json >& %t/error.txt
77
// RUN: %FileCheck %s -check-prefix=CHECK-ERROR < %t/error.txt
88

9+
// RUN: %target-swift-frontend -target x86_64-apple-macosx10.6 -swift-version 4 -enforce-exclusivity=checked %s -emit-ir -module-name CurrentModule -D CURRENT_MODULE -previous-module-installname-map-file %t/install-name.json | %FileCheck %s -check-prefix=CHECK-SYMBOLS-LOW-TARGET
10+
911
@available(OSX 10.8, *)
1012
@_originallyDefinedIn(module: "OriginalModule", macOS 10.10)
1113
public struct Entity {
@@ -19,4 +21,10 @@ public struct Entity {
1921
// CHECK-SYMBOLS: $ld$previous$/System/OriginalModule.dylib$$1$10.8$10.10$_$s14OriginalModule6EntityVMa$
2022
// CHECK-SYMBOLS: $ld$previous$/System/OriginalModule.dylib$$1$10.8$10.10$_$s14OriginalModule6EntityV06removeC0yyACF$
2123

24+
// CHECK-SYMBOLS-LOW-TARGET: $ld$previous$/System/OriginalModule.dylib$$1$1.0$10.10$_$s14OriginalModule6EntityVMn$
25+
// CHECK-SYMBOLS-LOW-TARGET: $ld$previous$/System/OriginalModule.dylib$$1$1.0$10.10$_$s14OriginalModule6EntityV03addC0yyACF$
26+
// CHECK-SYMBOLS-LOW-TARGET: $ld$previous$/System/OriginalModule.dylib$$1$1.0$10.10$_$s14OriginalModule6EntityVN$
27+
// CHECK-SYMBOLS-LOW-TARGET: $ld$previous$/System/OriginalModule.dylib$$1$1.0$10.10$_$s14OriginalModule6EntityVMa$
28+
// CHECK-SYMBOLS-LOW-TARGET: $ld$previous$/System/OriginalModule.dylib$$1$1.0$10.10$_$s14OriginalModule6EntityV06removeC0yyACF$
29+
2230
// CHECK-ERROR: cannot open previous install name map

0 commit comments

Comments
 (0)