Compilation Steps
1. Preprocessing (cpp) cc -E a.c > a.i
# 1 "hello.c"
# 1 ""
# 1 ""
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "" 2
# 1 "hello.c"
..
...
extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
# 943 "/usr/include/stdio.h" 3 4
# 2 "hello.c" 2
int main()
{
printf("hello\n");
}
# 1 "/usr/include/x86_64-linux-gnu/bits/types.h" 1 3
2. Compilation (cc) cc -S a.c # generates a.s
extreme@ALOPRASA-EAN6Q:/mnt/c/Users/aloprasa/winlinux$ cat hello.s
.file "hello.c"
.section .rodata
.LC0:
.string "hello"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl $.LC0, %edi
call puts
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4"
.section .note.GNU-stack,"",@progbits
3. Assemble (as) cc -c a.s # a.o
extreme@ALOPRASA-EAN6Q:/mnt/c/Users/aloprasa/winlinux$ file hello.o
hello.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
4. Linking (ld) cc a.o -o a # Generates binary program 'a'
No comments:
Post a Comment