在ELF文件中,如何确定_start的地址? [英] In an ELF file, how does the address for _start get detemined?
问题描述
我一直在阅读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
符号并将其值放在
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屋!