Understanding the _start assembly language in C program

I wrote a simple c program and tried to use GDB to debug the program. I understand the use of the following functions:

Enter

push   %ebp
mov    %esp,%ebp

Upon exit

leave
ret

Then I tried gdb on _start and I got the following

xor    %ebp,%ebp
pop    %esi
mov    %esp,%ecx
and    $0xfffffff0,%esp
push   %eax
push   %esp
push   %edx
push   $0x80484d0
push   $0x8048470
push   %ecx
push   %esi
push   $0x8048414
call   0x8048328 <__libc_start_main@plt>
hlt
nop
nop
nop
nop

I can not understand these lines and the logic of this.

Can anyone give any recommendations to help explain the code _start?

+4
source share
2 answers

Here is a well-commented > code that you posted.

To summarize, he performs the following actions:

  • set the clock stack frame with ebp = 0, so the code that goes through the stack can easily find its end.
  • esi, __libc_start_main
  • 16 , ABI. Linux, .
  • __libc_csu_fini, __libc_csu_init, , main __libc_start_main
  • __libc_start_main. ( ) glibc main. .
  • - __libc_start_main , hlt. ().
  • nop - , , 16 . .
+2

gnu _start . , C , , /, - , :

int x = 5;
int y;

int fun ( void )
{
   static int z;
}

x, y, z , . , , x, 5, , y . , , , ( ) _start main().

/, gnu _start. , , main() ++, , C.

-2

Source: https://habr.com/ru/post/1629657/


All Articles