This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
Re: Huge binaries?
- To: libstdc++ at sourceware dot cygnus dot com
- Subject: Re: Huge binaries?
- From: Nathan Myers <ncm at best dot com>
- Date: Sun, 21 Nov 1999 13:28:03 -0800 (PST)
- Cc: jsm at cygnus dot com
- Reply-To: libstdc++ at sourceware dot cygnus dot com
Kevin Ediger wrote:
> Gerald Gutierrez wrote:
> > When using gcc 2.95.2 and libstdc++, why is it that sometimes binaries
> > can get so HUGE? People must've seen this before. A small program can
> > compile to 600K in size, and even after stripping, it's still well
> > over 100K.
> >
> > Templates, perhaps?
>
> P.J. Plauger has an article about Locales in C/C++ Users Journal,
> Oct 1997. He blames a lot of the code bloat specifically on the
> C++ locales as mandated by the standard. He points out that when
> compiling "Hello, World" with his first library that implemented
> locales, the binary came out at 250,000 bytes. Another library gave
> a 1.5 Mbyte "Hello, World"! Clearly not acceptable.
>
> Plauger does state that he got hello world down to 20k. I guess the
> point is that the C++ standard locales are just plain expensive, even
> when you don't use them (unfortunately) and take some work to "optimize"
> away the bloat. However, if you do need them, they are VERY nice to
> have around.
As the person who designed the locale facilities in the Standard Library,
I would like to point out a few things:
1. The locale facilities were designed with the specific intent that
library implementers would arrange to optimize away the unused
portions. In other words, I assumed implementers would be competent.
2. Such optimization would be made much easier by a compiler/linker
optimization which identifies virtual functions that cannot be
called in a particular program and doesn't link them in. This
was implemented by Symantec three years ago, but gcc/ld doesn't
have it yet. (Richard Henderson of Cygnus says he implemented a
(limited) prototype version of it in a few days, last year.)
If a Cygnus customer were to request that the optimization be
implemented -- which would benefit all embedded C++, not just code
that uses locale -- they could probably get it in a very short time.
3. Bill Plauger's published opinions on the Standard should be taken
more as self-promotion than as objective evaluation. He has a
business to run, and appears to believe that he benefits from
making himself appear more clever than others, and more concerned
about potential customers' problems.
Back to the original question...
You can learn a lot about why files are big by looking at the pieces.
Instead of "ls -l", try "size". That tells you about the code rather
than the linker and debug symbols. Compile with and without "-g" and
see what difference that makes.
It is true that template names mangle much longer than names you write
yourself. If you build with "-fsquangle" symbol names both in the
linkage and debug records are much shorter.
Nathan Myers
ncm@nospam.cantrip.org
p.s. If you reply to this message, please reply only to the list, and
not to me. (If Jason would set up the lists properly, this request
would not be necessary.)