为什么有些可执行文件没有 main 函数?
我“objdump -d”一个可执行文件,例如/bin/ls,我发现汇编代码中没有任何main函数。为什么?
I "objdump -d" an executable, e.g, /bin/ls, and I found there's not any main function in the assembly code. Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能会在大多数尚未删除的可执行文件中找到“main()”:
http: //linux.die.net/man/1/strip
如果运行以下命令,您可能还会看到类似的内容:
You'd probably find a "main()" in most executables that haven't been stripped:
http://linux.die.net/man/1/strip
You'd probably also see something like this if you ran the following:
有几种可能的解释:
main
并不意味着世界需要它。main
函数可能已被编译器内联或删除。操作系统只是调用一个入口点;它并不关心这是否实际上是一个名为main
的函数的开始。objdump
)Objdump
可能不会公开程序中所有可能的符号;鉴于您将其指向链接的可执行文件而不是目标文件,因此 objdump 并没有真正的合同来告诉您可执行文件中的每个可能的函数;只是那些可能被外部调用的。符号信息只是助记符;处理器根本不考虑这些事情。
There are several possible explanations:
main
doesn't mean the world requires one.main
function may have been inlined or eliminated by the compiler in general. The operating system just calls an entry point; it doesn't care if that's actually the start of a function calledmain
.objdump
)Objdump
might not expose all possible symbols in a program; given that you're pointing it at linked executable and not object files, there's not really a contract for objdump to tell you every possible function in the executable; just those which might be called externally.Symbolic information are only mnemonics; the processor isn't looking at these things at all.