hoglet wrote: ↑Thu Nov 04, 2021 3:14 pm
The *SBRK command no longer exists - it seems it got dropped in one of the merged
Yes, it was a temporary debug feature only.
Unfortunately it's pretty much the same with GCC 10.3:
OK, at least it's not worse!
One reason for higher levels of optimisation resulting in more stack usage is, I assume, the effect of inlining. If you inline a function, any local variables of that function become local variables of the calling function, so instead of the stack space they occupied being freed on return, it just adds to the stack frame of the calling function.
A similar thing can happen with an optimised-out tail-call. If the calling function has very little stack usage but the tail-called function has a lot, the calling function acquires all that stack usage. But it might have been coded that way precisely to minimise stack growth when recursion is involved:
Code: Select all
void function(void)
{
recursive_call();
tail_call();
}
You want as little stack as possible to have been used when
recursive_call() is made, but optimising out the
tail_call() may mean that the entirety of that function's stack frame adds to the cumulative total on recursion!
It would be useful to be able to tell the compiler not to reserve stack ahead-of-time, but only when actually needed (which is probably what an assembly language programmer would do), but I'm not aware of any such capability.