delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/06/09/12:15:13

From: "Christopher Nelson" <paradox AT gye DOT satnet DOT net>
To: <djgpp AT delorie DOT com>
Subject: Re: Hello World and File size
Date: Tue, 8 Jun 1999 10:14:00 -0600
Message-ID: <01beb1c9$eb872cc0$LocalHost@thendren>
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 4.71.1712.3
X-MimeOLE: Produced By Microsoft MimeOLE V4.71.1712.3
Reply-To: djgpp AT delorie DOT com


>I've just tried it for the first time and immediately come up with the
>same question. C and C++ "hello" programs after compiling with djgpp have
>sizes 105 K and 287 K correspondingly. On the other hand when compiled
>with MS Visual C++ compiler their sizes are 28 k and 36 K.
>
>Are you sure that this big difference really goes away for large real-life
>programs?


okay, one more time.  let's think about this.  what does the hello-world
program need?

printf

what does printf need?  well, quite a bit of stuff really.  too much to make
it worth my time to write it all out here.

so where's all this stuff that printf needs?  libc.  where's DJGPP's libc?
in a static file called libc.a, which must be linked into every program.

how does MSVC link in printf?  it uses a dynamic link library, which is
obviously not linked into the executable at compile time, it's linked at run
time.

if you examine the helloworld.o file produced by gcc, you'll see a much more
accurate version of how much code is actually produced by DJGPP for the
hello world app.

now, understanding this, static library stuff is linked once and once only
into the executable, so the more parts of the program that require that
module, the better ratio you get between generated code and library code.

as an example of this, the compile-time linker for my dynamic link library
compiles to 260k, and it has a LOT of code.  it contains a flex lexer and a
bison parser, the two of which are about 80k and 60k respectively just in
source. when i use upx, the executable compresses down to 62k--- which
brings up another point:  another huge part of the code size are debug
symbols and the like.  if you don't compile with debugging information the
resulting executable will be smaller, even if you DON'T strip symbols.

    -={C}=-

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019