While going though the Makefile of the FreeRTOS HRS example in SDK 16.0.0, I noticed this part:
# Optimization flags OPT = -O3 -g3 # Uncomment the line below to enable link time optimization #OPT += -flto
By default, link time optimization (LTO) is not enabled.
If I enable LTO, then the linking does not work. I get following error message:
Linking target: _build/nrf52832_xxaa.out C:\cygwin64\tmp\cc6jYqnd.s: Assembler messages: C:\cygwin64\tmp\cc6jYqnd.s:2713: Error: offset out of range lto-wrapper.exe: fatal error: C:\Users\johndoe\GNU\gcc-arm-none-eabi-7-2018-q2-update-win32\bin\arm-none-eabi-gcc.exe returned 1 exit status compilation terminated. c:/users/johndoe/gnu/gcc-arm-none-eabi-7-2018-q2-update-win32/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/bin/ld.exe: error: lto-wrapper failed collect2.exe: error: ld returned 1 exit status make: *** [../../../../../../components/toolchain/gcc/Makefile.common:294: _build/nrf52832_xxaa.out] Error 1
I'm using gcc-arm-none-eabi-7-2018-q2-update-win32 which AFAIK is the "officially supported" toolchain with this SDK. The error comes when trying to build the unmodified example from the SDK so it is not related to any of my own tweaks.
Is this a known issue? Any way to fix it?
This could be somewhat related to the other post I made about earlier, wondering about the large size of the FreeRTOS app. While working on my own app, I noticed that the size of the binary goes down when I remove unnecessary source files from the Makefile. With LTO, any unused code should be dropped automatically. Therefore I think that enabling LTO would be the key to strip off any unnecessary stuff from the FreeRTOS project.