GCC optimizations

paulgoulpie wrote on Wednesday, May 15, 2019:

I have a problem regarding the selection of the GCC compiler optimization setting compared to the stack consumption of FreeRTOS tasks.
My architecture is

  • a STM32F407 with active hard FPU
  • the compiler is GCC (GNU Tools for Arm Embedded Processors 7-2018-q2-update) version 7.3.1
  • the version of FreeRTOS is FreeRTOSv10.2.1.
  • I use the heap5 to exploit the STM32F407’s CCMRAM zone for hosting the FreeRTOS heap.
    During my development phases I use the -Og compilation option (optimized for debug).
    During my release phases I use the -Os compilation option (optimized for size).
    I notice that by switching from one optimization mode to another, I have big differences in consumption in the FreeRTOS task stack.
    In optimization mode -Os, it consumes more stack than in -Og mode. There would be an option to disable an optimization parameter to enter or another trick in order to preserve the consumption in stack.

Thanking you.

Paul Goulpié

rtel wrote on Wednesday, May 15, 2019:

Curious - I would expect the opposite. If everything else working the
same as when you had the lower optimisation level? Just wondering if
this is a symptom of something rather than the cause of something. I
believe there are some tricks you can do with GCC to get it to tell you
the stack used by certain call paths - can’t remember off the top of my
head how to do it so would have to look it up. Other than that you
might have to do some kind of binary search by looking at the stack
depth at particular parts in the call hierachy to see if you can
identify one particular culprit.