在C程序的了解汇编语言_start标签 [英] Understanding assembly language _start label in a C program
本文介绍了在C程序的了解汇编语言_start标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一个简单的C程序,并试图做用GDB调试程序。据我所知,在使用的主要功能如下:
I had written a simple c program and was trying to do use GDB to debug the program. I understand the use of following in main function:
在输入
push %ebp
mov %esp,%ebp
在退出
leave
ret
然后我尝试在_start GDB和我得到了以下
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 am unable to understand these lines, and the logic behind this.
有人可以提供任何指导,以帮助解释的code _start
?
Can someone provide any guidance to help explain the code of _start
?
推荐答案
下面是很好的注释<一个href=\"https://github.com/bminor/glibc/blob/2a69f853c03034c2e383e0f9c35b5402ce8b5473/sysdeps/i386/start.S\"相对=nofollow>在code你贴的汇编源。
总结,它做以下的事情:
Summarized, it does the following things:
- 建立与EBP定点堆栈帧= 0,code,它遍历堆栈可以很容易地找到它的结束
- 弹出的命令行参数的个数为
ESI
,所以我们可以将它们传递到__ libc_start_main
- 对齐堆栈指针为16位的倍数,以便符合ABI。这不能保证在Linux中的某些版本的情况下,所以它必须以防万一手工完成。
-
__ libc_csu_fini
,__ libc_csu_init
的地址,参数向量,参数的数量和地址主
推作为参数传递给__ libc_start_main
-
__ libc_start_main
被调用。此功能(来源$ C $ C <一个href=\"https://github.com/bminor/glibc/blob/2a69f853c03034c2e383e0f9c35b5402ce8b5473/sysdeps/x86/libc-start.c\"相对=nofollow>这里)设置了一些glibc的内部变量,最后调用主
。它永远不会返回。 - 如果出于任何原因
__ libc_start_main
应该返回时,HLT
指令后放置。该指令是不是在用户code允许的,应引起程序崩溃(希望)。 - NOP 指令的最后一个系列
的填充是由汇编插入所以下一个函数开始于16个字节为更好的性能的倍数。这是从来没有在正常的执行达到了。
- establish a sentinel stack frame with ebp = 0 so code that walks the stack can find its end easily
- Pop the number of command line arguments into
esi
so we can pass them to__libc_start_main
- Align the stack pointer to a multiple of 16 bits in order to comply with the ABI. This is not guaranteed to be the case in some versions of Linux so it has to be done manually just in case.
- The addresses of
__libc_csu_fini
,__libc_csu_init
, the argument vector, the number of arguments and the address ofmain
are pushed as arguments to__libc_start_main
__libc_start_main
is called. This function (source code here) sets up some glibc-internal variables and eventually callsmain
. It never returns.- If for any reason
__libc_start_main
should return, ahlt
instruction is placed afterwards. This instruction is not allowed in user code and should cause the program to crash (hopefully). - The final series of
nop
instructions is padding inserted by the assembler so the next function starts at a multiple of 16 bytes for better performance. It is never reached in normal execution.
这篇关于在C程序的了解汇编语言_start标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文