Large code size?

Sam Lantinga slouken@devolution.com
Wed Mar 24 16:28:00 GMT 1999


> > We built robotcom.so with the compiler flags:
> > 	g++ -O2 -funroll-loops -fno-exceptions -DLINUX_BETA -D_REENTRANT
> > and the linker flags:
> > 	cc -shared -nostartfiles -s -o robotcom.so ...

> Hmm.  Does the gnu.linkonce trick work for shared libraries?
> (If you were building an executable and multiple .o files use,
> say, vector<int>, more than one .o file would have a definition
> of some of the vector<int> functions but the GNU linker would
> eliminate all but one copy.  I don't think this works for shared
> libraries, though I may be wrong).

The code size increase happens with both the binary and the shared library.
The shared library is just much smaller, so I was more easily able to tweak
the compilation flags.

The final link is done, and the result with the above flags on the main
binary gives:
-rwxrwxr-x   1 hercules devel     8299204 Mar 25 08:13 civctp
[hercules@asgard src]$ size civctp
   text    data     bss     dec     hex filename
5455970 2786012 1327492 9569474  9204c2 civctp

That's a whopping 4.5MB decrease in size just by using -fno-exceptions
It's still 25% larger than the equivalent VC++ code (which does have
exception handling enabled, BTW), but .5 MB of that is additional library
code that is a separate DLL on Windows, for a final count of only 17%
larger.

Thanks!
	-Sam Lantinga				(slouken@devolution.com)

Lead Programmer, Loki Entertainment Software
--
Author of Simple DirectMedia Layer -
	http://www.devolution.com/~slouken/SDL/
--


More information about the Gcc mailing list