Skip to content

Symbols blow up binary size to an unreasonable degree on x86_64-unknown-linux-gnu #46034

Closed
@crumblingstatue

Description

@crumblingstatue

Standard hello world program generated with cargo new --bin mytest

fn main() {
    println!("Hello, world!");
}

Built with cargo build --release, the resulting binary size is 4270408 bytes.
This sounds unreasonably large for a hello world program.

After strip --strip-all, we get 449224.

The non-stripped version is almost 10 times larger than the stripped version. Why?

This is with rustc 1.23.0-nightly (fa26421f5 2017-11-15), installed through rustup.

$ rustc -vV
rustc 1.23.0-nightly (fa26421f5 2017-11-15)
binary: rustc
commit-hash: fa26421f56e385b1055e65b29a55b36bb2eae23e
commit-date: 2017-11-15
host: x86_64-unknown-linux-gnu
release: 1.23.0-nightly
LLVM version: 4.0

Here is stable rustc 1.21.0 (3b72af97e 2017-10-09) for good measure:
Normal: 4059968
Stripped: 404096

This time, the initial size is lower, but the stripped size is even smaller, making the non-stripped version slightly more than 10 times larger.

(As a sidenote, I've been noticing that binary sizes for the same program have been steadily increasing with every new rustc, at least on x86_64-unknown-linux-gnu, but that's a separate issue, I suppose)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.E-help-wantedCall for participation: Help is requested to fix this issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.I-heavyIssue: Problems and improvements with respect to binary size of generated code.O-linuxOperating system: Linux

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions