Skip to content

Big static array causes rlib to bloat in size #136519

@nebulark

Description

@nebulark

A big static array inside a library causes the generated lib file to bloat in size, even if it is zero initialized.
I tried this code:

static BUFFER : [u8; 1 << 29] = unsafe { std::mem::zeroed() };

I would expect that this would not affect the size of library.
Instead this causes the library to include a LOT of 0s, increasing the size in this example to over 1GB.
The final executeable is unaffected, only the .rlib file bloats.

Meta

This happens in stable and nightly

rustc --version --verbose:

rustc 1.86.0-nightly (1e9b0177d 2025-01-24)
binary: rustc
commit-hash: 1e9b0177da38e3f421a3b9b1942f1777d166e06a
commit-date: 2025-01-24
host: x86_64-pc-windows-msvc
release: 1.86.0-nightly
LLVM version: 19.1.7

Metadata

Metadata

Assignees

Labels

C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchI-heavyIssue: Problems and improvements with respect to binary size of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions