1) Add -ffunction-sections to the compilation step
2) Add --gc-sections to the linking step
Step 1 puts each function into its own section - whereas previously functions foo() and bar() would both go to the .text section, now they will go to .text.foo and .text.bar sections.
At the second step, linker is instructed to drop unused sections. While linking, it will build call graph between sections and drop the ones that are not marked at the end. Because each function is now in its own section, this means dropping unused functions.
So, normally, it's as easy as adding one option to compile and link steps. In the case of SDK, some small tweaks to linker script may also be necessary. In our ESP8266 project we managed to save 30K by recompiling just libc and libm with -ffunction-sections, i'm sure a lot more can be saved if proprietary parts of the SDK are compiled with this flag.
For changes to crosstool to compile libc/libm, see this commit.Statistics: Posted by rojer — Thu Jan 07, 2016 11:09 am
]]>