在ELF文件中,如何确定_start的地址? [英] In an ELF file, how does the address for _start get detemined?

查看:196
本文介绍了在ELF文件中,如何确定_start的地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读ELF规范,无法弄清楚程序入口点和_start地址从何而来。

I've been reading the ELF specification and cannot figure out where the program entry point and _start address come from.

似乎它们应该位于一个相当一致的地方,但是我做了一些琐碎的程序,并且_start总是在另一个地方。

It seems like they should have to be in a pretty consistent place, but I made a few trivial programs, and _start is always in a different place.

有人可以澄清吗?

推荐答案

_start 符号可以在任何目标文件中定义。通常它是自动生成的(它对应于C中的 main )。您可以自己生成它,例如在汇编源文件中:

The _start symbol may be defined in any object file. Normally it is generated automatically (it corresponds to main in C). You can generate it yourself, for instance in an assembler source file:

.globl _start
_start:
    // assembly here

链接器处理完所有目标文件后,它会查找 _start 符号并将其值放在e_entry 字段中/gabi/1998-04-29/ch4.eheader.html rel = nofollow>精灵标头。加载程序从该字段获取地址,并在完成将所有节加载到内存中并准备执行文件后对其进行调用。

When the linker has processed all object files it looks for the _start symbol and puts its value in the e_entry field of the elf header. The loader takes the address from this field and makes a call to it after it has finished loading all sections in memory and is ready to execute the file.

这篇关于在ELF文件中,如何确定_start的地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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