Skip to content
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

Fix cross-compiling i686-pc-windows-gnu from Linux #49633

Closed
wants to merge 1 commit into from
Closed

Fix cross-compiling i686-pc-windows-gnu from Linux #49633

wants to merge 1 commit into from

Conversation

neersighted
Copy link

@neersighted neersighted commented Apr 4, 2018

This is still very rough and serves as a proof-of-concept for fixing the Linux -> 32-bit MinGW cross compilation workflow. Currently, clang and GCC's MinGW targets both only support DW2 (DWARF) or SJLJ (Set Jump Long Jump) unwinding on 32-bit Windows.

The default for GCC (and the way it is shipped on every major distro) is to use SJLJ on Windows, as DWARF cannot traverse non-DWARF frames. This would work fine, except for the fact that libgcc (our C runtime on the MinGW platform) exports symbols under a different name when configured to use SJLJ-style unwinding, and uses a preprocessor macro internally to alias them.

Because of this, we have to detect this scenario and link to the correct symbols ourselves.

This serves as a proof of concept, and has been tested with a full bootstrap and test suite run on both x86_64-unknown-linux-gnu and i686-pc-windows-gnu, as well as cross-compilation of some of my own projects.

Obviously, the detection is a bit unrefined. Right now we unconditionally use SJLJ when compiling Linux -> 32-bit MinGW. I'd like to add feature detection using compiler build flags or autotools-style compilation and object analysis. Input on the best way to proceed here is welcome.

Also, currently there is copy-pasted/duplicated code in libunwind. Ideally, this could be reduced, but this would likely require a rethinking of how iOS is special-cased above, to avoid further duplication. Input on how to best structure this file is requested.

Resolves #32859

r? @alexcrichton

This is still very rough and serves as a proof-of-concept for fixing
Linux -> 32-bit MinGW cross compilation workflow. Currently, clang and
GCC's MinGW targets both only support DW2 (DWARF) or SJLJ (Set Jump Long
Jump) unwinding on 32-bit Windows.

The default for GCC (and the way it is shipped on every major distro) is
to use SJLJ on Windows, as DWARF cannot traverse non-DWARF frames. This
would work fine, except for the fact that libgcc (our C runtime on the
MinGW platform) exports symbols under a different name when configured
to use SJLJ-style unwinding, and uses a preprocessor macro internally to
alias them.

Because of this, we have to detect this scenario and link to the correct
symbols ourselves. Linking has been tested with a full bootstrap on both
x86_64-unknown-linux-gnu and i686-pc-windows-gnu, as well as
cross-compilation of some of my own projects.

Obviously, the detection is a bit unrefined. Right now we
unconditionally use SJLJ when compiling Linux -> MinGW. I'd like to add
feature detection using compiler build flags or autotools-style
compilation and object analysis. Input on the best way to proceed here
is welcome.

Also, currently there is copy-pasted/duplicated code in libunwind.
Ideally, this could be reduced, but this would likely require a
rethinking of how iOS is special-cased above, to avoid further
duplication. Input on how to best structure this file is requested.
@neersighted
Copy link
Author

I've also removed a reduced, copy-pasted version of cfg_if! that appears to predate the full (still copy-pasted) version in this crate. I'm not sure what the convention is with stdlib dependencies. Would adding a dependency on cfg_if! as published in Cargo be acceptable, or do we wish to avoid such dependencies in the stdlib?

@alexcrichton
Copy link
Member

Hm does this produce working binaries in the sense that destructors are run? I'd expect that because LLVM isn't doing setjmp/longjmp whenever you panicked you'd skip destructors, right?

@pietroalbini pietroalbini added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 4, 2018
@bors
Copy link
Contributor

bors commented Apr 5, 2018

☔ The latest upstream changes (presumably #49684) made this pull request unmergeable. Please resolve the merge conflicts.

@pietroalbini pietroalbini added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 9, 2018
@pietroalbini
Copy link
Member

Thank you for this PR @neersighted! @alexcrichton asked some questions, could you answer them soon? Also, there are some conflicts that needs to be resolved.

@neersighted
Copy link
Author

Apologies for the delay here. Yeah, on further review, conditionals probably need to be revised for the personality function. I'll follow up once I can test those changes in a few days.

@pietroalbini
Copy link
Member

Ping from triage @neersighted! Will you have some time to work on this again in the near future?

@neersighted
Copy link
Author

After some more testing, I've discovered this approach will not work with Rust as-shipped, as the pre-compiled stdlib binaries shipped to rustup are compiled on their native platforms. With the way Rust is currently distributed, I don't think fixing this will be possible at the moment (until Xargo functionality is merged into Cargo, most likely).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't cross compile from Linux to Windows (i686)
4 participants