delorie.com is funded by banner ads.
  www.delorie.com/djgpp/v2faq/faq063.html   search  

| Previous | Next | Up | Top |

8.13 Why are DJGPP .exe files so large?

Q: I compiled a trivial "Hello world" program and got a 80KB executable file. That's ridiculously bloated!

Q: I switched to GCC 2.8.1, and my C++ executables are considerably larger than when compiled with GCC 2.7.2.1!


A: Did you link with -s switch to gcc, or run strip on the output of the linker? If not, the executable includes the debugging symbols, which makes it quite a lot larger. (It is not recommended to strip the symbols except when distributing production programs, because this makes debugging very hard indeed; that is why -s is not passed to gcc by default.)

C++ programs could be further bloated because the release of Binutils 2.8.1 was configured in a way that caused the assembler to put into the symbol table local labels generated when compiling code that uses exceptions. Later uploads of GNU Binutils should solve this problem, so consider upgrading to the latest bnuNNNb.zip.

Judging code sizes by looking at the size of "Hello" programs is meaningless, since most of the power of protected-mode programming goes wasted in such programs. There is no point in switching the processor to protected mode (which requires a lot of code) just to print a 15-byte string and exit. The overhead induced by the code needed to set up the protected-mode environment is additive; the larger the program, the smaller the overhead relative to the program size.

Apart from getting to protected-mode, the DJGPP startup code also includes such functionality as wildcard expansion, long command-line support, and loading the environment from a disk file; these usually aren't available with other DOS protected-mode compilers. Exception and signal handling (not available at all in v1.x), FPU detection and emulator loading (which were part of go32 in v1.x), are now also part of the startup code.

If your program doesn't need parts of the startup code, it can be made smaller by defining certain functions with empty bodies. These functions are __crt0_glob_function, __crt0_load_environment_file, and __crt0_setup_arguments. By defining empty substitutes for all three of these, you can make the "Hello" program be 28KB on disk. These functions are documented in the DJGPP libc reference, which see. Here's an example of definitions for these functions that will make the startup code as small as it gets(Note: If you define an empty substitute for __crt0_setup_arguments, you don't need to define a substitute for __crt0_glob_function.):

       char **__crt0_glob_function (char *arg) { return 0; }
       void   __crt0_load_environment_file (char *progname) { }
       void   __crt0_setup_arguments (void) { }

Note that if you define an empty substitute for __crt0_setup_arguments, your program will not be able to access its command-line arguments via the argv[] array. So this is only recommended for programs which don't accept any arguments at all.

You can make your program image still smaller by compressing it with a compressor called DJP. DJP is a DJGPP-specific executable file compressor. It is fast and has no memory overhead. It also knows about DJGPP Dynamically Loaded Modules (DLM) technology. (Note that DJP before version 1.06 was incompatible with Binutils 2.8.1 and later(Note: In particular, running strip on a program and then compressing it with DJP would produce a program that crashes upon startup.), so you should always use the latest DJP version available on SimTel.NET mirrors.)


  webmaster   donations   bookstore     delorie software   privacy  
  Copyright ⌐ 1998   by Eli Zaretskii     Updated Sep 1998  

Powered by Apache!

You can help support this site by visiting the advertisers that sponsor it! (only once each, though)