GCC Compiler Quick Reference
============================

BASIC COMPILATION
  gcc -o output source.c          Compile C
  g++ -o output source.cpp        Compile C++
  gcc -c source.c                 Compile only (no link)
  gcc -S source.c                 Generate assembly
  gcc -E source.c                 Preprocess only

OPTIMIZATION
  gcc -O0 source.c               No optimization (debug)
  gcc -O1 source.c               Basic optimization
  gcc -O2 source.c               Standard optimization
  gcc -O3 source.c               Aggressive optimization
  gcc -Os source.c               Optimize for size

DEBUG
  gcc -g source.c                Debug symbols (for GDB)
  gcc -ggdb source.c             GDB-specific debug info

WARNINGS
  gcc -Wall source.c             All common warnings
  gcc -Wextra source.c           Extra warnings
  gcc -Werror source.c           Treat warnings as errors
  gcc -pedantic source.c         Strict standard compliance

SECURITY FLAGS
  # Disable protections (for exploit development)
  gcc -fno-stack-protector -z execstack -no-pie source.c -o vuln

  # Disable specific protections
  -fno-stack-protector           Disable stack canary
  -z execstack                   Make stack executable (disable NX)
  -no-pie                        Disable PIE
  -Wl,-z,norelro                 Disable RELRO

  # Enable protections
  -fstack-protector-all          Enable stack canary
  -pie -fPIE                     Enable PIE
  -Wl,-z,relro,-z,now            Full RELRO
  -D_FORTIFY_SOURCE=2            Buffer overflow detection

LINKING
  gcc source.c -lm               Link math library
  gcc source.c -lpthread          Link pthreads
  gcc source.c -lcrypto           Link OpenSSL crypto
  gcc -static source.c            Static linking

ARCHITECTURE
  gcc -m32 source.c              Compile 32-bit
  gcc -m64 source.c              Compile 64-bit
  gcc -march=native source.c     Native architecture

COMMON CTF PATTERNS
  # Compile vulnerable binary for practice
  gcc -fno-stack-protector -z execstack -no-pie -o vuln vuln.c

  # Compile with debug symbols for reversing practice
  gcc -g -O0 -o binary source.c

  # Compile shellcode runner
  gcc -z execstack -o runner runner.c

  # Cross-compile
  gcc -m32 -o binary32 source.c
