Thank you everyone! Just to give a update, we managed to get sizes down quite a bit with some of the suggestions here. Here is what we do to reduce the size of the application without losing performance so that future seachers might find it:
Start by using bloaty to profile your application. It can give you a good indication where space is used.
-fdata-sections -ffunction-sectionsto clang and-Wl,-gc-sectionsto lld is very basic but saves a lot of space. This should probably be enabled by most applications. This reduces the size of the.textsection.-Wl,-icf=safeor-Wl,-icf=allthis enables code folding and saved about 10% of space in our application (YMMV), be aware that the all flag makes your application standards incompatible and you might end up with issues. We have already usedallon other platforms and it worked for us here. Reduced the.textsection size.-fvisibility=hidden- we build a statically linked self-contained application so this makes sense for us. We saved another 10% with this, but only size on disk, not VM size. It almost removed the.strtabsection for us. If you can’t use this use-fvisibility-inline-hiddenwhich only hides the inlines.-Wl,--pack-dyn-relocs=relrworked for us as well! I understand it depends on the deployment target’s loader, but it passed all our testing and removed a massive 12% of our application size by reducing the rela.dyn section down to almost nothing.- We tried the machine-outliner as well, it reduced the size with 5% but unfortunately it decreased performance with around 2-3% which we where unable to accept. Looking forward to try @ellishg’s outliner based on PGO when it lands in our toolchain.
- Experimental options like
-fexperimental-relative-c++-abi-vtablesand-fexperimental-omit-vtable-rttiwhere deemed to risky for where we are in our project currently, so while they seem very good for several reasons we need some more time to trial this before we enable it. - I have not tested the gvn sink/hoist - I was not sure exactly what they did and we more or less hit our size target with the relr change for now.
Thanks everyone for contributing and hopefully this will help someone else in the future that want to reduce the size of the binary.