Why does GCC LTO not work for my PSoC Creator project?
The versions of GCC that ship with PSoC Creator (version 3.0 or later) are known to be susceptible to issues with the GCC LTO feature as described below.
How do I know if my design is using GCC LTO?
- If you are using PSoC Creator 3.1 with the GCC toolchain and you set the following in the Build Settings dialog, you are at risk: Note: These settings were removed from PSoC Creator 3.2 to prevent users from encountering problems.
- Link Time Optimization set to "True" under Compiler > Optimization
- Optimization Level set to other than "None" under Linker > Optimization
- If you are using any version of PSoC Creator with the GCC toolchain and you manually enabled LTO via the –flto command line argument in the Build Settings dialog, under Compiler or Linker > Command Line > Custom Flags, then you are at risk.
Issue 1 – GCC Linker Error: Referenced Symbol Defined in Discarded Section
If GCC LTO has been enabled for your design, the linker may choose to optimize your design erroneously. This will result in a GCC linker error, similar to the following:
`_sbrk' referenced in section `.text._sbrk_r' of <path>/arm-none-eabi/lib/armv6-m\libg_s.a(lib_a-sbrkr.o): defined in discarded section `.text' of .\CortexM0\ARM_GCC_484\Release\Cm0Start.o (symbol from plugin)
Note: Even if the design currently compiles cleanly, seemingly unrelated changes can possibly trigger the defect.
Issue 2 – Hard Fault During PSoC 4/PSoC 5LP Initialization
If GCC LTO has been enabled for your design and you are using any PSoC 4 or PSoC 5LP family device, the CPU may hard fault during initialization. This is due to a conflict between cross-module inlining and ISR remapping in the cy_boot Component version 4.20 or earlier.
To resolve this issue in PSoC Creator 3.2, update your cy_boot Component to version 5.0.
To resolve this issue in PSoC Creator 3.1 or earlier, turn off LTO for the Generated_Source/<PSoC4 | PSoC5>/cy_boot/Cm0Start.c file. Right-click on this file in the Workspace Explorer, and disable the compiler Link Time Optimization setting; see "How do I know if my design is using GCC LTO?"