1/15
Flashcards covering the C compilation process, object file formats, memory mapping, static and dynamic linking, and debugging with GDB.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Identify the four main components of the GCC compilation and linking process in order.
What are the primary functions of the C preprocessor (CPP)?
It expands macros (substitutes values for constants defined by #define), copies the contents of header files into the code, and performs conditional compilation (e.g., #ifdef).
What GCC flag is used to produce an assembly file (.s) instead of an executable?
−S
What does the abbreviation ELF stand for, and what is its purpose?
ELF stands for Executable and Linkable Format; it is the standard file format for executables, object files, and shared libraries on Linux.
Match the ELF segments '.text', '.data', and '.bss' to their contents.
'.text' contains executable machine code; '.data' contains initialized static and global variables; '.bss' contains uninitialized static and global variables (initialized to zero).
Define static linking versus dynamic linking.
Static linking mashes all code into a single, standalone executable (using .a files). Dynamic linking uses shared libraries (.so files) that are loaded at load time or run time, allowing multiple programs to share the same library code in RAM.
What command line tool allows you to see the shared library dependencies of an executable?
ldd
How does a static variable defined inside a function differ from a standard local variable?
A static variable inside a function does not get re-initialized upon every call; it retains its previous value throughout the life of the program (successive function calls).
What happens to the stack and heap in terms of memory address growth?
The stack grows down from higher memory addresses to lower addresses, while the heap grows up towards higher memory addresses.
What is Address Space Layout Randomization (ASLR)?
A security feature that randomizes the memory addresses of the stack, heap, and libraries for each process so that attackers cannot predict specific memory locations.
In the process memory map, what is the default size of the stack on the systems discussed?
Approximately 8megabytes.
What GDB command is used to show the function call stack, particularly after a segmentation fault?
bt (backtrace)
In GDB, what is the difference between the 'step' (s) and 'next' (n) commands?
'step' will enter into function calls to execute them line-by-line, whereas 'next' will execute the entire function as a single step and move to the next line in the current scope.
What is a 'stack overflow' in the context of recursion?
It occurs when a program exceeds the allocated memory for the stack (often due to infinite or deep recursion), typically resulting in a segmentation fault.
What bug is caused by assuming memory from malloc is initialized to zero?
Reading uninitialized memory (Heap data is not cleared by malloc; only calloc or manual initialization ensures it is zeroed).
On the 64-bit machine MOS, what is the theoretical range of memory addresses?
From 0 to 264−1.