Skip to content

[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

Merged
merged 1 commit into from
Jan 20, 2017

Conversation

tinysun212
Copy link
Contributor

What's in this pull request?

Resolved bug number: (SR-)


Before merging this pull request to apple/swift repository:

  • Test pull request on Swift continuous integration.

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

Platform Comment
All supported platforms @swift-ci Please smoke test
All supported platforms @swift-ci Please smoke test and merge
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

A smoke test on macOS does the following:

  1. Builds the compiler incrementally.
  2. Builds the standard library only for macOS. Simulator standard libraries and
    device standard libraries are not built.
  3. lldb is not built.
  4. The test and validation-test targets are run only for macOS. The optimized
    version of these tests are not run.

A smoke test on Linux does the following:

  1. Builds the compiler incrementally.
  2. Builds the standard library incrementally.
  3. lldb is built incrementally.
  4. The swift test and validation-test targets are run. The optimized version of these
    tests are not run.
  5. lldb is tested.

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
All supported platforms @swift-ci Please test and merge
OS X platform @swift-ci Please test OS X platform
OS X platform @swift-ci Please benchmark
Linux platform @swift-ci Please test Linux platform

Lint Testing

Language Comment
Python @swift-ci Please Python lint

Note: Only members of the Apple organization can trigger swift-ci.

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.

@@ -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")
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

@jrose-apple
Copy link
Contributor

@compnerd Mind looking this over as well?


if (triple.isWindowsGNUEnvironment())
return "mingw";

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

@tinysun212 tinysun212 force-pushed the pr-swiftc-cygwin-2 branch from 32d22d6 to d3b5697 Compare July 30, 2016 07:56
@tinysun212 tinysun212 changed the title [swiftc/driver] Fixes for Cygwin [swiftc] Fixed for Cygwin Aug 2, 2016
@tinysun212 tinysun212 force-pushed the pr-swiftc-cygwin-2 branch 2 times, most recently from 8d605a8 to 1fb9249 Compare August 14, 2016 23:44
@tinysun212
Copy link
Contributor Author

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())
Copy link
Member

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()?

Copy link
Contributor Author

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.

@tinysun212
Copy link
Contributor Author

Any more reviews ?

@slavapestov
Copy link
Contributor

Looks like this needs rebase and conflict resolution too

@slavapestov slavapestov self-assigned this Jan 13, 2017
@tinysun212
Copy link
Contributor Author

@slavapestov I rebased and resolved conflicts this PR.

@jrose-apple
Copy link
Contributor

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() &&
Copy link
Member

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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar

Copy link
Contributor Author

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)) ||
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.
@tinysun212
Copy link
Contributor Author

tinysun212 commented Jan 18, 2017

@compnerd The test script autolink-coff.swift was changed and other reviews were applied.

@slavapestov
Copy link
Contributor

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor

Ok, I'm merging this as soon as @cmpnerd gives the go-ahead (or does @compnerd already have commit access)?

@slavapestov
Copy link
Contributor

@swift-ci Please smoke test

@compnerd
Copy link
Member

@slavapestov yeah, I do have commit access :-).

@slavapestov slavapestov merged commit 7b5cf4a into swiftlang:master Jan 20, 2017
@tinysun212 tinysun212 deleted the pr-swiftc-cygwin-2 branch October 20, 2018 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants