I disassembled simple program written in C++ and there is a function:
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
What does this function? And why are there so many NOP operations after RET instruction?
As netrom mentioned,
__static_initialization_and_destruction_0(int, int)arranges for global constructors and destructors to be called.Many compilers add
nopinstructions after functions to enable incremental relinking. If you change the function a bit and it grows, the linker doesn’t have to move all functions that follow. Instead, the growth overwrites some of the former nop’s.