The Red Zone: 128 Bytes of Free Stack You Didn't Know You Had

2026-05-12

The red zone is a region of 128 bytes below the stack pointer (%rsp) that the System V AMD64 ABI guarantees won't be clobbered by signal handlers or interrupts. Leaf functions — functions that call nothing else — can use this scratch space without bothering to decrement %rsp at all. It's a small but pervasive optimization that shows up in nearly every optimized x86-64 binary.

Normally, allocating stack space means sub $N, %rsp on entry and add $N, %rsp on exit. For a tiny leaf function that needs 16 bytes for a temporary, those two instructions are pure overhead. With the red zone, the compiler just writes to -8(%rsp) and -16(%rsp) directly. No prologue, no epilogue stack adjustment.

Why it's safe: on x86-64 Linux, when a signal arrives, the kernel pushes the signal frame below the 128-byte red zone before invoking the handler. Hardware interrupts in user mode behave the same way. Your data in the red zone survives untouched.

Concrete example. Compile double square(double x) { double t = x*x; return t; } with gcc -O2 and you'll see:

Where it bites you:

Rule of thumb: if your leaf function needs ≤128 bytes of locals and makes zero calls, the compiler will skip the stack adjustment entirely. Above 128, or any CALL in the body, and you pay the normal prologue cost. You can disable it globally with -mno-red-zone — useful when writing freestanding code, bootloaders, or anything that runs with interrupts on its own stack.

Check it yourself: objdump -d /usr/bin/* | grep -B1 'sub.*%rsp' | wc -l versus total functions — you'll find a surprising fraction of functions never touch %rsp at all.

See it in action: Check out Do NOT Build This... by camman18 to see this theory applied.
Key Takeaway: The AMD64 ABI reserves 128 bytes below %rsp as scratch space leaf functions can use without adjusting the stack pointer — a free optimization in userspace, but disabled in the kernel because interrupts don't honor it.

All newsletters