Skip to content

Move metadata out of dylibs #23366

Closed
@vadimcn

Description

@vadimcn
Contributor

Crate metadata constitute a significant proportion of Rust dylibs. It's only needed for compilation; otherwise it just bloats up the size of Rust programs, and, unlike debug info, can't even be easily stripped.
In the case of dylibs, we could move metadata out into a companion file (say, <library>.rsmd), which developers may choose to not distribute if linking to the library is not expected (for example, Rust's own stage0 binaries).
I think this approach would be very congruent with Rust's philosophy of zero cost abstractions. The only downside I can see, is that distribution of dylibs as libraries would become slightly less convenient as there would be two files instead of one.

Activity

nagisa

nagisa commented on Mar 14, 2015

@nagisa
Member

Is is actually pretty easy to strip them. The incantation is something similar to strip -R __note.rustc for apples and strip -R .note.rustc for everything else.

vadimcn

vadimcn commented on Mar 15, 2015

@vadimcn
ContributorAuthor

Is is actually pretty easy to strip them.

Ah, that's nice to know!
Still, one has to jump through extra hoops to get the optimal binary. This seems... sub-optimal.
People are already asking why Rust executables are so much bigger than C++'s. Soon they'll notice that dylibs are larger too.

added
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
on Jun 6, 2016
steveklabnik

steveklabnik commented on Jun 6, 2016

@steveklabnik
Member

Triage: no change, marking with enhancement, since it can be stripped.

jonas-schievink

jonas-schievink commented on Jun 6, 2016

@jonas-schievink
Contributor

Don't cdylibs solve this?

retep998

retep998 commented on Jun 6, 2016

@retep998
Member

cdylib does solve this issue for itself, however the issue still exists for dylib for people who really want to have their Rust program depends on Rust dylibs instead of statically linking them. Also this has an impact on the size of Rust distributions, since rustc's dependencies are all in dylib form (so plugins can work correctly), while in reality they don't need any of that metadata bloat since code is compiled against the libraries in the appropriate rustlib folder.

cuviper

cuviper commented on Jul 24, 2016

@cuviper
Member

Note that it's not actually easy to strip these notes according to #26764.

Another fun aspect is that systems which use .gnu_debugdata, described here, will end up duplicating the entire .note.rustc. The given procedure uses objcopy --only-keep-debug, which also preserves notes, then further strips into a mini_debuginfo file with just symbol tables and those notes. That mini_debuginfo finally gets compressed into a new .gnu_debugdata section on the original file. But it's not so "mini" when it contains all of .note.rustc.

That MiniDebuginfo procedure can probably add an exclusion, the same as it does for .gdb_index and .comment already, but it wouldn't be nice if every language had their own special exclusions here...

cuviper

cuviper commented on Aug 15, 2016

@cuviper
Member

Now that #35409's 1bb1444 converted it away from an allocated note, it should be fine to be stripped.

steveklabnik

steveklabnik commented on Sep 30, 2017

@steveklabnik
Member

Triage: not aware of any work on this issue.

gilescope

gilescope commented on Oct 29, 2020

@gilescope
Contributor

Now that we have cargo strip can we close this?

bjorn3

bjorn3 commented on May 15, 2022

@bjorn3
Member

#93945 once I revive it would fix this issue.

7 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-metadataArea: Crate metadataC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @steveklabnik@cuviper@sanxiyn@retep998@nagisa

      Issue actions

        Move metadata out of dylibs · Issue #23366 · rust-lang/rust