覆盖主程序入口点的可能缺点
Possible drawbacks of overriding the entry point of a main program
所以我试图在我的 C 程序中为 main
设置我自己的自定义名称,我找到了 this 答案。
You can specify an entry point to your program using the -e
flag to ld
.
That means you can override the entry point if you like, but you may not want to do that for a C program you intend to run normally on your machine, since start
might do all kinds of OS specific stuff that's required before your program runs.
如果不从 crt0.o
调用 _start
并编写我自己的代码来做任何我想做的事情,(可能的)缺点是什么?
入口点通常做类似
的事情
- 准备参数并调用
main
并处理其 exit
- 在
main
之前调用 global constructors,在 之后调用析构函数
- 填充全局变量,如
environ
等
- 初始化C运行时间,例如timezone、
stdio
流等
- 也许configure x87使用80位浮点数
- 如果您的装载机没有
,则充气并归零.bss
- 在您的平台上 运行 托管 C 程序所需的任何其他内容
这些东西与您的 C 实现紧密耦合,因此通常您仅在针对 freestanding environment.
时才提供自己的 _start
所以我试图在我的 C 程序中为 main
设置我自己的自定义名称,我找到了 this 答案。
You can specify an entry point to your program using the
-e
flag told
. That means you can override the entry point if you like, but you may not want to do that for a C program you intend to run normally on your machine, sincestart
might do all kinds of OS specific stuff that's required before your program runs.
如果不从 crt0.o
调用 _start
并编写我自己的代码来做任何我想做的事情,(可能的)缺点是什么?
入口点通常做类似
的事情- 准备参数并调用
main
并处理其exit
- 在
main
之前调用 global constructors,在 之后调用析构函数
- 填充全局变量,如
environ
等 - 初始化C运行时间,例如timezone、
stdio
流等 - 也许configure x87使用80位浮点数
- 如果您的装载机没有 ,则充气并归零
- 在您的平台上 运行 托管 C 程序所需的任何其他内容
.bss
这些东西与您的 C 实现紧密耦合,因此通常您仅在针对 freestanding environment.
时才提供自己的_start