Why does an assembly program only work when linked with crt1.o crti.o and crtn.o?

谁说胖子不能爱 提交于 2019-11-30 14:01:16
Michael McGarrah

Here are what the files do for you. They are the c-runtime environment and setup that link to the OS.

  • crt1.o Newer style of the initial runtime code. Contains the _start symbol which sets up the env with argc/argv/libc _init/libc _fini before jumping to the libc main. glibc calls this file 'start.S'.

  • crti.o Defines the function prolog; _init in the .init section and _fini in the .fini section. glibc calls this 'initfini.c'.

  • crtn.o Defines the function epilog. glibc calls this 'initfini.c'.

There is an excellent write up and example code to be found at the following website http://wiki.osdev.org/Creating_a_C_Library for each of the libraries above.

In 3-bit Linux, they're on the stack. At start up, 0(%esp) contains argc. At 4(%esp), you'll find a pointer to the program name (which is included in argc). After that comes an array of pointers to the arguments, concluded with a NULL pointer. After that comes another NULL-concluded array of pointers to system variables. I am told that there may be over 200 of them!!

Shiarta

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