Fw: gcc 3.2 code bloating?
Miguel Ramírez
mramirez@iua.upf.es
Wed Oct 9 02:40:00 GMT 2002
>I'm not 100% on this, but I vaguely recollect that largish parts of
>iostream and friends had to be reworked for standards compliance:
>something along the lines of cout must be a specific instantiation of a
>templated class. (Hopefully someone else will fill in the details.)
Well, I know that gcc 3.1 was the first gcc with a libstdc++ that fully
implemented the standard, making to compile iostream painfully slow
when compared with gcc-2.95.
>Assuming you're using the GNU linker it should automatically discard all
>instatiated templates that it doesn't use.
Yeah, it seems to be some kind of problem with the linker. But since
mingw comes with same (in theory) linker, it seems to be also a problem
for people running more "orthodox" setups.
Besides, that pile of template code seems like not only instantiated because
I am using the
stdout, stdin, stderr C++ interface but also sstream, fstream, etc. Since I
do not know exactly the C++ standards details I am just guessing here.
>> ii) since the binutils are implemented on top of Windoze base services
>> there's an overhead of about 20 k
>I'm curious what you mean by this. I've seen a lot of people try
> gcc helloworld.c
>and MSVC
> cl helloworld.c
>and then niavely compare the size of the binaries and say Windows is
>bloaded or some such: that isn't a fair comparison. For a suitable linux
>or solaris build, for example, GCC defaults to shared C runtime and a
>small segment alignment defined by the elf format (16 bytes or
>thereabouts?) whereas MSVC staticly links the C runtime and defaults to 4K
>segment alignment to match the OS page size. If you instead compile
> cl helloworld.c /MD /link /ALIGN:16
>you'll get a similarly sized executable out of MSVC.
>Going back to your original question, have you tried size or strip on the
>binaries to find out exactly how much is binary or data vs. padding and
>debug info? (hence how much actually gets loaded?)
If I strip the debug-symbols executable:
mramirez@APDIUA1 /c/mingw_tests
$ strip test.exe
I get
mramirez@APDIUA1 /c/mingw_tests
$ ls -la
total 126
drwxr-xr-x 2 mramirez Administ 4096 Oct 9 09:23 .
drwxr-xr-x 100 mramirez Administ 40960 Oct 9 07:22 ..
-rw-r--r-- 1 mramirez Administ 154 Oct 9 07:25 Makefile
-rw-r--r-- 1 mramirez Administ 135 Oct 9 07:29 test.cxx
-rwxr-xr-x 1 mramirez Administ 210944 Oct 9 09:23 test.exe
i.e. 1 MBytes less. But already 200K for a simple "hello world" is too much,
isn't it?
I change the Makefile for a release build:
mramirez@APDIUA1 /c/mingw_tests
$ make clean
rm *.exe
mramirez@APDIUA1 /c/mingw_tests
$ make
g++ -o test -Wall -O2 test.cxx
and I get
mramirez@APDIUA1 /c/mingw_tests
$ ls -la
total 243
drwxr-xr-x 2 mramirez Administ 4096 Oct 9 09:24 .
drwxr-xr-x 100 mramirez Administ 40960 Oct 9 07:22 ..
-rw-r--r-- 1 mramirez Administ 155 Oct 9 09:24 Makefile
-rw-r--r-- 1 mramirez Administ 154 Oct 9 07:25 Makefile~
-rw-r--r-- 1 mramirez Administ 135 Oct 9 07:29 test.cxx
-rwxr-xr-x 1 mramirez Administ 448537 Oct 9 09:24 test.exe
400K for release.... I strip it
mramirez@APDIUA1 /c/mingw_tests
$ strip test.exe
mramirez@APDIUA1 /c/mingw_tests
$ ls -la
total 127
drwxr-xr-x 2 mramirez Administ 4096 Oct 9 09:24 .
drwxr-xr-x 100 mramirez Administ 40960 Oct 9 07:22 ..
-rw-r--r-- 1 mramirez Administ 155 Oct 9 09:24 Makefile
-rw-r--r-- 1 mramirez Administ 154 Oct 9 07:25 Makefile~
-rw-r--r-- 1 mramirez Administ 135 Oct 9 07:29 test.cxx
-rwxr-xr-x 1 mramirez Administ 210944 Oct 9 09:24 test.exe
the same numbers.
I am using the GNU linker for sure, since I am using mingw+msys. No
environment
variable poltergeist here.
Besides, note that I am not comparing build sizes between the Micro$oft
compiler
builds and gcc builds. I am just comparing build size between two different
versions
of gcc on different platforms. A simple helloworld.c such as this one:
#include <stdio.h>
int main( int argc, char** argv )
{
printf("MinGW says hello to you\n");
return 0;
}
mramirez@APDIUA1 /c/mingw_tests
$ gcc -o testC -g -Wall helloworld.c
mramirez@APDIUA1 /c/mingw_tests
$ ls -la testC
-rwxr-xr-x 1 mramirez Administ 25039 Oct 9 09:35 testC
mramirez@APDIUA1 /c/mingw_tests
$ gcc -o testC -Wall helloworld.c
mramirez@APDIUA1 /c/mingw_tests
$ ls -la testC
-rwxr-xr-x 1 mramirez Administ 22443 Oct 9 09:35 testC
mramirez@APDIUA1 /c/mingw_tests
$ strip testC.exe
mramirez@APDIUA1 /c/mingw_tests
$ ls -la testC
-rwxr-xr-x 1 mramirez Administ 10752 Oct 9 09:36 testC
as you can see even the simplest C program is bigger (compared with
gcc-2.95 on a Debian 3.0 box):
SID@rivendel:~/exec_size$ gcc -o testC -Wall helloworld.c
SID@rivendel:~/exec_size$ ls -la testC
-rwxr-xr-x 1 mramirez iua 4832 Oct 9 11:35 testC
I hope I don't confuse anyone with all those shell pasting.
Miguel RamÃrez
More information about the Gcc-help
mailing list