Chap I
Chap II
Preprocessing
gcc -E src.c -o src.i
This operation did several things.
- processing all the instructions begin with ‘#’, delete all of them except ‘#pragma’, and process the ‘#include’ recursively.
- delete all comments.
- add line number and file name identifiers
Compile
to assembly code
gcc -S src.i -o src.s
# or
gcc -S src.c -o src.s
# or
ccl src.c
Assembly
to machine code
as src.s -o src.o
# or
gcc -c src.s -o src.o
# or
gcc -c src.c -o src.o
Link
to executable program
ld src.o ......... *.o
Chap III
get file type
$ file /bin/bash
/bin/bash: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, stripped
$ file librt.so.1
librt.so.1: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, for GNU/Linux 3.2.0, stripped
Some Segments
int printf(const char *, ...);
int global_init_var = 0x11;
int global_uninit_var;
void func(int i) { printf("%d\n", i); }
int main(void) {
static int static_var = 0x22;
static int static_var2;
int a = 1;
int b;
func(static_var + static_var2 + a + b);
return a;
}