Consider dynamically link to libgcc_s
when targeting windows-gnu
#89919
Labels
O-windows
Operating system: Windows
libgcc_s
when targeting windows-gnu
#89919
Description
Rust now choose to statically link to
libgcc_eh
andlibpthread
when no-C prefer-dynamic
is specified:rust/compiler/rustc_target/src/spec/windows_gnu_base.rs
Lines 50 to 58 in 1ddd4e6
It is because that some software end users may not have MinGW64 runtimes installed, and it may be complicated for developers to bundle the MinGW64 runtime. However, this case should have been correctly handled with
-C target-feature=+crt-static
.Pros
Smaller binary size: We could simply link with the system MinGW64 runtime, and it will help reduce some of the binary size. The distributed binary will also benifit from newer MinGW64 runtime without recompiling.
No sidebacks when using
crt-static
: MinGW64 doesn't statically link tomsvcrt
due to license restrictions. Therefore the modification here won't make difference when usingcrt-static
. It should perform as usual, and simply bundle the MinGW64 runtime.Future exception safety: I've noticed the in design feature for future exception safety. Then it needs the rust binary to dynamically link to the MinGW64 runtime.
Behavior consistence: Most other targets only link to the unwind runtime statically when feature
crt-static
is on. We could set it on as default in thewindows-gnu
target, but leave the choice to the developers.Cons
MISC breaking: Some crates may assume the original behavior, although I haven't found one.
Other notes
Not only the
windows_gnu_base.rs
should be modified,library/unwind/src/lib.rs
should also be modified to properly deal withcrt-static
feature. Also, it should be investigated that where to linklibpthread
statically.I came to this idea when developing with Rust and GTK. GTK depends on a lot of other libraries, for example, harfbuzz, which itself is written by C++ and links to
libgcc_s
. Therefore I needn't statically link tolibgcc_eh
, because anyway I need to ship the binaries with alibgcc
. However, I couldn't find a switch to turn it off. I couldn't use-C prefer-dynamic
, because I don't want to dynamically link tolibstd-xxxxxxx
, which only increases the final binaries size. In addition, some crates, for example, hyper, blocks theprefer-dynamic
build, because of its (maybe wrongly written)crate-type
.The text was updated successfully, but these errors were encountered: