Merge pull request #3841 from tinysun212/pr-swiftc-cygwin-2

[swiftc] Fixed for Cygwin
This commit is contained in:
Slava Pestov
2017-01-19 20:17:47 -08:00
committed by GitHub
14 changed files with 74 additions and 43 deletions

View File

@@ -117,6 +117,11 @@ static clang::CodeGenerator *createClangCodeGenerator(ASTContext &Context,
return ClangCodeGen;
}
/// A helper for determining if the triple uses the DLL storage
static bool useDllStorage(const llvm::Triple &Triple) {
return Triple.isOSBinFormatCOFF() && !Triple.isOSCygMing();
}
IRGenModule::IRGenModule(IRGenerator &irgen,
std::unique_ptr<llvm::TargetMachine> &&target,
SourceFile *SF, llvm::LLVMContext &LLVMContext,
@@ -442,7 +447,7 @@ llvm::Constant *swift::getRuntimeFn(llvm::Module &Module,
if (auto fn = dyn_cast<llvm::Function>(cache)) {
fn->setCallingConv(cc);
if (llvm::Triple(Module.getTargetTriple()).isOSBinFormatCOFF() &&
if (::useDllStorage(llvm::Triple(Module.getTargetTriple())) &&
(fn->getLinkage() == llvm::GlobalValue::ExternalLinkage ||
fn->getLinkage() == llvm::GlobalValue::AvailableExternallyLinkage))
fn->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
@@ -522,7 +527,7 @@ llvm::Constant *swift::getWrapperFn(llvm::Module &Module,
auto *globalFnPtr = new llvm::GlobalVariable(
Module, fnPtrTy, false, llvm::GlobalValue::ExternalLinkage, nullptr,
symbol);
if (llvm::Triple(Module.getTargetTriple()).isOSBinFormatCOFF())
if (::useDllStorage(llvm::Triple(Module.getTargetTriple())))
globalFnPtr->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
// Forward all arguments.
@@ -641,7 +646,7 @@ llvm::Constant *IRGenModule::getEmptyTupleMetadata() {
EmptyTupleMetadata = Module.getOrInsertGlobal(
MANGLE_AS_STRING(METADATA_SYM(EMPTY_TUPLE_MANGLING)),
FullTypeMetadataStructTy);
if (Triple.isOSBinFormatCOFF())
if (useDllStorage())
cast<llvm::GlobalVariable>(EmptyTupleMetadata)
->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
return EmptyTupleMetadata;
@@ -655,7 +660,7 @@ llvm::Constant *IRGenModule::getObjCEmptyCachePtr() {
// struct objc_cache _objc_empty_cache;
ObjCEmptyCachePtr = Module.getOrInsertGlobal("_objc_empty_cache",
OpaquePtrTy->getElementType());
if (Triple.isOSBinFormatCOFF())
if (useDllStorage())
cast<llvm::GlobalVariable>(ObjCEmptyCachePtr)
->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
} else {
@@ -688,7 +693,7 @@ Address IRGenModule::getAddrOfObjCISAMask() {
assert(TargetInfo.hasISAMasking());
if (!ObjCISAMaskPtr) {
ObjCISAMaskPtr = Module.getOrInsertGlobal("swift_isaMask", IntPtrTy);
if (Triple.isOSBinFormatCOFF())
if (useDllStorage())
cast<llvm::GlobalVariable>(ObjCISAMaskPtr)
->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
}
@@ -854,7 +859,7 @@ void IRGenModule::addLinkLibrary(const LinkLibrary &linkLib) {
llvm::SmallString<64> buf;
encodeForceLoadSymbolName(buf, linkLib.getName());
auto symbolAddr = Module.getOrInsertGlobal(buf.str(), Int1Ty);
if (Triple.isOSBinFormatCOFF())
if (useDllStorage())
cast<llvm::GlobalVariable>(symbolAddr)
->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
@@ -919,9 +924,9 @@ void IRGenModule::emitAutolinkInfo() {
}),
AutolinkEntries.end());
if (TargetInfo.OutputObjectFormat == llvm::Triple::COFF ||
TargetInfo.OutputObjectFormat == llvm::Triple::MachO ||
Triple.isPS4()) {
if ((TargetInfo.OutputObjectFormat == llvm::Triple::COFF &&
!Triple.isOSCygMing()) ||
TargetInfo.OutputObjectFormat == llvm::Triple::MachO || Triple.isPS4()) {
llvm::LLVMContext &ctx = Module.getContext();
if (!LinkerOptions) {
@@ -938,8 +943,9 @@ void IRGenModule::emitAutolinkInfo() {
assert(FoundOldEntry && "Could not replace old linker options entry?");
}
} else {
assert(TargetInfo.OutputObjectFormat == llvm::Triple::ELF &&
"expected ELF output format");
assert((TargetInfo.OutputObjectFormat == llvm::Triple::ELF ||
Triple.isOSCygMing()) &&
"expected ELF output format or COFF format for Cygwin/MinGW");
// Merge the entries into null-separated string.
llvm::SmallString<64> EntriesString;
@@ -972,7 +978,7 @@ void IRGenModule::emitAutolinkInfo() {
llvm::GlobalValue::CommonLinkage,
llvm::Constant::getNullValue(Int1Ty),
buf.str());
if (Triple.isOSBinFormatCOFF())
if (useDllStorage())
symbol->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
}
}
@@ -1075,6 +1081,8 @@ void IRGenModule::error(SourceLoc loc, const Twine &message) {
message.toStringRef(buffer));
}
bool IRGenModule::useDllStorage() { return ::useDllStorage(Triple); }
void IRGenerator::addGenModule(SourceFile *SF, IRGenModule *IGM) {
assert(GenModules.count(SF) == 0);
GenModules[SF] = IGM;