Why some executables don't have main function?
I "objdump -d" an executable, e.g, /bin/ls, and I found there's not any main function in 开发者_Go百科the assembly code. Why?
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:
objdump -d /bin/ls|grep main
objdump: /bin/ls: no symbols
There are several possible explanations:
- The program in question may not be written in C. Just because C requires a
main
doesn't mean the world requires one. - The
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
. - (I'm not sure about
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.
精彩评论