Skip to content

Commit 72d4f3c

Browse files
authored
Merge pull request #24259 from bob-wilson/rdar50110036-51-0424
References to _swift_FORCE_LOAD* symbols should be weak
2 parents 2335540 + 69d9690 commit 72d4f3c

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

include/swift/IRGen/Linking.h

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

10771077
static const IRLinkage ExternalImport;
1078+
static const IRLinkage ExternalWeakImport;
10781079
static const IRLinkage ExternalExport;
10791080
};
10801081

lib/IRGen/IRGenModule.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,8 +981,12 @@ void IRGenModule::addLinkLibrary(const LinkLibrary &linkLib) {
981981
encodeForceLoadSymbolName(buf, linkLib.getName());
982982
auto ForceImportThunk =
983983
Module.getOrInsertFunction(buf, llvm::FunctionType::get(VoidTy, false));
984-
ApplyIRLinkage(IRLinkage::ExternalImport)
985-
.to(cast<llvm::GlobalValue>(ForceImportThunk));
984+
985+
const IRLinkage IRL =
986+
llvm::Triple(Module.getTargetTriple()).isOSBinFormatCOFF()
987+
? IRLinkage::ExternalImport
988+
: IRLinkage::ExternalWeakImport;
989+
ApplyIRLinkage(IRL).to(cast<llvm::GlobalValue>(ForceImportThunk));
986990

987991
buf += "_$";
988992
appendEncodedName(buf, IRGen.Opts.ModuleName);

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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// RUN: %target-swift-frontend -emit-module -parse-stdlib -o %t -module-name someModule -module-link-name module %S/../Inputs/empty.swift -autolink-force-load
1414
// RUN: %target-swift-frontend -emit-ir -lmagic %s -I %t > %t/force-load.txt
1515
// RUN: %FileCheck %s < %t/force-load.txt
16-
// RUN: %FileCheck -check-prefix=FORCE-LOAD-CLIENT %s < %t/force-load.txt
16+
// RUN: %FileCheck -check-prefix FORCE-LOAD-CLIENT -check-prefix FORCE-LOAD-CLIENT-%target-object-format %s < %t/force-load.txt
1717

1818
// RUN: %target-swift-frontend -emit-ir -parse-stdlib -module-name someModule -module-link-name module %S/../Inputs/empty.swift | %FileCheck --check-prefix=NO-FORCE-LOAD %s
1919
// RUN: %target-swift-frontend -emit-ir -parse-stdlib -module-name someModule -module-link-name module %S/../Inputs/empty.swift -autolink-force-load | %FileCheck --check-prefix=FORCE-LOAD %s
@@ -49,5 +49,6 @@ import someModule
4949
// FORCE-LOAD-CLIENT: @llvm.used = appending global [{{[0-9]+}} x i8*] [
5050
// FORCE-LOAD-CLIENT: i8* bitcast (void ()** @"_swift_FORCE_LOAD_$_module_$_autolinking" to i8*)
5151
// FORCE-LOAD-CLIENT: ], section "llvm.metadata"
52-
// FORCE-LOAD-CLIENT: declare {{(dllimport )?}}void @"_swift_FORCE_LOAD_$_module"()
52+
// FORCE-LOAD-CLIENT-MACHO: declare extern_weak {{(dllimport )?}}void @"_swift_FORCE_LOAD_$_module"()
53+
// FORCE-LOAD-CLIENT-COFF: declare extern {{(dllimport )?}}void @"_swift_FORCE_LOAD_$_module"()
5354

0 commit comments

Comments
 (0)