These videos are about calling C functions and how those calls are implemented at the machine-code level. (We make no distinction between “procedure” and “function”.) The videos are especially about the use of the C stack for local variables and keeping track of return points.
- Procedure 1: Intro 4:29An introduction to function calls and the details that have to be managed at the machine level to implement functions.
- Procedure 2: C stack 5:19A kind of stack—
specifically and colloquially known as “the C stack”— is the key implementation technique for function calls in C.
- Although the C standard doesn’t say anything about a stack, we can (roughly) expose its existence as reflected in local variable addresses.
- Why local-variable allocation is tied up with the C stack.The word rentrant belongs here as a more generic characterization of the kinds of functions that need stack allocation for local variables. I have simplified somewhat by just characterizing the functions as recursive.
- The callx and retx machine-code instructions support function calls and returns.
- How a function call provides argument values to the called function, and how that function returns a result: registers and the stack.
- An application binary interface (ABI) specifies how a function can use registers and correctly cooperate with other functions.In the video, I say “caller-saved” and “callee-saved” backwards on the “x86-64 Linux Register Usage” slide. The original slides were also backwards.
- Procedure 8: ABIs 1:42A little more information about what an ABI specifies.
- How gdb knows which functions are part of the current continuation (i.e., how to provide a backtrace)—
or why it might not have that information. This exploration leads us to the notion of a frame pointer.I should have pointed out that compiling with -O will tend to generate code that uses a frame pointer, similar to -fno-omit-frame-pointer. However, the generated code gets generally noisier without optimization.
- All about using %rbx as a frame pointer.
- Now that we have all the pieces, we can summarize the overall C stack layout.