cwinapilinker

hidden routines linked in c program


Hullo, When one disasembly some win32 exe prog compiled by c compiler it shows that some compilers links some 'hidden' routines in it - i think even if c program is an empty one and has a 5 bytes or so.

I understand that such 5 bytes is enveloped in PE .exe format but why to put some routines - it seem not necessary for me and even somewhat annoys me. What is that? Can it be omitted? As i understand c program (not speaking about c++ right now which i know has some initial routines) should not need such complementary hidden functions..

Much tnx for answer, maybe even some extended info link, cause this topic interests me much

//edit

ok here it is some disasembly Ive done way back then (digital mars and old borland commandline (i have tested also) both make much more code, (and Im specialli interested in bcc32) but they do not include readable names/symbols in such dissassembly so i will not post them here

thesse are somewhat readable - but i am not experienced in understending what it is ;-)

https://dl.dropbox.com/u/42887985/prog_devcpp.htm

https://dl.dropbox.com/u/42887985/prog_lcc.htm

https://dl.dropbox.com/u/42887985/prog_mingw.htm

https://dl.dropbox.com/u/42887985/prog_pelles.htm

some explanatory comments whats that heere? (I am afraid maybe there is some c++ sh*t here, I am interested in pure c addons not c++ though, but too tired now to assure that it was compiled in c mode, extension of compiled empty-main prog was c so I was thinking it will be output in c not c++)

tnx for longer explanations what it is


Solution

  • Since your win32 exe file is a dynamically linked object file, it will contain the necessary data needed by the dynamic linker to do its job, such as names of libraries to link to, and symbols that need resolving.

    Even a program with an empty main() will link with the c-runtime and kernel32.dll libraries (and probably others? - a while since I last did Win32 dev).

    You should also be aware that main() is only the entry point of your program - quite a bit has already gone on before this point such as retrieving and tokening the command-line, setting up the locale, creating stderr, stdin, and stdout and setting up the other mechanism required by the c-runtime library such a at_exit(). Similarly, when your main() returns, the runtime does some clean-up - and at the very least needs to call the kernel to tell it that you're done.

    As to whether it's necessary? Yes, unless you fancy writing your own program prologue and epilogue each time. There are probably are ways of writing minimal, statically linked applications if you're sufficiently masochistic.

    As for storage overhead, why are you getting so worked up? It's not enough to worry about.