๐ WAYPOINT LESSON
Four Stages, Four Tools
โญโญโญ advancedโณ 16 min read๐ Lesson 181 of 225
What cpp, cc1, as, and ld each produce โ and the gcc flags that stop at each boundary.
gcc is a driver, not one program
One gcc hello.c command orchestrates four stages:
- Preprocessor (cpp): expands macros and includes โ still C text.
- Compiler proper (cc1): C text โ assembly text.
- Assembler (as): assembly โ object file (machine code + symbol table).
- Linker (ld): objects + libraries โ executable.
gcc -E stops after preprocessing, -S after compiling, -c after assembling. Each flag hands you an intermediate artifact you can actually read.
Why the boundaries matter
-Eoutput shows what macros really did โ the ground truth of module 9.-Soutput is where you watch optimization happen (module 4's claims become visible).-cproduces the .o whose symbol table the linker resolves โ and whose collisions and missing definitions produce link errors.
The linking step defines C's programming model
Undefined reference, multiple definition, and static-vs-external linkage are all linker concepts. Declaring a function without defining it compiles fine (the compiler trusts you) and fails only at link โ which is why header/implementation drift surfaces so late.
โก Now practice
Ready to CodePipeline DrillsStop at each stage, inspect the artifacts, and predict linker behavior โ the toolchain as a laboratory. These challenges use system() to drive real gcc/ar/nm.
4 challenges ยท ยท ~24 min