Skip to content

rust: Need to automatically do symbol export handling and --gc-sections when linking a Rust staticlib into another target #11792

Open
@sdroege

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.

  1. staticlibs 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 of staticlibs. 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

  2. staticlibs 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 in staticlibs anyway.

Somewhat related Rust issues: rust-lang/rust#111593 and rust-lang/rust#111594

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions