MinGW generates large executable files

Charles Bailey <[email protected]> Fri, 20 Mar 2020 17:15:09 -0500
Newsgroups gmane.comp.gnu.mingw.user
Message-ID <[email protected]>
I have been trying to determine why the executable files produced by 
MinGW are much larger than I would expect, even for small, simple, 
console-mode programs.  I tried an experiment with what is probably the 
smallest possible C program.
Just one line:
int main(void) {return 0;}

When I compile this with TCC I get a .exe file that is just 1,536 
bytes.  With gcc from MinGW I get a .exe that is 42,035 bytes long.  
Executing the strip command on it to remove debug symbols brings it down 
to 19,470 bytes, which is still more than 12 times the size of the 
TCC-produced file.

I recently learned how to use the dumpbin command from Microsoft to 
analyze an .exe file.  When I run this on the TCC-generated file I see 
that it has 2 sections:
         1000 .data
         1000 .text

It imports 10 items from msvcrt.dll:
   __set_app_type
   _controlfp
   __argc
   __argv
   _environ
   __getmainargs
   exit
   _XcptFilter
   _exit
   _except_handler3

When I run dumpbin on the MinGW-produced file I see that it has 8 sections:
         1000 .CRT
         1000 .bss
         1000 .data
         1000 .eh_fram
         1000 .idata
         1000 .rdata
         3000 .text
         1000 .tls

It imports 18 functions from KERNEL32.dll:
   DeleteCriticalSection
   EnterCriticalSection
   ExitProcess
   FindClose
   FindFirstFileA
   FindNextFileA
   FreeLibrary
   GetCommandLineA
   GetLastError
   GetModuleHandleA
   GetProcAddress
   InitializeCriticalSection
   LeaveCriticalSection
   LoadLibraryA
   SetUnhandledExceptionFilter
   TlsGetValue
   VirtualProtect
   VirtualQuery

And, 32 functions from msvcrt.dll:
   _strdup
   _stricoll
   __getmainargs
   __mb_cur_max
   __p__environ
   __p__fmode
   __set_app_type
   _cexit
   _errno
   _fpreset
   _fullpath
   _iob
   _isctype
   _onexit
   _pctype
   _setmode
   abort
   atexit
   calloc
   free
   fwrite
   malloc
   mbstowcs
   memcpy
   realloc
   setlocale
   signal
   strcoll
   strlen
   tolower
   vfprintf
   wcstombs

What is all that extra stuff that MinGW is inserting?  Why is it 
referencing tons of functions that I'm not even using?  Are there some 
gcc options I can specify to eliminate that extra stuff?

Thanks,
Charles Bailey

_______________________________________________
MinGW-Users mailing list
[email protected]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.osdn.me/mailman/listinfo/mingw-users
Also: mailto:[email protected]?subject=unsubscribe