Compiler optimzation O2 and O3 with mbed-os 5.11

Hey all!

Compiling with GCC_ARM and -O1 flag, my application runs fine but upon changing the optimization flag to -O3, the program gets stuck in a bootloop. Upon further investigation, I found out that it is crashing in the OS kernel start, so it cannot be a problem with the application.

Did someone else try -O2 or -O3 optimizations?

Thank you and best regards,

Hi Saad,

That’s interesting - what target are you compiling for and with which version of gcc?

Presently we only support (and test against) gcc v6 which we realize is getting old. If you are using gcc v7 or v8 and continue to have problems, please revert to v6. We recommend using the 2017-Q2 update located here:

Thanks for reporting this issue.

Ralph, Team Mbed

Hey Ralph,

Thanks for the response. That’s strange because I’m actually using GCC v6 2017-q2-update.

Upon a painstaking decomposition of the -O3 flags, I found out that it’s the “-fschedule-insns” (which reschedules instructions where supported to avoid CPU stalls) that breaks it. I didn’t look further into why this is happening so far.

BTW the MCU I’m using is the Nordic Nrf52840.