zoukankan      html  css  js  c++  java
  • -fomit-frame-pointer 编译选项在gcc 4.8.2版本中的汇编代码研究

    #include 
    void fun(void) { printf("fun"); }
    int main(int argc, char *argv[]){ fun(); return 0;}
    
    $ gcc -o test_ffp test.c                                $ gcc -fomit-frame-pointer -o test_ffp test.c
    -rwxr-xr-x 1 Admin 40968 Jan 23 21:14 test.exe          -rwxr-xr-x 1 Admin 40968 Jan 23 21:22 test_ffp.exe
    $ gdb -q test.exe                                       $ gdb -q test_ffp.exe 
    (gdb) disass main                                       (gdb) disass main   
    Dump of assembler code for 
    --ction main:               Dump of assembler code for 
    --ction main:
       0x00401574 <+0>:     push   %ebp                        0x00401573 <+0>:     push   %ebp
       0x00401575 <+1>:     mov    %esp,%ebp                   0x00401574 <+1>:     mov    %esp,%ebp
       0x00401577 <+3>:     and    $0xfffffff0,%esp            0x00401576 <+3>:     and    $0xfffffff0,%esp
       0x0040157a <+6>:     call   0x401fb0 <__main>           0x00401579 <+6>:     call   0x401fb0 <__main>
       0x0040157f <+11>:    call   0x401560                    0x0040157e <+11>:    call   0x401560 
       0x00401584 <+16>:    mov    $0x0,%eax                   0x00401583 <+16>:    mov    $0x0,%eax
       0x00401589 <+21>:    leave                              0x00401588 <+21>:    leave  
       0x0040158a <+22>:    ret                                0x00401589 <+22>:    ret    
       0x0040158b <+23>:    nop                                0x0040158a <+23>:    nop
       0x0040158c <+24>:    xchg   %ax,%ax                     0x0040158b <+24>:    nop
       0x0040158e <+26>:    xchg   %ax,%ax                     0x0040158c <+25>:    xchg   %ax,%ax
    End of assembler dump.                                  End of assembler dump.   
    
    (gdb) disass fun                                         (gdb) disass fun
    Dump of assembler code for 
    --ction fun:                 Dump of assembler code for 
    --ction fun:
       0x00401560 <+0>:     push   %ebp                        0x00401560 <+0>:     sub    $0x1c,%esp
       0x00401561 <+1>:     mov    %esp,%ebp                   0x00401563 <+3>:     movl   $0x404024,(%esp)
       0x00401563 <+3>:     sub    $0x18,%esp                  0x0040156a <+10>:    call   0x402738 
       0x00401566 <+6>:     movl   $0x404024,(%esp)            0x0040156f <+15>:    add    $0x1c,%esp
       0x0040156d <+13>:    call   0x402738                    0x00401572 <+18>:    ret
       0x00401572 <+18>:    leave                           End of assembler dump.
       0x00401573 <+19>:    ret                             (gdb)
    End of assembler dump.
    (gdb)
    
    文件大小是一样,结果fun函数的汇编代码中push %ebp; leave; 没有啦.
  • 相关阅读:
    Hash
    字符串hash
    NOIp 2014解方程
    NOIp2014 寻找道路
    NOIp2013火柴排队
    用scanf("%d",)读入long long类型
    lis问题
    西江月·证明
    计算系数
    积木大赛&PLA-Postering
  • 原文地址:https://www.cnblogs.com/nlsoft/p/4245110.html
Copyright © 2011-2022 走看看