@@ -452,6 +452,7 @@ llvm::Constant *swift::getRuntimeFn(llvm::Module &Module,
452
452
fn->setCallingConv (cc);
453
453
454
454
if (llvm::Triple (Module.getTargetTriple ()).isOSBinFormatCOFF () &&
455
+ !llvm::Triple (Module.getTargetTriple ()).isOSCygMing () &&
455
456
(fn->getLinkage () == llvm::GlobalValue::ExternalLinkage ||
456
457
fn->getLinkage () == llvm::GlobalValue::AvailableExternallyLinkage))
457
458
fn->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
@@ -531,7 +532,8 @@ llvm::Constant *swift::getWrapperFn(llvm::Module &Module,
531
532
auto *globalFnPtr =
532
533
new llvm::GlobalVariable (Module, fnPtrTy, false ,
533
534
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 ())
535
537
globalFnPtr->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
536
538
537
539
// Forward all arguments.
@@ -649,7 +651,7 @@ llvm::Constant *IRGenModule::getEmptyTupleMetadata() {
649
651
650
652
EmptyTupleMetadata =
651
653
Module.getOrInsertGlobal (" _TMT_" , FullTypeMetadataStructTy);
652
- if (Triple. isOSBinFormatCOFF ())
654
+ if (useDllStorage ())
653
655
cast<llvm::GlobalVariable>(EmptyTupleMetadata)
654
656
->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
655
657
return EmptyTupleMetadata;
@@ -663,7 +665,7 @@ llvm::Constant *IRGenModule::getObjCEmptyCachePtr() {
663
665
// struct objc_cache _objc_empty_cache;
664
666
ObjCEmptyCachePtr = Module.getOrInsertGlobal (" _objc_empty_cache" ,
665
667
OpaquePtrTy->getElementType ());
666
- if (Triple. isOSBinFormatCOFF ())
668
+ if (useDllStorage ())
667
669
cast<llvm::GlobalVariable>(ObjCEmptyCachePtr)
668
670
->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
669
671
} else {
@@ -696,7 +698,7 @@ Address IRGenModule::getAddrOfObjCISAMask() {
696
698
assert (TargetInfo.hasISAMasking ());
697
699
if (!ObjCISAMaskPtr) {
698
700
ObjCISAMaskPtr = Module.getOrInsertGlobal (" swift_isaMask" , IntPtrTy);
699
- if (Triple. isOSBinFormatCOFF ())
701
+ if (useDllStorage ())
700
702
cast<llvm::GlobalVariable>(ObjCISAMaskPtr)
701
703
->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
702
704
}
@@ -862,7 +864,7 @@ void IRGenModule::addLinkLibrary(const LinkLibrary &linkLib) {
862
864
llvm::SmallString<64 > buf;
863
865
encodeForceLoadSymbolName (buf, linkLib.getName ());
864
866
auto symbolAddr = Module.getOrInsertGlobal (buf.str (), Int1Ty);
865
- if (Triple. isOSBinFormatCOFF ())
867
+ if (useDllStorage ())
866
868
cast<llvm::GlobalVariable>(symbolAddr)
867
869
->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
868
870
@@ -927,9 +929,9 @@ void IRGenModule::emitAutolinkInfo() {
927
929
}),
928
930
AutolinkEntries.end ());
929
931
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 ()) {
933
935
llvm::LLVMContext &ctx = Module.getContext ();
934
936
935
937
if (!LinkerOptions) {
@@ -946,8 +948,9 @@ void IRGenModule::emitAutolinkInfo() {
946
948
assert (FoundOldEntry && " Could not replace old linker options entry?" );
947
949
}
948
950
} 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" );
951
954
952
955
// Merge the entries into null-separated string.
953
956
llvm::SmallString<64 > EntriesString;
@@ -980,7 +983,7 @@ void IRGenModule::emitAutolinkInfo() {
980
983
llvm::GlobalValue::CommonLinkage,
981
984
llvm::Constant::getNullValue (Int1Ty),
982
985
buf.str ());
983
- if (Triple. isOSBinFormatCOFF ())
986
+ if (useDllStorage ())
984
987
symbol->setDLLStorageClass (llvm::GlobalValue::DLLExportStorageClass);
985
988
}
986
989
}
0 commit comments