'Why stack frame aligned by 24 bytes?
I am reading Computer Systems: A Programmer's Perspective 3rd Edition by Randal E. Bryant and David R. O'Hallaron.
In chapter 3 and section 7.5, there is figure demonstrating how stack frames are allocated as follows:
I couldn't understand that why are line 4 and 12 needed. It seems that those lines are not required because the surplus 8 bytes of stack memory are not used at all.
As comment indicates, IMHO, it seems that it is inevitably allocated to align stack frame by 24 bytes:
- additional 16 bytes for
pushq %rbpandpushq %rbxrespectively - , and 8 bytes for
subq $8, %rsp
So, my question can be summarized to "Why stack frames are aligned by 24 bytes?"
Solution 1:[1]
24 bytes is not a power of 2 and hence cannot be an alignment. The real alignment is to 16 bytes and you forgot to account for the call instruction also pushing 8 bytes on the stack. So in total, the stack pointer is moved by 32 bytes, preserving alignment to 16 bytes.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | fuz |

