@@ -117,6 +117,11 @@ static clang::CodeGenerator *createClangCodeGenerator(ASTContext &Context,
117117 return ClangCodeGen;
118118}
119119
120+ // / A helper for determining if the triple uses the DLL storage
121+ static bool useDllStorage (const llvm::Triple &Triple) {
122+ return Triple.isOSBinFormatCOFF () && !Triple.isOSCygMing ();
123+ }
124+
120125IRGenModule::IRGenModule (IRGenerator &irgen,
121126 std::unique_ptr<llvm::TargetMachine> &&target,
122127 SourceFile *SF, llvm::LLVMContext &LLVMContext,
@@ -439,7 +444,7 @@ llvm::Constant *swift::getRuntimeFn(llvm::Module &Module,
439444 if (auto fn = dyn_cast<llvm::Function>(cache)) {
440445 fn->setCallingConv (cc);
441446
442- if (llvm::Triple (Module.getTargetTriple ()). isOSBinFormatCOFF ( ) &&
447+ if (:: useDllStorage ( llvm::Triple (Module.getTargetTriple ())) &&
443448 (fn->getLinkage () == llvm::GlobalValue::ExternalLinkage ||
444449 fn->getLinkage () == llvm::GlobalValue::AvailableExternallyLinkage))
445450 fn->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
@@ -519,7 +524,7 @@ llvm::Constant *swift::getWrapperFn(llvm::Module &Module,
519524 auto *globalFnPtr = new llvm::GlobalVariable (
520525 Module, fnPtrTy, false , llvm::GlobalValue::ExternalLinkage, nullptr ,
521526 symbol);
522- if (llvm::Triple (Module.getTargetTriple ()). isOSBinFormatCOFF ( ))
527+ if (:: useDllStorage ( llvm::Triple (Module.getTargetTriple ())))
523528 globalFnPtr->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
524529
525530 // Forward all arguments.
@@ -638,7 +643,7 @@ llvm::Constant *IRGenModule::getEmptyTupleMetadata() {
638643 EmptyTupleMetadata = Module.getOrInsertGlobal (
639644 MANGLE_AS_STRING (METADATA_SYM (EMPTY_TUPLE_MANGLING)),
640645 FullTypeMetadataStructTy);
641- if (Triple. isOSBinFormatCOFF ())
646+ if (useDllStorage ())
642647 cast<llvm::GlobalVariable>(EmptyTupleMetadata)
643648 ->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
644649 return EmptyTupleMetadata;
@@ -652,7 +657,7 @@ llvm::Constant *IRGenModule::getObjCEmptyCachePtr() {
652657 // struct objc_cache _objc_empty_cache;
653658 ObjCEmptyCachePtr = Module.getOrInsertGlobal (" _objc_empty_cache" ,
654659 OpaquePtrTy->getElementType ());
655- if (Triple. isOSBinFormatCOFF ())
660+ if (useDllStorage ())
656661 cast<llvm::GlobalVariable>(ObjCEmptyCachePtr)
657662 ->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
658663 } else {
@@ -685,7 +690,7 @@ Address IRGenModule::getAddrOfObjCISAMask() {
685690 assert (TargetInfo.hasISAMasking ());
686691 if (!ObjCISAMaskPtr) {
687692 ObjCISAMaskPtr = Module.getOrInsertGlobal (" swift_isaMask" , IntPtrTy);
688- if (Triple. isOSBinFormatCOFF ())
693+ if (useDllStorage ())
689694 cast<llvm::GlobalVariable>(ObjCISAMaskPtr)
690695 ->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
691696 }
@@ -851,7 +856,7 @@ void IRGenModule::addLinkLibrary(const LinkLibrary &linkLib) {
851856 llvm::SmallString<64 > buf;
852857 encodeForceLoadSymbolName (buf, linkLib.getName ());
853858 auto symbolAddr = Module.getOrInsertGlobal (buf.str (), Int1Ty);
854- if (Triple. isOSBinFormatCOFF ())
859+ if (useDllStorage ())
855860 cast<llvm::GlobalVariable>(symbolAddr)
856861 ->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
857862
@@ -916,9 +921,9 @@ void IRGenModule::emitAutolinkInfo() {
916921 }),
917922 AutolinkEntries.end ());
918923
919- if (TargetInfo.OutputObjectFormat == llvm::Triple::COFF ||
920- TargetInfo. OutputObjectFormat == llvm:: Triple::MachO ||
921- Triple.isPS4 ()) {
924+ if (( TargetInfo.OutputObjectFormat == llvm::Triple::COFF &&
925+ ! Triple. isOSCygMing ()) ||
926+ TargetInfo. OutputObjectFormat == llvm::Triple::MachO || Triple.isPS4 ()) {
922927 llvm::LLVMContext &ctx = Module.getContext ();
923928
924929 if (!LinkerOptions) {
@@ -935,8 +940,9 @@ void IRGenModule::emitAutolinkInfo() {
935940 assert (FoundOldEntry && " Could not replace old linker options entry?" );
936941 }
937942 } else {
938- assert (TargetInfo.OutputObjectFormat == llvm::Triple::ELF &&
939- " expected ELF output format" );
943+ assert ((TargetInfo.OutputObjectFormat == llvm::Triple::ELF ||
944+ Triple.isOSCygMing ()) &&
945+ " expected ELF output format or COFF format for Cygwin/MinGW" );
940946
941947 // Merge the entries into null-separated string.
942948 llvm::SmallString<64 > EntriesString;
@@ -969,7 +975,7 @@ void IRGenModule::emitAutolinkInfo() {
969975 llvm::GlobalValue::CommonLinkage,
970976 llvm::Constant::getNullValue (Int1Ty),
971977 buf.str ());
972- if (Triple. isOSBinFormatCOFF ())
978+ if (useDllStorage ())
973979 symbol->setDLLStorageClass (llvm::GlobalValue::DLLExportStorageClass);
974980 }
975981}
@@ -1072,6 +1078,8 @@ void IRGenModule::error(SourceLoc loc, const Twine &message) {
10721078 message.toStringRef (buffer));
10731079}
10741080
1081+ bool IRGenModule::useDllStorage () { return ::useDllStorage (Triple); }
1082+
10751083void IRGenerator::addGenModule (SourceFile *SF, IRGenModule *IGM) {
10761084 assert (GenModules.count (SF) == 0 );
10771085 GenModules[SF] = IGM;
0 commit comments