1.最初のat&a 64アセンブリ
1 .section .data 2 strFormat: 3 .asciz " %s \ n " 4 strUseLibc: 5 .asciz " こんにちは、私に会ったら、c libを呼び出しました:) " 6 strUseSyscall: 7 .asciz " そして、私に会ったら、あなたはsyscallを呼び出しました。\ n " 8 endOfStrUseSyscall: 9 10 .section .text 11 .globl _start 12 _start: 13 #関数呼び出しによって渡されるパラメーターは、プッシュメソッドを使用しなくなりました 14 movq $ strFormat、%rdi 15 movq $ strUseLibc、%rsi 16 呼び出し printf 17 18#システムコールレジスタが変更され、int 0x80もsyscall 19 movq $ 1 、%rdi 20 movq $ strUseSyscall、%rsi 21 movq $(endOfStrUseSyscall-strUseSyscall)、% rdx 22 movq $ 1 、%rax 23に 置き換えられました syscall 24 25 #さらに、システムコールの数も異なります 26 movq $ 127 、%rdi#意図的にゼロ以外の値を返します 27 movq $ 60 、%rax 28 syscall
2 cからアセンブリに変換してから、binにコンパイルする
GCCコンパイルの背後
http://tinylab.org/behind-the-gcc-compiler/
1 #include <stdio.h> 2 #include <unistd.h> 3 4 int sum(int a){ 5 return a ; 6 } 7 int main(){ 8 int b = 0 ; 9 b = sum(1); 10 printf(" hello:%d \ n "、b); 11 _exit(0); 12 }
1 gcc -S test .c -fno-asynchronous-unwind-tables -fno-exceptions -fno-stack-protector 2 sed -i -e " s#main#_start#g " test .s 3 gcc -c test .s 4 #ld -o test test .o /usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o / usr / lib / x86_64-linux-gnu / crtn。 o -lc --dynamic-linker / lib64 / ld-linux-x86- 64 .so。2 5 ld -o test test .o -lc --dynamic-linker / lib64 / ld-linux-x86- 64 .so。2