@@ -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,
@@ -442,7 +447,7 @@ llvm::Constant *swift::getRuntimeFn(llvm::Module &Module,
442447 if (auto fn = dyn_cast<llvm::Function>(cache)) {
443448 fn->setCallingConv (cc);
444449
445- if (llvm::Triple (Module.getTargetTriple ()). isOSBinFormatCOFF ( ) &&
450+ if (:: useDllStorage ( llvm::Triple (Module.getTargetTriple ())) &&
446451 (fn->getLinkage () == llvm::GlobalValue::ExternalLinkage ||
447452 fn->getLinkage () == llvm::GlobalValue::AvailableExternallyLinkage))
448453 fn->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
@@ -522,7 +527,7 @@ llvm::Constant *swift::getWrapperFn(llvm::Module &Module,
522527 auto *globalFnPtr = new llvm::GlobalVariable (
523528 Module, fnPtrTy, false , llvm::GlobalValue::ExternalLinkage, nullptr ,
524529 symbol);
525- if (llvm::Triple (Module.getTargetTriple ()). isOSBinFormatCOFF ( ))
530+ if (:: useDllStorage ( llvm::Triple (Module.getTargetTriple ())))
526531 globalFnPtr->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
527532
528533 // Forward all arguments.
@@ -641,7 +646,7 @@ llvm::Constant *IRGenModule::getEmptyTupleMetadata() {
641646 EmptyTupleMetadata = Module.getOrInsertGlobal (
642647 MANGLE_AS_STRING (METADATA_SYM (EMPTY_TUPLE_MANGLING)),
643648 FullTypeMetadataStructTy);
644- if (Triple. isOSBinFormatCOFF ())
649+ if (useDllStorage ())
645650 cast<llvm::GlobalVariable>(EmptyTupleMetadata)
646651 ->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
647652 return EmptyTupleMetadata;
@@ -655,7 +660,7 @@ llvm::Constant *IRGenModule::getObjCEmptyCachePtr() {
655660 // struct objc_cache _objc_empty_cache;
656661 ObjCEmptyCachePtr = Module.getOrInsertGlobal (" _objc_empty_cache" ,
657662 OpaquePtrTy->getElementType ());
658- if (Triple. isOSBinFormatCOFF ())
663+ if (useDllStorage ())
659664 cast<llvm::GlobalVariable>(ObjCEmptyCachePtr)
660665 ->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
661666 } else {
@@ -688,7 +693,7 @@ Address IRGenModule::getAddrOfObjCISAMask() {
688693 assert (TargetInfo.hasISAMasking ());
689694 if (!ObjCISAMaskPtr) {
690695 ObjCISAMaskPtr = Module.getOrInsertGlobal (" swift_isaMask" , IntPtrTy);
691- if (Triple. isOSBinFormatCOFF ())
696+ if (useDllStorage ())
692697 cast<llvm::GlobalVariable>(ObjCISAMaskPtr)
693698 ->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
694699 }
@@ -854,7 +859,7 @@ void IRGenModule::addLinkLibrary(const LinkLibrary &linkLib) {
854859 llvm::SmallString<64 > buf;
855860 encodeForceLoadSymbolName (buf, linkLib.getName ());
856861 auto symbolAddr = Module.getOrInsertGlobal (buf.str (), Int1Ty);
857- if (Triple. isOSBinFormatCOFF ())
862+ if (useDllStorage ())
858863 cast<llvm::GlobalVariable>(symbolAddr)
859864 ->setDLLStorageClass (llvm::GlobalValue::DLLImportStorageClass);
860865
@@ -919,9 +924,9 @@ void IRGenModule::emitAutolinkInfo() {
919924 }),
920925 AutolinkEntries.end ());
921926
922- if (TargetInfo.OutputObjectFormat == llvm::Triple::COFF ||
923- TargetInfo. OutputObjectFormat == llvm:: Triple::MachO ||
924- Triple.isPS4 ()) {
927+ if (( TargetInfo.OutputObjectFormat == llvm::Triple::COFF &&
928+ ! Triple. isOSCygMing ()) ||
929+ TargetInfo. OutputObjectFormat == llvm::Triple::MachO || Triple.isPS4 ()) {
925930 llvm::LLVMContext &ctx = Module.getContext ();
926931
927932 if (!LinkerOptions) {
@@ -938,8 +943,9 @@ void IRGenModule::emitAutolinkInfo() {
938943 assert (FoundOldEntry && " Could not replace old linker options entry?" );
939944 }
940945 } else {
941- assert (TargetInfo.OutputObjectFormat == llvm::Triple::ELF &&
942- " expected ELF output format" );
946+ assert ((TargetInfo.OutputObjectFormat == llvm::Triple::ELF ||
947+ Triple.isOSCygMing ()) &&
948+ " expected ELF output format or COFF format for Cygwin/MinGW" );
943949
944950 // Merge the entries into null-separated string.
945951 llvm::SmallString<64 > EntriesString;
@@ -972,7 +978,7 @@ void IRGenModule::emitAutolinkInfo() {
972978 llvm::GlobalValue::CommonLinkage,
973979 llvm::Constant::getNullValue (Int1Ty),
974980 buf.str ());
975- if (Triple. isOSBinFormatCOFF ())
981+ if (useDllStorage ())
976982 symbol->setDLLStorageClass (llvm::GlobalValue::DLLExportStorageClass);
977983 }
978984}
@@ -1075,6 +1081,8 @@ void IRGenModule::error(SourceLoc loc, const Twine &message) {
10751081 message.toStringRef (buffer));
10761082}
10771083
1084+ bool IRGenModule::useDllStorage () { return ::useDllStorage (Triple); }
1085+
10781086void IRGenerator::addGenModule (SourceFile *SF, IRGenModule *IGM) {
10791087 assert (GenModules.count (SF) == 0 );
10801088 GenModules[SF] = IGM;
0 commit comments