I know that in x86_64, there exists a 128 byte red zone above (or below, address-wise) the stack pointer that functions can use without subtracting from rsp.

This sounds to me like the only things that need to be aware of the red-zone are situations in which code will get interrupted by other code running on the same stack.

The only cases where this seems relevant to me are:

  • OS-level interrupt handlers (either switch stacks without touching the red zone, or subtract red zone size before using the stack)
  • user-level signal handlers (since AFAIK POSIX signals deliver on the same stack if sigaltstack() wasn't used)

In those cases, when that code handles the existence of a red zone, linking together code compiled with -mno-red-zone and without it should not be a problem, right?

It'd only be a problem if the code assumes -mno-red-zone and some code uses it anyway.

Is my reasoning about this correct?

If this is correct, why do so many OS-dev resources tell you to enable -mno-red-zone? is it just to reduce complexity?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.