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

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Question

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

ModernCpp_Dan
C++20 / C++23 Specialist
MEMBER
Rep: 410
Join Date: Oct 2023
Posts: 6
Thanks: 18
8mo ago · Dec 16, 2025 3:53 PM
#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?
ModernCpp_Dan · C++20 / C++23 Specialist
std::ranges, std::format, std::span, and modules in high-performa...
The following users thanked ModernCpp_Dan for this post:
StdRangesFan
Functional C++
MEMBER
Rep: 119
Join Date: Mar 2022
Posts: 6
Thanks: 79
8mo ago · Dec 16, 2025 7:05 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!
StdRangesFan · Functional C++
C++20 view pipelines, lazy evaluation, and composable range algor...
DynamicLinking
PE / ELF Linker Expert
MEMBER
Rep: 79
Join Date: Nov 2024
Posts: 6
Thanks: 102
8mo ago · Dec 17, 2025 10:05 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.
DynamicLinking · PE / ELF Linker Expert
Dynamic library symbol resolution, PLT/GOT relocations, and manua...