Domanda

I "objdump -d" an executable, e.g, /bin/ls, and I found there's not any main function in the assembly code. Why?

È stato utile?

Soluzione

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.

Altri suggerimenti

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top