Link-time optimizer ( -flto)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Link-time optimizer ( -flto)

1,151 Views
robertnguyen
Contributor II

Does anyone use link-time optimizer in KDS?  Does the optimizer work in MQX? I tried to use it by setting it in the Optimization (C/C++ Build - Settings) and at the C++ Linker, the size of flash image reduced quite a bit but it did not run at all ( stuck at toolchain_startup function). Any suggestion is greatly appreciated.

Labels (1)
0 Kudos
3 Replies

833 Views
bobpaddock
Senior Contributor III

It is important to mark ISRs and other functions that the compiler may think are never called with the attribute USED.

#define ATTR_USED __attribute__ ((used))

Aggressive removal of code can remove things that are actually used, however the compiler may not be able to track their usage to know they are used.

This in a way defeats what LTO was meant to do, remove dead code.  Comes down to proper code hygiene.

There should be no dead code that needs removed.

Also GCC 5.0 and GCC 5.1 are broken and shall not be used.  Use 4.8/4.9 or 5.2q4.

0 Kudos

833 Views
robertnguyen
Contributor II

Thanks for the advice. I removed lto option in bsp (MQX) project and it seems to works (KDS 3.1, MQX 4.2, arm gcc 4.8.4).

0 Kudos

833 Views
BlackNight
NXP Employee
NXP Employee

Yes, it works well for me, but I'm using FreeRTOS. Check all the warnings, and make sure that you have built all object files with -flto (remove the 'Debug' folder to have a clean state before building).

I have seen problems in startup code if the objects (e.g. __SP_INIT) do not have the same size in all declarations.

The other thing is that I moved up to the latest GNU ARM Embedded (launchpad) tools 5.2 2015 q4 (see Switching ARM GNU Tool Chain and Libraries in Kinetis Design Studio | MCU on Eclipse ). LTO had some issues afaik in older ARM toolchains, so this might help.

I hope this helps,

Erich

0 Kudos