-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[swiftc] Fixed for Cygwin #3841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -38,6 +38,11 @@ if(SWIFT_HOST_VARIANT MATCHES "${SWIFT_DARWIN_VARIANTS}") | |||
LINK_FLAGS " -lobjc -Wl,-force_load,\"${SWIFT_REPL_ARCLITE}\"") | |||
endif() | |||
|
|||
if("${CMAKE_SYSTEM_NAME}" STREQUAL "CYGWIN") | |||
set_property(TARGET swift APPEND_STRING PROPERTY | |||
LINK_FLAGS " -Wl,--allow-multiple-definition") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linker generates the error of multiple definition of guard variable for swift::ImmutablePointerSetFactory<swift::SILInstruction>::EmptyPtrSet
in libswiftSILOptimizer.a
.
And the EmptyPtrSet
is defined at include/swift/Basic/ImmutablePointerSet.h
.
The symbol is defined in the object files compiled from all lib/SILOptimizer/ARC/*.cpp
(10 files). I think it is related to 'template instantiation'. But I don't know whether those sources are good or bad.
I added this flag instead of touching sources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GNU ld linker has a very poor approximation of COFF support. It fails constantly under a myriad of conditions, including COMDAT symbols. The --allow-multiple-definitions
is attempting to compensate for a poor implementation of a COFF linker. To make things worse, this is something which is hardcoded into the gcc specs IIRC, and has even partially made its way into clang :-(. I for one welcome our new LLVM overlords^W^W^W^Wlld.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove this part. Updating clang to 3.8.1 with recent released cygwin package, the link flag can be removed.
With some test code, I found the Cygwin clang compiler 3.7.1 generates wrong section type for the data section which has a guard variable for template-static-member. That leads to linker's multiple definition message.
@compnerd Mind looking this over as well? |
|
||
if (triple.isWindowsGNUEnvironment()) | ||
return "mingw"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nicer to use a switch here instead. That way if we run into similar issues in the future, its easier to extend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean a nested switch in case llvm::Triple::Win32:
?
switch (triple.getEnvironment()) {
case llvm::Triple::Cygnus:
return "cygwin";
case llvm::Triple::GNU:
return "mingw":
default:
return "windows";
}
I can not imagine how cover those with single switch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, a nested switch. You should be able to do a covered switch there, and have most of the environments be unreachable.
32d22d6
to
d3b5697
Compare
d3b5697
to
5f25625
Compare
8d605a8
to
1fb9249
Compare
ping? |
@@ -43,7 +43,7 @@ irgen::emitTypeLayoutVerifier(IRGenFunction &IGF, | |||
/*var arg*/ false); | |||
auto verifierFn = IGF.IGM.Module.getOrInsertFunction( | |||
"_swift_debug_verifyTypeLayoutAttribute", verifierFnTy); | |||
if (IGF.IGM.Triple.isOSBinFormatCOFF()) | |||
if (IGF.IGM.Triple.isOSBinFormatCOFF() && !IGF.IGM.Triple.isOSCygMing()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use IGF.IGM.useDLLStorage()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed it. Updated it just.
ac75188
to
ba7e600
Compare
Any more reviews ? |
Looks like this needs rebase and conflict resolution too |
ba7e600
to
3cdf40b
Compare
@slavapestov I rebased and resolved conflicts this PR. |
This was mostly waiting for @compnerd's sign-off, I think. |
@@ -440,6 +440,7 @@ llvm::Constant *swift::getRuntimeFn(llvm::Module &Module, | |||
fn->setCallingConv(cc); | |||
|
|||
if (llvm::Triple(Module.getTargetTriple()).isOSBinFormatCOFF() && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this should use useDllStorage()
instead of adding the negation check so that this is more similar to the previous case.
@@ -519,7 +520,8 @@ 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 (llvm::Triple(Module.getTargetTriple()).isOSBinFormatCOFF() && | |||
!llvm::Triple(Module.getTargetTriple()).isOSCygMing()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll change them.
TargetInfo.OutputObjectFormat == llvm::Triple::MachO || | ||
Triple.isPS4()) { | ||
if ((TargetInfo.OutputObjectFormat == llvm::Triple::COFF && | ||
(!Triple.isOSCygMing() || Triple.getArch() == llvm::Triple::thumb)) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the special case for cygwin on Windows ARM here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test script - https://github.com/apple/swift/blob/master/test/IRGen/autolink-coff.swift - asserts the target thumbv7--windows-gnu
to use the MSVC-style autolink, which uses .drectve
section.
I created the autolink-coff-x86.swift
for MinGW (x86--windows-gnu
) to test the Linux-style autolink.
If we drop/modify the autolink test case for thumbv7--windows-gnu
, the code will be simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets change the test for that target. Really, the only Windows ARM target that I know of which is tested/works is Windows itanium (with clang) or msvc (with msvc).
Fixed for the difference of Cygwin with other Windows variants (MSVC, Itanium, MinGW). - The platform name is renamed to "cygwin" from "windows" which is used for searching the standard libraries. - The consideration for DLL storage class (DllExport/DllImport) is not required for Cygwin and MinGW. There is no problem when linking in these environment. - Cygwin should use large memory model as default.(This may be changed if someone ports to 32bit) - Cygwin and MinGW should use the autolink feature in the sameway of Linux due to the linker's limit.
3cdf40b
to
b8dd577
Compare
@compnerd The test script |
@swift-ci Please smoke test |
Ok, I'm merging this as soon as @cmpnerd gives the go-ahead (or does @compnerd already have commit access)? |
@swift-ci Please smoke test |
@slavapestov yeah, I do have commit access :-). |
What's in this pull request?
Resolved bug number: (SR-)
Before merging this pull request to apple/swift repository:
Triggering Swift CI
The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:
Smoke Testing
A smoke test on macOS does the following:
device standard libraries are not built.
version of these tests are not run.
A smoke test on Linux does the following:
tests are not run.
Validation Testing
Lint Testing
Note: Only members of the Apple organization can trigger swift-ci.
Fixed for the difference of Cygwin with other Windows variants (MSVC,
Itanium, MinGW).
for searching the standard libraries.
required for Cygwin and MinGW. There is no problem when linking in
these environment.
if someone ports to 32bit)
Linux due to the linker's limit.