How GCC Handles Function Returns and Stack Memory Allocation on x86-64
A technical deep-dive explains how GCC manages stack memory and function return values during compilation on x86-64 architecture. The article covers three return mechanisms defined by the System V AMD64 ABI: returning scalar values via a single register, returning small structs across multiple registers, and returning large structs via a hidden pointer supplied by the caller. Stack memory allocation is handled through standard x86 instructions, where GCC adjusts the stack pointer register to reserve space for a function's local variables. The piece also explains the role of the endbr64 instruction, a hardware-level security checkpoint from Intel and AMD's Control-flow Enforcement Technology that prevents Jump-Oriented Programming attacks. Sample C code and GCC disassembly output via objdump are used throughout to illustrate each concept.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in