Skip to content

Commit eeebf0c

Browse files
committed
IRGen: give the force load symbol export DLL storage
The force load symbol was not marked as DLL export. This would result in the symbol not being emitted into the import library and consequently not being available to the consumer. This ensures that the symbol is visible outside of the module.
1 parent 63c117a commit eeebf0c

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/IRGen/IRGenModule.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -975,10 +975,13 @@ void IRGenModule::emitAutolinkInfo() {
975975
if (!IRGen.Opts.ForceLoadSymbolName.empty()) {
976976
llvm::SmallString<64> buf;
977977
encodeForceLoadSymbolName(buf, IRGen.Opts.ForceLoadSymbolName);
978-
(void)new llvm::GlobalVariable(Module, Int1Ty, /*constant=*/false,
979-
llvm::GlobalValue::CommonLinkage,
980-
llvm::Constant::getNullValue(Int1Ty),
981-
buf.str());
978+
auto symbol =
979+
new llvm::GlobalVariable(Module, Int1Ty, /*constant=*/false,
980+
llvm::GlobalValue::CommonLinkage,
981+
llvm::Constant::getNullValue(Int1Ty),
982+
buf.str());
983+
if (Triple.isOSBinFormatCOFF())
984+
symbol->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
982985
}
983986
}
984987

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
4+
// RUN: %swift -target i686--windows-msvc -parse-as-library -parse-stdlib -module-name autolink -module-link-name autolink -autolink-force-load -emit-ir -o - %s | FileCheck %s
5+
// RUN: %swift -target i686--windows-itanium -parse-as-library -parse-stdlib -module-name autolink -module-link-name autolink -autolink-force-load -S -o - %s | FileCheck %s -check-prefix CHECK-ASM-GNU
6+
// RUN: %swift -target i686--windows-msvc -parse-as-library -parse-stdlib -module-name autolink -module-link-name autolink -autolink-force-load -S -o - %s | FileCheck %s -check-prefix CHECK-ASM-MSC
7+
8+
// CHECK: @"_swift_FORCE_LOAD_$_autolink" = common dllexport global i1 false
9+
// CHECK-ASM-GNU: .ascii " -export:__swift_FORCE_LOAD_$_autolink,data"
10+
// CHECK-ASM-MSC: .ascii " /EXPORT:__swift_FORCE_LOAD_$_autolink,DATA"
11+

0 commit comments

Comments
 (0)