c++ - GLOBAL__I_main 函数

标签 c++ assembly g++

我反汇编了一个用C++写的简单程序,有一个函数:

080486a8 <_GLOBAL__I_main>:
 80486a8:   55                      push   %ebp
 80486a9:   89 e5                   mov    %esp,%ebp
 80486ab:   83 ec 18                sub    $0x18,%esp
 80486ae:   c7 44 24 04 ff ff 00    movl   $0xffff,0x4(%esp)
 80486b5:   00 
 80486b6:   c7 04 24 01 00 00 00    movl   $0x1,(%esp)
 80486bd:   e8 a6 ff ff ff          call   8048668 <_Z41__static_initialization_and_destruction_0ii>
 80486c2:   c9                      leave  
 80486c3:   c3                      ret    
 80486c4:   90                      nop
 80486c5:   90                      nop
 80486c6:   90                      nop
 80486c7:   90                      nop
 80486c8:   90                      nop
 80486c9:   90                      nop
 80486ca:   90                      nop
 80486cb:   90                      nop
 80486cc:   90                      nop
 80486cd:   90                      nop
 80486ce:   90                      nop
 80486cf:   90                      nop 

这个有什么作用?为什么RET指令后有这么多NOP操作?

最佳答案

如 netrom 所述,__static_initialization_and_destruction_0(int, int) 安排调用全局构造函数和析构函数。

许多编译器在函数后添加nop 指令以启用增量重新链接。如果您稍微更改函数并且它增长,链接器不必移动后面的所有函数。相反,增长覆盖了一些以前的 nop。

关于c++ - GLOBAL__I_main 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6478306/

相关文章:

c++ - lu_factorize 返回什么?

c++ - size_type 和 multi_array 索引的 Boost 有符号/无符号比较

assembly - 如何将寄存器中的VALUE移至NASM中的存储变量?

c++ - 没有命名类型错误 C++

c++ - 二进制 * 运算符未找到

c++ - 决定将哪个派生类作为参数传递

linux - 您在哪里检查 x86-64 机器上的系统调用原型(prototype)?

linux - 汇编 - 为什么 strtol 破坏 %rcx 寄存器?

c++ - 如何将整数参数传递给 shell 脚本,然后将其传递给程序?

c++ - 被调用者如何知道参数是通过寄存器而不是堆栈传递的