C Compilation, Memory, and Debugging Lecture Notes

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/15

flashcard set

Earn XP

Description and Tags

Flashcards covering the C compilation process, object file formats, memory mapping, static and dynamic linking, and debugging with GDB.

Last updated 12:24 AM on 6/18/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

16 Terms

1
New cards

Identify the four main components of the GCC compilation and linking process in order.

  1. Preprocessor (CPP)
  2. Compiler (CC1)
  3. Assembler (AS)
  4. Linker (collect2/LD)
2
New cards

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).

3
New cards

What GCC flag is used to produce an assembly file (.s) instead of an executable?

S-S

4
New cards

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.

5
New cards

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).

6
New cards

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.

7
New cards

What command line tool allows you to see the shared library dependencies of an executable?

ldd

8
New cards

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).

9
New cards

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.

10
New cards

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.

11
New cards

In the process memory map, what is the default size of the stack on the systems discussed?

Approximately 8megabytes8\,\text{megabytes}.

12
New cards

What GDB command is used to show the function call stack, particularly after a segmentation fault?

bt (backtrace)

13
New cards

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.

14
New cards

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.

15
New cards

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).

16
New cards

On the 64-bit machine MOS, what is the theoretical range of memory addresses?

From 00 to 26412^{64}-1.