Tiny Core Linux

Tiny Core Extensions => TCE Tips & Tricks => Topic started by: polikuo on August 21, 2023, 10:42:39 AM

Title: Shrink the size
Post by: polikuo on August 21, 2023, 10:42:39 AM
I'm trying to build firefox which requires several other extensions.
One of them is cbindgen, which has its unique way for compilation.
If you check the notes, you'll see that none of them use any compile flags.

A bit of googling leads me to the stackoverflow (https://stackoverflow.com/questions/29008127/why-are-rust-executables-so-huge/54842093#54842093).
In brief, he says by adding these lines into the .toml config, you get smaller binary and strip it in a go.
Code: [Select]
[profile.release]
opt-level = "z"
codegen-units = 1
panic = 'abort'
strip = true

[profile.release-lto]
inherits = "release"
lto = true
Note that, to optimize for size, "s" (opt-level = "s") is a synonym to "z".

A quick test on my pies (all with LTO)
Code: [Select]
$ du *
5.5M    cbindgen-pi4-default
1.7M    cbindgen-pi4-adjusted-stripped
3.8M    cbindgen-pi4-default-stripped
1.7M    cbindgen-pi3-adjusted-stripped

The hack isn't RPI specific, we can introduce it into other arch.
What do you think ?  :)
Title: Re: Shrink the size
Post by: jazzbiker on August 21, 2023, 11:24:09 AM
Hi polikuo!

-Oz was introduced in gcc12.

from https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Optimize-Options.html:

-Oz

    Optimize aggressively for size rather than speed. This may increase the number of instructions executed if those instructions require fewer bytes to encode. -Oz behaves similarly to -Os including enabling most -O2 optimizations.

Looks like -Ofast antipode.
Title: Re: Shrink the size
Post by: Vaguiner on August 21, 2023, 01:58:09 PM
maybe tcc?