Skip to main content

GCC under the hood

Steps GCC Performs

  1. Preprocessing
  2. Compiler
  3. Assembler
  4. Linker

hello.c

#include <stdio.h>

int main() {
printf("Hello");
return 0;
}

Step 1:

cpp hello.c > hello.i

Step 2:

Generate assembler code

gcc -S hello.i

Step 3:

as -o hello.o hello.s

Step 4:

ld -o hello hello.o

Will give you error cannot find _start, cannot find printf Solution:

ld -e main -o hello hello.o /lib/libc.so -I /lib64/ld-linux-x86-64.so.2

Source