From 7fa316c71d865c3ae66be3f8949ba4f282767c4f Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Tue, 10 Jun 2025 16:56:14 -0700 Subject: [PATCH] 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. --- lib/IRGen/GenDecl.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/IRGen/GenDecl.cpp b/lib/IRGen/GenDecl.cpp index 83c2662cb663c..a94bf35be35de 100644 --- a/lib/IRGen/GenDecl.cpp +++ b/lib/IRGen/GenDecl.cpp @@ -3963,16 +3963,21 @@ IRGenModule::getAddrOfLLVMVariable(LinkEntity entity, // inside the standard library with the definition being in the runtime // preventing the normal detection from identifying that this is module // local. - if (getSwiftModule()->isStdlibModule()) + // + // If we are statically linking the standard library, we need to internalise + // the symbols. + if (getSwiftModule()->isStdlibModule() || + (Context.getStdlibModule() && + Context.getStdlibModule()->isStaticLibrary())) if (entity.isTypeKind() && (IsWellKnownBuiltinOrStructralType(entity.getType()) || entity.getType() == kAnyFunctionType)) if (auto *GV = dyn_cast(var)) - if (GV->hasDLLImportStorageClass()) - ApplyIRLinkage({llvm::GlobalValue::ExternalLinkage, - llvm::GlobalValue::DefaultVisibility, - llvm::GlobalValue::DefaultStorageClass}) - .to(GV); + if (GV->hasDLLImportStorageClass()) + ApplyIRLinkage({llvm::GlobalValue::ExternalLinkage, + llvm::GlobalValue::DefaultVisibility, + llvm::GlobalValue::DefaultStorageClass}) + .to(GV); // Install the concrete definition if we have one. if (definition && definition.hasInit()) {