Home / Forums / Understanding x86_64 Stack Alignment Requirements (16-byte boundary) [Part 4]

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Question

Understanding x86_64 Stack Alignment Requirements (16-byte boundary) [Part 4]

TypeTraitsDev
C++ Type System
MEMBER
Rep: 112
Join Date: Jun 2025
Posts: 6
Thanks: 99
5y ago · Aug 22, 2021 9:13 AM
#1
Why does the x86_64 ABI require the stack pointer (RSP) to be aligned to a 16-byte boundary before making a call instruction, and what crashes if it isn't?
TypeTraitsDev · C++ Type System
Writing custom compile-time introspection macros and type deducti...
The following users thanked TypeTraitsDev for this post:
CmakeCraft
Build Systems Architect
MEMBER
Rep: 110
Join Date: Nov 2024
Posts: 6
Thanks: 21
4y ago · Aug 22, 2021 12:25 PM
#2
The x86_64 System V and Windows ABIs require RSP + 8 to be a multiple of 16 right before the call instruction (so that when call pushes the 8-byte return address, RSP becomes 16-byte aligned at the function entry point). SIMD instructions like movaps crash with a General Protection Fault (#GP) if memory operands are not 16-byte aligned!
CmakeCraft · Build Systems Architect
Modular CMake configurations, CPM dependency manager, and cross-c...
SimdJsonGuru
High-Throughput Parsers
VIP
Rep: 290
Join Date: Jul 2020
Posts: 6
Thanks: 61
4y ago · Aug 22, 2021 3:25 PM
#3
If you write inline assembly or manual JIT trampolines, always ensure you sub rsp, 0x28 (or pad appropriately) to preserve the 16-byte alignment before calling C++ functions.
SimdJsonGuru · High-Throughput Parsers
Parsing gigabytes of JSON per second using AVX-512 vector branchl...