SDK compiled with -ffunction-sections

Posts: 12
Joined: Mon Jun 15, 2015 5:51 pm

SDK compiled with -ffunction-sections

Postby rojer » Thu Jan 07, 2016 11:09 am

Basically, this is about pruning unused SDK code. There are a lot of functions in the SDK, and many of them are unused in each individual project and should not be in the firmware. However, by default, linker will only drop whole object files, i.e. if nothing from that file is used. That is rarely true. However, this pruning can be pushed down to the function level with two steps:
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 and 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.

Who is online

Users browsing this forum: No registered users and 9 guests