Skip to content

Commit 7fa316c

Browse files
committed
IRGen: internalise well known types with static linking
When statically linking the standard library ensure that we emit the well known metadata and accessors with internal linkage. This fixes a number of warnings about incorrect DLL storage when building Foundation on Windows for static linking.
1 parent 1484f1c commit 7fa316c

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3963,16 +3963,21 @@ IRGenModule::getAddrOfLLVMVariable(LinkEntity entity,
39633963
// inside the standard library with the definition being in the runtime
39643964
// preventing the normal detection from identifying that this is module
39653965
// local.
3966-
if (getSwiftModule()->isStdlibModule())
3966+
//
3967+
// If we are statically linking the standard library, we need to internalise
3968+
// the symbols.
3969+
if (getSwiftModule()->isStdlibModule() ||
3970+
(Context.getStdlibModule() &&
3971+
Context.getStdlibModule()->isStaticLibrary()))
39673972
if (entity.isTypeKind() &&
39683973
(IsWellKnownBuiltinOrStructralType(entity.getType()) ||
39693974
entity.getType() == kAnyFunctionType))
39703975
if (auto *GV = dyn_cast<llvm::GlobalValue>(var))
3971-
if (GV->hasDLLImportStorageClass())
3972-
ApplyIRLinkage({llvm::GlobalValue::ExternalLinkage,
3973-
llvm::GlobalValue::DefaultVisibility,
3974-
llvm::GlobalValue::DefaultStorageClass})
3975-
.to(GV);
3976+
if (GV->hasDLLImportStorageClass())
3977+
ApplyIRLinkage({llvm::GlobalValue::ExternalLinkage,
3978+
llvm::GlobalValue::DefaultVisibility,
3979+
llvm::GlobalValue::DefaultStorageClass})
3980+
.to(GV);
39763981

39773982
// Install the concrete definition if we have one.
39783983
if (definition && definition.hasInit()) {

0 commit comments

Comments
 (0)