GCC under the hood
Steps GCC Performs
- Preprocessing
- Compiler
- Assembler
- 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
