为什么GCC在函数的开头插入一个callq?

时间:2018-04-14 05:21:17

标签: gcc assembly

我的代码如下:

int foo(void);
int  __attribute__((noinline))  xxx(int a)
{
        return a+3;
}

int my_main(void)
{
    int pos;

    pos = foo();
    if (pos)
            return 1;

    return xxx(3);
}

使用'gcc -O3 -g -c main.c'编译它,结果是:

Disassembly of section .text:

0000000000000000 <xxx>:
   0:   8d 47 03                lea    0x3(%rdi),%eax
   3:   c3                      retq
   4:   66 90                   xchg   %ax,%ax
   6:   66 2e 0f 1f 84 00 00    nopw   %cs:0x0(%rax,%rax,1)
   d:   00 00 00

0000000000000010 <my_main>:
  10:   48 83 ec 08             sub    $0x8,%rsp
  14:   e8 00 00 00 00          callq  19 <my_main+0x9>
  19:   85 c0                   test   %eax,%eax
  1b:   75 13                   jne    30 <my_main+0x20>
  1d:   bf 03 00 00 00          mov    $0x3,%edi
  22:   48 83 c4 08             add    $0x8,%rsp
  26:   eb d8                   jmp    0 <xxx>
  28:   0f 1f 84 00 00 00 00    nopl   0x0(%rax,%rax,1)
  2f:   00
  30:   b8 01 00 00 00          mov    $0x1,%eax
  35:   48 83 c4 08             add    $0x8,%rsp
  39:   c3                      retq

查看my_main()函数,为什么它有自己的调用(callq 19)?

0 个答案:

没有答案