Search code examples
objdump

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 the assembly code. Why?


Solution

  • 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.