Why is _init from glibc's csu/init-first.c called before _start even if _start is the ELF entry point?

天大地大妈咪最大 提交于 2019-11-30 20:12:38
4566976

Where the debugger halts first in your example isn't the real beginning of the process.

In the ELF header there is an entry for the program interpreter (dynamic linker). On Linux 64 bit its value is /lib64/ld-linux-x86-64.so.2. The kernel sets the initial instruction pointer to the entry point of this program interpreter. The symbol name of it is _start too, like the programs _start.

After the dynamic linker has done its work, calling also functions in the program, like _init in glibc, it calls the entry point of the program.

The breakpoint at _start doesn't work for the dynamic linker because it takes only the address of the program's _start.

You can find the entry point address with readelf -h /lib64/ld-linux-x86-64.so.2.

You could also set a breakpoint at _dl_start and print a backtrace to see that this function is called from dynamic linker's _start.

If you download glibc's current source code you can find the entry point of the dynamic loader at glibc-2.21/sysdeps/x86_64/dl-machine.h starting on line 121.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!