为什么从_start返回段错误? [英] Why does returning from _start segfault?

查看:16
本文介绍了为什么从_start返回段错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将代码不在main函数中,而是直接放入_start:

 段 .text全局_start_开始:推rbpmov rbp, rsp;... 程序逻辑 ...离开ret

编译:

yasm -f elf64 main.sld -o main main.o

运行:

./main分段错误(核心转储)

我看了,离开是

mov esp,ebp流行音乐

但是,为什么弹出堆栈帧的结尾和设置的基帧指针指向前一帧的基数会导致分段错误?

确实,退出系统调用会优雅地退出.

解决方案

根据

没有退货地址".
退出进程的唯一方法是通过 SYS_EXIT

xorl %edi, %edi ;错误码movl $60, %eax ;SYS_EXIT系统调用

<小时>

13.4.1 节初始堆栈和寄存器状态.

I tried to put code not in the main function, but directly into _start:

    segment .text
    global _start
_start:
    push rbp
    mov rbp, rsp
    ; ... program logic ...
    leave
    ret

Compile:

yasm -f elf64 main.s
ld -o main main.o

Run:

./main
Segmentation fault(core dumped)

I read, leave is

mov esp,ebp
pop ebp

But why is it that such an epilogue to the pop stack frame and the set base frame pointer to a previous frame's base results in a segmentation fault?

Indeed, making an exit system call exits gracefully.

解决方案

As per ABI1 the stack at the entry on _start is

There is no "return address".
The only way to exit a process is through SYS_EXIT

xorl %edi, %edi   ;Error code
movl $60, %eax    ;SYS_EXIT
syscall


1 Section 3.4.1 Initial Stack and Register State.

这篇关于为什么从_start返回段错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆