In some cases you'll see rep ret instead of rep. See the ABI link at the beginning of this answer for details, but in short, integral types and pointers are passed in registers %rdi, %rsi, %rdx, %rcx, %r8, and %r9, with floating-point arguments in the %xmm0 to %xmm7 registers. (In general, the value subtracted from and added to %rsp is an odd multiple of 8.)įunction parameters are typically passed in registers. When stack frames are omitted -fomit-frame-pointer for GCC -, the function implementation changes essentially to subq $8, %rsp Re-align stack frame, andīecause there is no stack frame ( %rbp is used for other purposes, and its value is never pushed to stack), each function call pushes only the return address to the stack, which is an 8-byte quantity, so we need to subtract 8 from %rsp to keep it a multiple of 16. to "unwind" stack frames that one or more functions can be aborted and control passed to some ancestor function, without leaving unneeded stuff on the stack. O2 -fno-omit-frame-pointer to keep stack frames while enabling optimizations otherwise, however.)Īlthough the same ABI applies to all binaries, no matter what language they are written in, certain other languages do need stack frames for "unwinding" (for example, to "throw exceptions" to an ancestor caller of the current function) i.e. This makes sense, because for programs written in C, the stack frames are most useful for debugging, but not much else.
#STACK SMASHING DETECTED MANJARO ARCHITECT FREE#
Because the compiler knows the difference between %rbp and %rsp at any point within the function, it is free to use either one as the base for the local variables.Ī stack frame is just the local function's playground: the region of stack the current function uses.Ĭurrent versions of GCC disable the stack frame whenever optimizations are used. While %rbp points to the current stack frame, %rsp points to the top of the stack.
(Note that the return address and the previous %rbp pushed to the stack are both 8 bytes in size, 16 bytes in total.) If no stack space is needed for local variables, there is no subq $16, %rsp or similar instruction. The amount of memory reserved for the local variables is always a multiple of 16 bytes, to keep the stack aligned to 16 bytes. Subq $16, %rsp Reserve 16 bytes for local variables Movq %rsp, %rbp Address of current stack frame Typical C functions are compiled to pushq %rbp Save address of previous stack frame This means the stack grows down smaller addresses are "higher up" in the stack. Linux uses the System V ABI for x86-64 (AMD64) architecture see System V ABI at OSDev Wiki for details.