In an ELF file, how does the address for _start get detemined?

后端 未结 3 881
故里飘歌
故里飘歌 2020-12-11 18:01

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

It seems like they should have to be in a

3条回答
  •  生来不讨喜
    2020-12-11 18:56

    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
    

    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.

提交回复
热议问题