开发者

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:

  1. The program in question may not be written in C. Just because C requires a main doesn't mean the world requires one.
  2. 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 called main.
  3. (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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜