Uh oh!
There was an error while loading. Please reload this page.
Enable windows-gnu target to link to libgcc dynamically. - #90020
Enable windows-gnu target to link to libgcc dynamically.#90020Berrysoft wants to merge 6 commits into
windows-gnu target to link to libgcc dynamically.#90020Conversation
rust-highfive
commented
Oct 18, 2021
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. |
rust-highfive
commented
Oct 18, 2021
|
Mark-Simulacrum
commented
Oct 18, 2021
r? @petrochenkov maybe? |
petrochenkov
commented
Oct 19, 2021
cc @Amanieu@mati865 If it does make sense then the changes here look entirely reasonable to me. |
Amanieu
commented
Oct 19, 2021
I think this breaks the case where |
@Amanieu I don't think so. |
petrochenkov
commented
Oct 20, 2021
Technically you can, the compiler won't report an error, it just doesn't make sense on most targets. |
Berrysoft
commented
Oct 20, 2021
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 |
mati865
commented
Oct 20, 2021
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. |
Berrysoft
commented
Oct 20, 2021
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 |
mati865
commented
Oct 20, 2021
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 |
Berrysoft
commented
Oct 21, 2021
Which test? Do you mean it will break because it enables |
Berrysoft
commented
Oct 21, 2021
As for #72241, I think this pull request solves that: if |
Berrysoft
commented
Oct 21, 2021
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. |
mati865
commented
Oct 21, 2021
I meant the other part of that comment: |
mati865
commented
Oct 21, 2021
I don't remember which one, you would have to run them. |
Berrysoft
commented
Oct 21, 2021
No, it needn't.
Oh, OK. I finally know why there was For the exceptions across DLLs, I'll investigate further. |
Berrysoft
commented
Oct 21, 2021
@mati865 I ran the test against target |
mati865
commented
Oct 21, 2021
I'm too busy to look into tests now but I'm fairly sure you need stage1 compiler and std. |
petrochenkov
commented
Oct 21, 2021
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. |
Berrysoft
commented
Oct 21, 2021
I've tested on Linux that when |
Berrysoft
commented
Oct 22, 2021
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 |
Berrysoft
commented
Oct 23, 2021
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. |
bors
commented
Oct 30, 2021
☔ The latest upstream changes (presumably #90205) made this pull request unmergeable. Please resolve the merge conflicts. |
petrochenkov
commented
Nov 15, 2021
@Berrysoft In theory if we are linking to any dylib, then we should switch the executable to |
petrochenkov
commented
Nov 27, 2021
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 |
petrochenkov
commented
Dec 3, 2021
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:
|
petrochenkov
commented
Dec 3, 2021
What this means for windows gnu - it'll get |
petrochenkov
commented
Dec 3, 2021
@Berrysoft |
Berrysoft
commented
Dec 3, 2021
@petrochenkov Maybe you're right, and we need to rethink about all these problems. |
mati865
commented
Dec 3, 2021
What about MSVC where CRT can be statically linked? |
petrochenkov
commented
Dec 3, 2021
@mati865 |
mati865
commented
Dec 3, 2021
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 |
petrochenkov
commented
Dec 4, 2021
@mati865 The design in #90020 (comment) still works in this case - shared libgcc/libpthread are indeed necessary for managing shared resources (cross-binary exceptions). |
Dylan-DPC
commented
Feb 19, 2022
@Berrysoft any updates on this? |
JohnCSimon
commented
Mar 20, 2022
@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-staticis enabled or disabled.The
libunwindpart 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-staticas default when using GNU toolchain on Windows?