LOGBOOK

HELP

Quiz Entry - updated: 2026.07.10

What determines whether a function needs a stack frame at all?

A function needs stack space only when it can't keep everything in registers — e.g. too many locals, an &-taken local, arrays/structs, callee-saved regs to preserve, or making calls itself.

Many small functions need no frame at all. The compiler allocates one only when forced to, by any of these:

  1. Too many locals to fit in registers
  2. Address-of (&x) on a local — it must have a real memory address
  3. Arrays or structs as locals (they live in memory)
  4. Calling other functions — may need to spill caller-saved registers
  5. More than 6 arguments to pass to a callee (extra args go on the stack)
  6. Using callee-saved registers that must be saved/restored

A pure leaf function often compiles with zero stack operations:

long add(long x, long y) { return x + y; }
add:
    leaq (%rdi,%rsi), %rax   # no push/pop, no sub $N,%rsp
    ret

Whereas a function that calls others usually needs a frame to hold values across those calls.

Reverse-engineering tip: the presence of a prologue/epilogue and the size of the sub $N,%rsp already tell you a lot about how much local state a function juggles.

Go deeper:

From Quiz: REVE1 / The Processor Interface | Updated: Jul 10, 2026