Zephry LTO optimization

Hello!

Code size is quite crucial in our project, naturally CONFIG_SIZE_OPTIMIZATIONS is enabled. In other projects I've experience with LTO (link time optimization), this feature could cut off a few more percents from final binary size. Alas I haven't seen any easily reachable option to activate LTO in Zephyr.

My best guess was the following in CMakeLists.txt:

zephyr_ld_options("-flto")

but the resulting binary size remained the same. I've digged into the build directory and found this in build.ninja:

...
LINK_FLAGS = -gdwarf-4
LINK_LIBRARIES = ... -flto
...

This tells me the build system added -flto to LINK_LIBRARIES instead of LINK_FLAGS. How can I make Zephyr build system use my custom linker flag? Possibly without hacking, the standard Zephyr way is preferred...

Parents
  • H Tamas, sorry for the delay.

    Tamas Selmeci said:
    I tried the statement found in the PR with more NCS-2.2.0 and NCS-2.4.1 applications, and surprisingly the final binary was usually greater than without LTO!

    Our developers are experiencing the same as well.

    Tamas Selmeci said:
    Is there any way forcing NCS to use -lflto not only for the application code, but for the rest (Zephyr kernel) too? I'd give it a try...

    This is something currently being implemented. However, I am not able to predict at what time anything will be available. 

  • Experimental support for LTO was added in nRF Connect SDK v2.6.0. It can be enabled by setting CONFIG_LTO=y and CONFIG_ISR_TABLES_LOCAL_DECLARATION=y in your prj.conf file.

Reply Children
No Data
Related