rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
94.82k stars 12.22k forks source link

28x binary size regression in recent nightly #85519

Closed jonas-schievink closed 3 years ago

jonas-schievink commented 3 years ago

There seems to be a significant regression in binary size in the most recent nightly:

nightly-2021-05-19

$ size target/thumbv6m-none-eabi/debug/hello
   text    data     bss     dec     hex filename
   6056      48    1032    7136    1be0 target/thumbv6m-none-eabi/debug/hello

nightly-2021-05-20

$ size target/thumbv6m-none-eabi/debug/hello
   text    data     bss     dec     hex filename
 201372      48    1032  202452   316d4 target/thumbv6m-none-eabi/debug/hello

Steps to reproduce:

Commits in that range: https://github.com/rust-lang/rust/compare/4e3e6db01...f94942d84

https://github.com/rust-lang/rust/pull/85274 looks suspicious (cc @luqmana)

jamesmunns commented 3 years ago

This seems to have been noticed here as well: https://github.com/rust-osdev/bootloader/pull/168

Edit: Fixed link to rust-osdev repo instead of this issue

Edit 2: This also indicates you can work-around the regression by manually passing --gc-sections as a linker flag.

jamesmunns commented 3 years ago

Also as a note, @japaric tested this with using arm-none-eabi-ld as the linker instead of the default rust-lld, and this issue remained (referring to #85274). He can confirm whether he set the "linker flavor" or similar as well.

Dirbaio commented 3 years ago

it's very likely #85274, since adding -C link-arg=--gc-sections to rustflags fixes the bloat.

nagisa commented 3 years ago

Is the linker for this target guaranteed to be gnu ld? Doesn't sound like something that we can claim, can we? It does look like we default to lld.

jonas-schievink commented 3 years ago

We do default to LLD, which can also garbage-collect unused sections

nagisa commented 3 years ago

Yeah, I was just wondering if we should expand our logic around when we specify the --gc-sections flag or just say that the targets use a gnu-ld-like linker.

jonas-schievink commented 3 years ago

Yeah, in practice I don't think anyone uses a non-GNU-compatible linker there

petrochenkov commented 3 years ago

It may make sense to set the default for linker_is_gnu to true because ld-style linkers are usually gnu, and it's easier to explicitly list exceptions than to not forget setting it to true for all random embedded targets.

petrochenkov commented 3 years ago

If the default is not flipped then compiler\rustc_target\src\spec\thumb_base.rs needs to add linker_is_gnu: true + other target specs should probably be audited as well.