-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Enable windows-gnu
target to link to libgcc
dynamically.
#90020
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Mark-Simulacrum (or someone else) soon. Please see the contribution instructions for more information. |
|
r? @petrochenkov maybe? |
cc @Amanieu @mati865 If it does make sense then the changes here look entirely reasonable to me. |
I think this breaks the case where |
@Amanieu I don't think so. |
Technically you can, the compiler won't report an error, it just doesn't make sense on most targets. |
No. The compiler will complain about not finding
Yes, at least on this target, it doesn't make sense at all. MinGW won't statically link with |
MinGW is probably never going to support static CRT (unless MS opens UCRT sources) so Now this makes linking to shared libgcc as the default which is going make executables depend on libgcc and winpthreads DLLs. There is Rust test which is going to fail in such case. |
If we treat the unwind library is a part of C runtime, Therefore, just Even though if there's someday when MS opens their UCRT source, and MinGW could be able to link with UCRT statically, I don't think we need to add another feature to precisely control which and which not to be statically linked. Just static all it can, or dynamic all it can. And if we decide to make I just mean to give developers a choice to dynamically link to |
This will break exceptions across DLLs on 32-bit target which is also has a test IIRC. Don't get me wrong, I would love to see this working with MinGW targets but I have no idea how to do it correctly from the beginning. I won't oppose merging this if maintainers agree this is the way to go. To keep current behaviour unchanged this might require adding additional feature like proposed in #72241 (comment) or some kind of heuristic whether to make default |
Which test? Do you mean it will break because it enables |
As for #72241, I think this pull request solves that: if |
OK, I have to admit that I'm changing the behavior now. Anyway the compiler behavior will be changed, no matter adding Yes, a new feature may be less misleading, and maybe good to those who have OCD. But it simply wastes a lot of time, and finally we will find that, we create a new target feature specified for
We won't get any more benefit to propersal a new feature, but only much more complexity. |
I meant the other part of that comment: |
I don't remember which one, you would have to run them. |
No, it needn't.
Oh, OK. I finally know why there was For the exceptions across DLLs, I'll investigate further. |
@mati865 I ran the test against target |
I'm too busy to look into tests now but I'm fairly sure you need stage1 compiler and std. |
The meaning of This is different from ELF-based targets, where we basically remove dynamic linker from the story when linking libc statically, and thus require linking everything statically in this mode. |
I've tested on Linux that when |
It needs separate triple for other reasons like using native TLS instead of emutls and UCRT instead of MSVCRT. Neither of them works properly when mixed with GCC made binaries.
This still is behavioural change, previously executables had no runtime dependencies on unwinding library out of the box. With this PR it's no longer the case and user has to use |
OK, but it's another question. Now they belong to the same target (and no one actually trying to mix different toolchains), and I think we need new issues to solve that.
Yes, it needs more changes and more fixes to keep the behavior. In practical, if |
As long as you have to fix the tests it means this target behaviour is changed.
To keep it we would need new feature that detects which option should be default. User would still use |
OK, so I'm now asking that if it is acceptable that I'm changing the behavior. To my opinion, it is much more natural. |
☔ The latest upstream changes (presumably #90205) made this pull request unmergeable. Please resolve the merge conflicts. |
@Berrysoft In theory if we are linking to any dylib, then we should switch the executable to |
I'm basically ok with switching the windows-gnu targets to The only case that worries me is the previous comment #90020 (comment) - an executable with dynamic crate deps (e.g. dynamic libstd). Perhaps we just need more fine-grained options related to |
I went through major targets supporting dynamic linking and they all seem to expose relatively similar behavior with regards to linking CRT (libc or analogues) dynamically or statically. An executable and all its dynamic dependencies must share a common CRT for things like cross-binary exceptions and cross-binary allocations/deallocations on platform like Windows (which don't do most of OS interactions through CRT), and maybe for other shared resource management as well on platforms like Linux (which do most of OS interactions through CRT).
Whether a dynamic library may require managing shared resources is ultimately a user's choice. Side note: for targets doing dynamic linking in userspace via ELF interpreter field (Linux), we can remove the interpreter field and speedup their launch if there's no dynamic dependencies at all (CRT or others). So the question is what "with(out) an explicit request" above means. Considering the above, I think my suggested solution is:
|
What this means for windows gnu - it'll get |
@Berrysoft |
@petrochenkov Maybe you're right, and we need to rethink about all these problems. |
What about MSVC where CRT can be statically linked? |
@mati865 |
Well I find it confusing because MSVC is the only Windows target right now that allows statically linking CRT into executables. So judging by the name I'd expect if I pass |
@mati865 The design in #90020 (comment) still works in this case - shared libgcc/libpthread are indeed necessary for managing shared resources (cross-binary exceptions). |
@Berrysoft any updates on this? |
@Berrysoft @rustbot label: +S-inactive |
Closes #89919.
It seems that the change is trival, and I've tested on my own computer with success, with both
crt-static
is enabled or disabled.The
libunwind
part is not tested, but it should work in theory, according to the patch of MSYS2.There's one more problem needs to talk about: should we enable
crt-static
as default when using GNU toolchain on Windows?