[Solved] warning: stack usage is 120 bytes [-Wstack-usage=]
warning: stack usage is 120 bytes [-Wstack-usage=]
Hi Good day!
I just want to ask about this warning:
warning: stack usage is 120 bytes [-Wstack-usage=]
By the way, I’m using the following:
e2 studio IDE
GCC for Renesas RL78 v4.9.202201
R5F104ML (RL78/G14 Fast Prototyping Board) – On-chip memory: 512-KB ROM, 48-KB RAM, 8-KB data flash memory
I’m aware though that this warning will disappear by increasing the stack size limit in the project settings and so far, the function where the warning is coming from runs fine. But I’m curious, what should be the maximum stack usage should I allocate for a function? The default upon creating a project is set to 40. Should I not exceed that limit? My knowledge when it comes to stack usage is honestly limited. I hope you could help me understand it. Thank you in advance for the answers.
Regards,
June
Best answer
Hello,
Thank you for reaching out to us!
As stated in the GCC manual (<toolchain install location>/Doc/gcc.html or online at https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html),
the -Wstack-usage=byte-size command line option helps developers in finding functions that may have unexpectedly high stack memory usage. A high stack memory usage doesn’t necessarily mean that there’s something wrong with the code, nor could we recommend a maximum amount of stack memory to aim for.
This is all application-dependent, as everything boils down to RAM usage: RAM is used to store initialized/uninitialized global variables, as well as the stack itself (which in turn stores the local variables, return addresses, etc.). Data starts at lower memory addresses and grows towards higher memory addresses. The stack memory starts at a high memory address and grows towards low memory addresses (and towards the area reserved for data).
To ensure correct program execution, developers must ensure that the highest stack memory usage scenario (deepest function call depth, highest per function stack usage, etc.) does not overwrite the memory region reserved for data.
Inspecting the linker file (generate/linker_script.ld), which tells the linker where and in what order the output sections should be allocated, and the map file (Debug/<project_name>.map), which lists the actual allocations, might provide some further insight regarding this issue.
We hope this helps.
__
Best regards,
The Open Source Tools Team