Dumping the static stack reservation sizes for functions

I would like to be able to emit a list of functions by name and their fixed stack reservation size information, so that a programmer can gauge how much stack they are likely to need in tightly constrained embedded systems. Despite the rich number of options, the only option I can find that is even relatively close is:

-warn-stack-size=

Is there some existing way of getting this information emitted in an easily parsable way (e.g. in CSV form) , or will I need to add the capability?

Thanks,

MartinO

Hi Martin,

I would like to be able to emit a list of functions by name and their fixed stack reservation size information, so that a programmer can gauge how much stack they are likely to need in tightly constrained embedded systems. Despite the rich number of options, the only option I can find that is even relatively close is:

-warn-stack-size=<uint>

Is there some existing way of getting this information emitted in an easily parsable way (e.g. in CSV form) , or will I need to add the capability?

There is an optimization remark emitted (in YAML) for the stack size:

$ clang -fsave-optimization-record foo.c
$ cat foo.opt.yaml
[…]
--- !Analysis
Pass: prologepilog
Name: StackSize
DebugLoc: { File: foo.c, Line: 3, Column: 0 }
Function: main
Args:
  - NumStackBytes: '24'
  - String: ' stack bytes in function'
...
[…]

For more information about optimization remarks I suggest Adam’s talk: https://llvm.org/devmtg/2016-11/Slides/Nemet-Compiler-assistedPerformanceAnalysis.pdf

Cheers,

Cool this is better than I expected - I never thought about the YAML support. And the document reference is really very good.

Thanks Francis,

  MartinO

Alternatively, you can parse the assembly…

https://github.com/spotify/linux/blob/master/scripts/checkstack.pl

I’ve used something like this in the past on x86 and ARM. I also parsed the output of objdump enough so that I could connect callers and callees (static dispatch only), so that I could analyze stack depths.