@@ -452,6 +452,7 @@ llvm::Constant *swift::getRuntimeFn(llvm::Module &Module,
452452 fn->setCallingConv (cc);
453453
454454 if (llvm::Triple (Module.getTargetTriple ()).isOSBinFormatCOFF () &&
455+ !llvm::Triple (Module.getTargetTriple ()).isOSCygMing () &&
455456 (fn->getLinkage () == llvm::GlobalValue::ExternalLinkage ||
456457 fn->getLinkage () == llvm::GlobalValue::AvailableExternallyLinkage))
457458 fn->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
@@ -531,7 +532,8 @@ llvm::Constant *swift::getWrapperFn(llvm::Module &Module,
531532 auto *globalFnPtr =
532533 new llvm::GlobalVariable (Module, fnPtrTy, false ,
533534 llvm::GlobalValue::ExternalLinkage, 0 , symbol);
534- if (llvm::Triple (Module.getTargetTriple ()).isOSBinFormatCOFF ())
535+ if (llvm::Triple (Module.getTargetTriple ()).isOSBinFormatCOFF () &&
536+ !llvm::Triple (Module.getTargetTriple ()).isOSCygMing ())
535537 globalFnPtr->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
536538
537539 // Forward all arguments.
@@ -649,7 +651,7 @@ llvm::Constant *IRGenModule::getEmptyTupleMetadata() {
649651
650652 EmptyTupleMetadata =
651653 Module.getOrInsertGlobal (" _TMT_" , FullTypeMetadataStructTy);
652- if (Triple. isOSBinFormatCOFF ())
654+ if (useDllStorage ())
653655 cast<llvm::GlobalVariable>(EmptyTupleMetadata)
654656 ->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
655657 return EmptyTupleMetadata;
@@ -663,7 +665,7 @@ llvm::Constant *IRGenModule::getObjCEmptyCachePtr() {
663665 // struct objc_cache _objc_empty_cache;
664666 ObjCEmptyCachePtr = Module.getOrInsertGlobal (" _objc_empty_cache" ,
665667 OpaquePtrTy->getElementType ());
666- if (Triple. isOSBinFormatCOFF ())
668+ if (useDllStorage ())
667669 cast<llvm::GlobalVariable>(ObjCEmptyCachePtr)
668670 ->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
669671 } else {
@@ -696,7 +698,7 @@ Address IRGenModule::getAddrOfObjCISAMask() {
696698 assert (TargetInfo.hasISAMasking ());
697699 if (!ObjCISAMaskPtr) {
698700 ObjCISAMaskPtr = Module.getOrInsertGlobal (" swift_isaMask" , IntPtrTy);
699- if (Triple. isOSBinFormatCOFF ())
701+ if (useDllStorage ())
700702 cast<llvm::GlobalVariable>(ObjCISAMaskPtr)
701703 ->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
702704 }
@@ -862,7 +864,7 @@ void IRGenModule::addLinkLibrary(const LinkLibrary &linkLib) {
862864 llvm::SmallString<64 > buf;
863865 encodeForceLoadSymbolName (buf, linkLib.getName ());
864866 auto symbolAddr = Module.getOrInsertGlobal (buf.str (), Int1Ty);
865- if (Triple. isOSBinFormatCOFF ())
867+ if (useDllStorage ())
866868 cast<llvm::GlobalVariable>(symbolAddr)
867869 ->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
868870
@@ -927,9 +929,9 @@ void IRGenModule::emitAutolinkInfo() {
927929 }),
928930 AutolinkEntries.end ());
929931
930- if (TargetInfo.OutputObjectFormat == llvm::Triple::COFF ||
931- TargetInfo. OutputObjectFormat == llvm:: Triple::MachO ||
932- Triple.isPS4 ()) {
932+ if (( TargetInfo.OutputObjectFormat == llvm::Triple::COFF &&
933+ ! Triple. isOSCygMing ()) ||
934+ TargetInfo. OutputObjectFormat == llvm::Triple::MachO || Triple.isPS4 ()) {
933935 llvm::LLVMContext &ctx = Module.getContext ();
934936
935937 if (!LinkerOptions) {
@@ -946,8 +948,9 @@ void IRGenModule::emitAutolinkInfo() {
946948 assert (FoundOldEntry && " Could not replace old linker options entry?" );
947949 }
948950 } else {
949- assert (TargetInfo.OutputObjectFormat == llvm::Triple::ELF &&
950- " expected ELF output format" );
951+ assert ((TargetInfo.OutputObjectFormat == llvm::Triple::ELF ||
952+ Triple.isOSCygMing ()) &&
953+ " expected ELF output format or COFF format for Cygwin/MinGW" );
951954
952955 // Merge the entries into null-separated string.
953956 llvm::SmallString<64 > EntriesString;
@@ -980,7 +983,7 @@ void IRGenModule::emitAutolinkInfo() {
980983 llvm::GlobalValue::CommonLinkage,
981984 llvm::Constant::getNullValue (Int1Ty),
982985 buf.str ());
983- if (Triple. isOSBinFormatCOFF ())
986+ if (useDllStorage ())
984987 symbol->setDLLStorageClass (llvm::GlobalValue::DLLExportStorageClass);
985988 }
986989}
0 commit comments