GCC Toolchain Internals

What the gcc driver actually runs, what each optimization and debug level enables, and the flags that silently change correctness or portability — march=native, -Ofast, -std defaults, and the libstdc++ versus libc++ split.

Overview

The gcc command is a driver, not a compiler

Most engineers use gcc for years without knowing it is a driver. It reads input suffixes, consults a table of spec strings and launches subprocesses. Almost every 'why is this flag not doing what I expect' question is answered in thirty seconds by -###, because the driver injects arguments you never typed.

Two flags show you that injected work. gcc -v prints each subprocess command and runs it; gcc -### prints them without running anything.

Key concepts

  • The driver and its subprocesses
  • Spec strings
  • -O2 versus -O3
  • -Og and -Os and -Oz
  • -Ofast and -ffast-math
  • -g levels and DWARF
  • -march versus -mtune
  • libstdc++ versus libc++ and the CXX11 ABI

Interview questions

  • Explain what actually happens when you type g++ -O2 -g main.cpp -o app, and how you would inspect it.
  • What flags would you set for a shipped release build, and which flags would you refuse to set?
  • You want AVX-512 performance but the fleet is heterogeneous. How do you get it without shipping a binary that crashes?
  • A team wants to turn on -Wall -Wextra -Werror on a ten-year-old codebase. How do you do it without stopping all other work?
  • What GCC versus Clang differences have actually bitten you, and how do you keep a codebase building on both?

Sign up free to read the full topic

More DevOps topics

Start free on Cariara · Coding problems · System design studio