Description
Currently when linking a Rust staticlib into an executable or shared library with another linker, the resulting file sizes are multiple times bigger than when having rustc
do the job directly.
This happens because lots of unnecessary symbols are exported, and the linker is not removing any unnecessary sections either. Basically, all of the std library and any other Rust crate are included instead of stripping away unnecessary parts.
-
staticlib
s are exporting all public symbols from both the crate itself as well as any Rust dependency that is included inside it, including the standard library. meson's currently approach to symbol visibility is to simply use visibility attributes but that doesn't work in this case because of the "link whole" approach ofstaticlib
s. I'm not sure how this can be solved on the meson side in a useful way. This is kind of related to Add support for symbol visibility export files #4747 -
staticlib
s contain the whole static libraries of their dependencies, so there's a lot of unnecessary code in there.--gc-sections
(or-dead_strip
on macOS) would get rid of them for executables, and also for shared libraries once 1. is solved. Currently there is no cross-toolchain way of specifying this in meson from what I can see, and this should probably happen automatically when linking instaticlib
s anyway.
Somewhat related Rust issues: rust-lang/rust#111593 and rust-lang/rust#111594