1

I have a large number of methods written in C spread across multiple files and all of them create local variables (mostly structure instances). After compiling these with ARM EABI GCC compiler on Windows, I try to examine the .o object files using objdump.

arm-none-eabi-objdump.exe -f -p -h -x -d -s -t test.o > test.txt

My question is: How do I calculate/retrieve the peak stack memory used by a method?

None of the methods allocate any dynamically allocated memory using malloc. So, I hoped that this would be easier.

I need this because I need to compare the amount of memory used by each method when compiled with various optimization options. This is to check if any local memory optimization has been carried out. I also understand that for some local variables, the compiler may use registers. However, I just need to know whatever is the maximum stack memory required by a method or if there is a way to calculate it.

Elroy
  • 167
  • 1
  • 8
  • Go through the disassembly and look for `push` and `sub sp, sp, #x` instructions? – tangrs Jul 16 '13 at 05:43
  • 1
    http://stackoverflow.com/a/6392173/12711 – Michael Burr Jul 16 '13 at 06:00
  • Yup, I think that's it! Strange that SO search didn't show up this result. Thanks Michael! – Elroy Jul 16 '13 at 06:11
  • @Elroy: I've found that using Google to search SO generally gets me better results than SO's search. Just drop a "site:stackoverflow.com" in the query. – Michael Burr Jul 16 '13 at 18:34
  • 1
    Actually, the suggestions in that answer don't work. `gcc` will lazily adjust the stack for some optimizations which will increase stack use at a benefit of performance. Paradoxically, the higher optimization levels will load more locals in registers, reducing use. So, even the `-fstack-usage` combined with a call graph is flawed; you need to know when `inlined` functions will have their locals removed from the stack. See: [`-fconserve-stack`](http://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/Optimize-Options.html) – artless noise Jul 17 '13 at 12:20
  • @artlessnoise Will check -fconserve-stack and check the difference. Thanks for the input! – Elroy Jul 19 '13 at 03:12

0 Answers0