为什么我的code将在启动功能的最后崩溃? [英] Why my code will crash at the end of the start function?
问题描述
测试平台是32位Linux。
Test platform is 32 bit Linux.
基本上,我做了修改生成的入口点更改从ASM code GCC 主要为开始如下:
Basically, I did a modification to the asm code gcc generated to change the entry point from main to start as below:
ASM code:
.file "test.c"
.intel_syntax noprefix
.section .rodata
.LC0:
.string "%d\n"
.text
.globl start
.type start, @function
start:
push ebp
mov ebp, esp
call main
mov eax, 0
leave
ret
.size start, .-start
.globl main
.type main, @function
main:
push ebp
mov ebp, esp
and esp, -16
sub esp, 32
mov DWORD PTR [esp+28], 1
mov eax, OFFSET FLAT:.LC0
mov edx, DWORD PTR [esp+28]
mov DWORD PTR [esp+4], edx
mov DWORD PTR [esp], eax
call printf
mov eax, 0
然后我用这些来编译和链接:
Then I use these to compile and link:
as test.s -g -o test.o
ld -o test test.o -lc -dynamic-linker /lib/ld-linux.so.2 -e start
在用gdb调试,就可以顺利工作,直到开始函数结束时,
然后从调试信息似乎$ EIP不知道从哪里下一个跳了,
发生故障段...
When debug using gdb, it can successfully work until the end of start function, then from the debug info it seems that $EIP don't know where to jump next, and segment fault occurs...
任何人都可以给我在这个问题上的一些帮助..?
谢谢了很多!
Could anyone give me some help on this issue..? Thank you a lot!
推荐答案
你应该叫退出
,而不是设置EAX为0和回报,因为你没有用C主要功能(C运行时),所以无处可归。
you should call exit
instead of set eax to 0 and return, because you don't use C main function(C-runtime), so nowhere to return.
这篇关于为什么我的code将在启动功能的最后崩溃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!