Skip to content

Commit dd94a9f

Browse files
committed
References to _swift_FORCE_LOAD* symbols should be weak
When Swift always copied the overlay dylibs into app bundles, it was OK for these symbol references to be non-weak, but with the overlays now part of the OS on Apple platforms, we need to handle backward deployment scenarios where a new overlay does not exist on an old OS version. A weak reference will serve to pull in the overlay dylib if it exists, without causing a fatal error if it does not. rdar://problem/50110036
1 parent cac35ca commit dd94a9f

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

include/swift/IRGen/Linking.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,7 @@ struct IRLinkage {
10851085
static const IRLinkage Internal;
10861086

10871087
static const IRLinkage ExternalImport;
1088+
static const IRLinkage ExternalWeakImport;
10881089
static const IRLinkage ExternalExport;
10891090
};
10901091

lib/IRGen/IRGenModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ void IRGenModule::addLinkLibrary(const LinkLibrary &linkLib) {
985985
encodeForceLoadSymbolName(buf, linkLib.getName());
986986
auto ForceImportThunk =
987987
Module.getOrInsertFunction(buf, llvm::FunctionType::get(VoidTy, false));
988-
ApplyIRLinkage(IRLinkage::ExternalImport)
988+
ApplyIRLinkage(IRLinkage::ExternalWeakImport)
989989
.to(cast<llvm::GlobalValue>(ForceImportThunk));
990990

991991
buf += "_$";

lib/IRGen/Linking.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ const IRLinkage IRLinkage::ExternalImport = {
5757
llvm::GlobalValue::DLLImportStorageClass,
5858
};
5959

60+
const IRLinkage IRLinkage::ExternalWeakImport = {
61+
llvm::GlobalValue::ExternalWeakLinkage,
62+
llvm::GlobalValue::DefaultVisibility,
63+
llvm::GlobalValue::DLLImportStorageClass,
64+
};
65+
6066
const IRLinkage IRLinkage::ExternalExport = {
6167
llvm::GlobalValue::ExternalLinkage,
6268
llvm::GlobalValue::DefaultVisibility,

test/Serialization/autolinking.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ import someModule
4646
// FORCE-LOAD-CLIENT: @llvm.used = appending global [{{[0-9]+}} x i8*] [
4747
// FORCE-LOAD-CLIENT: i8* bitcast (void ()** @"_swift_FORCE_LOAD_$_module_$_autolinking" to i8*)
4848
// FORCE-LOAD-CLIENT: ], section "llvm.metadata"
49-
// FORCE-LOAD-CLIENT: declare {{(dllimport )?}}void @"_swift_FORCE_LOAD_$_module"()
49+
// FORCE-LOAD-CLIENT: declare extern_weak {{(dllimport )?}}void @"_swift_FORCE_LOAD_$_module"()
5050

0 commit comments

Comments
 (0)