@@ -446,6 +446,7 @@ llvm::Constant *swift::getRuntimeFn(llvm::Module &Module,
446446 fn->setCallingConv (cc);
447447
448448 if (llvm::Triple (Module.getTargetTriple ()).isOSBinFormatCOFF () &&
449+ !llvm::Triple (Module.getTargetTriple ()).isOSCygMing () &&
449450 (fn->getLinkage () == llvm::GlobalValue::ExternalLinkage ||
450451 fn->getLinkage () == llvm::GlobalValue::AvailableExternallyLinkage))
451452 fn->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
@@ -525,7 +526,8 @@ llvm::Constant *swift::getWrapperFn(llvm::Module &Module,
525526 auto *globalFnPtr =
526527 new llvm::GlobalVariable (Module, fnPtrTy, false ,
527528 llvm::GlobalValue::ExternalLinkage, 0 , symbol);
528- if (llvm::Triple (Module.getTargetTriple ()).isOSBinFormatCOFF ())
529+ if (llvm::Triple (Module.getTargetTriple ()).isOSBinFormatCOFF () &&
530+ !llvm::Triple (Module.getTargetTriple ()).isOSCygMing ())
529531 globalFnPtr->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
530532
531533 // Forward all arguments.
@@ -643,7 +645,7 @@ llvm::Constant *IRGenModule::getEmptyTupleMetadata() {
643645
644646 EmptyTupleMetadata =
645647 Module.getOrInsertGlobal (" _TMT_" , FullTypeMetadataStructTy);
646- if (Triple. isOSBinFormatCOFF ())
648+ if (useDllStorage ())
647649 cast<llvm::GlobalVariable>(EmptyTupleMetadata)
648650 ->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
649651 return EmptyTupleMetadata;
@@ -657,7 +659,7 @@ llvm::Constant *IRGenModule::getObjCEmptyCachePtr() {
657659 // struct objc_cache _objc_empty_cache;
658660 ObjCEmptyCachePtr = Module.getOrInsertGlobal (" _objc_empty_cache" ,
659661 OpaquePtrTy->getElementType ());
660- if (Triple. isOSBinFormatCOFF ())
662+ if (useDllStorage ())
661663 cast<llvm::GlobalVariable>(ObjCEmptyCachePtr)
662664 ->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
663665 } else {
@@ -690,7 +692,7 @@ Address IRGenModule::getAddrOfObjCISAMask() {
690692 assert (TargetInfo.hasISAMasking ());
691693 if (!ObjCISAMaskPtr) {
692694 ObjCISAMaskPtr = Module.getOrInsertGlobal (" swift_isaMask" , IntPtrTy);
693- if (Triple. isOSBinFormatCOFF ())
695+ if (useDllStorage ())
694696 cast<llvm::GlobalVariable>(ObjCISAMaskPtr)
695697 ->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
696698 }
@@ -856,7 +858,7 @@ void IRGenModule::addLinkLibrary(const LinkLibrary &linkLib) {
856858 llvm::SmallString<64 > buf;
857859 encodeForceLoadSymbolName (buf, linkLib.getName ());
858860 auto symbolAddr = Module.getOrInsertGlobal (buf.str (), Int1Ty);
859- if (Triple. isOSBinFormatCOFF ())
861+ if (useDllStorage ())
860862 cast<llvm::GlobalVariable>(symbolAddr)
861863 ->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
862864
@@ -921,9 +923,9 @@ void IRGenModule::emitAutolinkInfo() {
921923 }),
922924 AutolinkEntries.end ());
923925
924- if (TargetInfo.OutputObjectFormat == llvm::Triple::COFF ||
925- TargetInfo. OutputObjectFormat == llvm:: Triple::MachO ||
926- Triple.isPS4 ()) {
926+ if (( TargetInfo.OutputObjectFormat == llvm::Triple::COFF &&
927+ ! Triple. isOSCygMing ()) ||
928+ TargetInfo. OutputObjectFormat == llvm::Triple::MachO || Triple.isPS4 ()) {
927929 llvm::LLVMContext &ctx = Module.getContext ();
928930
929931 if (!LinkerOptions) {
@@ -940,8 +942,9 @@ void IRGenModule::emitAutolinkInfo() {
940942 assert (FoundOldEntry && " Could not replace old linker options entry?" );
941943 }
942944 } else {
943- assert (TargetInfo.OutputObjectFormat == llvm::Triple::ELF &&
944- " expected ELF output format" );
945+ assert ((TargetInfo.OutputObjectFormat == llvm::Triple::ELF ||
946+ Triple.isOSCygMing ()) &&
947+ " expected ELF output format or COFF format for Cygwin/MinGW" );
945948
946949 // Merge the entries into null-separated string.
947950 llvm::SmallString<64 > EntriesString;
@@ -974,7 +977,7 @@ void IRGenModule::emitAutolinkInfo() {
974977 llvm::GlobalValue::CommonLinkage,
975978 llvm::Constant::getNullValue (Int1Ty),
976979 buf.str ());
977- if (Triple. isOSBinFormatCOFF ())
980+ if (useDllStorage ())
978981 symbol->setDLLStorageClass (llvm::GlobalValue::DLLExportStorageClass);
979982 }
980983}
0 commit comments