public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Large code size?
@ 1999-03-24 17:57 N8TM
  1999-03-31 23:46 ` N8TM
  0 siblings, 1 reply; 56+ messages in thread
From: N8TM @ 1999-03-24 17:57 UTC (permalink / raw)
  To: slouken, jbuck; +Cc: egcs

In a message dated 3/24/99 4:48:21 PM Pacific Standard Time,
slouken@devolution.com writes:

> > What happens if you replace -O2 with -Os?  (optimize for space ... which
>  > in many cases does a fairly decent job of optimizing for speed as well)?
>  > You should get smaller code.
>  
>  The size decrease is on the order of 5-10%, which isn't worth if it we
>  lose any significant speed.
-Os is faster on i686 than -O2 for my codes, using egcs-1.1.2 -funroll-loops.
-O2 sometimes gains on the experimental/enhanced/snapshots.

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-24 17:57 Large code size? N8TM
@ 1999-03-31 23:46 ` N8TM
  0 siblings, 0 replies; 56+ messages in thread
From: N8TM @ 1999-03-31 23:46 UTC (permalink / raw)
  To: slouken, jbuck; +Cc: egcs

In a message dated 3/24/99 4:48:21 PM Pacific Standard Time,
slouken@devolution.com writes:

> > What happens if you replace -O2 with -Os?  (optimize for space ... which
>  > in many cases does a fairly decent job of optimizing for speed as well)?
>  > You should get smaller code.
>  
>  The size decrease is on the order of 5-10%, which isn't worth if it we
>  lose any significant speed.
-Os is faster on i686 than -O2 for my codes, using egcs-1.1.2 -funroll-loops.
-O2 sometimes gains on the experimental/enhanced/snapshots.

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-24 14:49   ` Dima Volodin
@ 1999-03-31 23:46     ` Dima Volodin
  0 siblings, 0 replies; 56+ messages in thread
From: Dima Volodin @ 1999-03-31 23:46 UTC (permalink / raw)
  To: Martin von Loewis; +Cc: Sam Lantinga, egcs

Martin von Loewis wrote:

> > It looks like exception handling is disabled by default, and we don't use it
> > in our code...  ?
>
> Well, then I recommend compiling with -fno-exceptions. Exception handling
> *is* activated by default.

And use dynamic libstdc++

> Martin

Dima


^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-24 23:22       ` Martin v. Loewis
@ 1999-03-31 23:46         ` Martin v. Loewis
  0 siblings, 0 replies; 56+ messages in thread
From: Martin v. Loewis @ 1999-03-31 23:46 UTC (permalink / raw)
  To: jbuck; +Cc: slouken, hjl, slouken, egcs, mindbender

> Hmm.  Does the gnu.linkonce trick work for shared libraries?

Yes, it does:

mira% g++ -c -fPIC -ftemplate-depth-110  a.cc
mira% size a.o
   text    data     bss     dec     hex filename
 128446    9656       1  138103   21b77 a.o
mira% g++ -c -fPIC -ftemplate-depth-110  b.cc
mira% size a.o                               
   text    data     bss     dec     hex filename
 128446    9656       1  138103   21b77 a.o
mira% g++ -shared -o a.so a.o b.o 
mira% size a.so
   text    data     bss     dec     hex filename
 153487   20756      32  174275   2a8c3 a.so

What doesn't work: you can't eliminate template instantiations from a
shared library in the final link of the program.

Regards,
Martin

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-25  8:28     ` Andi Kleen
@ 1999-03-31 23:46       ` Andi Kleen
  0 siblings, 0 replies; 56+ messages in thread
From: Andi Kleen @ 1999-03-31 23:46 UTC (permalink / raw)
  To: Jason Merrill; +Cc: egcs

jason@cygnus.com (Jason Merrill) writes:

> >>>>> Joe Buck <jbuck@Synopsys.COM> writes:
> 
>  >> 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?
> 
> I would think so, but it certainly doesn't work if you don't use the GNU
> linker, and 'cc' isn't likely to.

On Linux cc is a link to gcc, and the gnu linker is the only linker.

Of course it is possible that he uses an outdated binutils version
that doesn't support it yet.

-Andi
-- 
This is like TV. I don't like TV.

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-24 16:28 Sam Lantinga
       [not found] ` < E10Py0p-0001gL-00@roboto.devolution.com >
@ 1999-03-31 23:46 ` Sam Lantinga
  1 sibling, 0 replies; 56+ messages in thread
From: Sam Lantinga @ 1999-03-31 23:46 UTC (permalink / raw)
  To: Joe Buck; +Cc: slouken, egcs, highlander

> > 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/
--

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-24 14:42 ` Martin von Loewis
  1999-03-24 14:49   ` Dima Volodin
@ 1999-03-31 23:46   ` Martin von Loewis
  1 sibling, 0 replies; 56+ messages in thread
From: Martin von Loewis @ 1999-03-31 23:46 UTC (permalink / raw)
  To: Sam Lantinga; +Cc: egcs

> It looks like exception handling is disabled by default, and we don't use it
> in our code...  ?

Well, then I recommend compiling with -fno-exceptions. Exception handling
*is* activated by default.

Regards,
Martin


^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-25  9:49 Sam Lantinga
       [not found] ` < E10QEFo-0002NA-00@roboto.devolution.com >
@ 1999-03-31 23:46 ` Sam Lantinga
  1 sibling, 0 replies; 56+ messages in thread
From: Sam Lantinga @ 1999-03-31 23:46 UTC (permalink / raw)
  To: Nick Ing-Simmons; +Cc: egcs

> H . J . Lu <hjl@lucon.org> writes:
> >> 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 ...

> Is not -funroll-loops by definition going to make things larger?

Yup, but the speedup is worth the small size increase.
It was the Megabytes of size increase that we were worried about.

	-Sam Lantinga				(slouken@devolution.com)

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

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-24 15:54   ` Joe Buck
       [not found]     ` < 199903242353.PAA02719@atrus.synopsys.com >
@ 1999-03-31 23:46     ` Joe Buck
  1 sibling, 0 replies; 56+ messages in thread
From: Joe Buck @ 1999-03-31 23:46 UTC (permalink / raw)
  To: Sam Lantinga; +Cc: hjl, slouken, egcs, mindbender

> 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).

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-24 17:07   ` H.J. Lu
       [not found]     ` < m10PycJ-000ErMC@ocean.lucon.org >
@ 1999-03-31 23:46     ` H.J. Lu
  1 sibling, 0 replies; 56+ messages in thread
From: H.J. Lu @ 1999-03-31 23:46 UTC (permalink / raw)
  To: Sam Lantinga; +Cc: egcs

> 
> > > > > The egcs version (compiled with egcs 1.1.1, -O2 -funroll-loops):
> > > > > -rwxrwxr-x   1 hercules devel     1534443 Mar 25  1999 robotcom.so
> > > > > 
> > > > > The VC++ version (compiled with VC++ 5.0, /G5 /Ox /Ot /Og /Oi /Op /Ob2)
> > > > > -r-xr-xr-x   1 hercules devel      654336 Mar 14 10:26 robotcom.dll
> > > > > 
> > > > > Any ideas why this might be? 
> > > 
> > > > Did you try to apply 'strip.exe' to the resulting binary?
> 
> > What does
> 
> > # size robotcom.so
> > # file robotcom.so
> 
> > say? BTW, how did you make robotcom.so?
> 
> 
> 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 ...
> 

If that is exactly what you use on Linux, they are wrong. You should
use

# g++ -O2 -fPIC -funroll-loops -fno-exceptions -DLINUX_BETA -D_REENTRANT
# g++ -shared -s -o robotcom.so ...

BTW, you should read

ftp://sunsite.unc.edu/pub/Linux/GCC/elf.ps.gz

if you want to program under Linux. It is kind of dated. But it is
still quite useful.


-- 
H.J. Lu (hjl@gnu.org)

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-24 16:47 Sam Lantinga
@ 1999-03-31 23:46 ` Sam Lantinga
  0 siblings, 0 replies; 56+ messages in thread
From: Sam Lantinga @ 1999-03-31 23:46 UTC (permalink / raw)
  To: Joe Buck; +Cc: egcs, slouken

> > 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.

> What happens if you replace -O2 with -Os?  (optimize for space ... which
> in many cases does a fairly decent job of optimizing for speed as well)?
> You should get smaller code.

The size decrease is on the order of 5-10%, which isn't worth if it we
lose any significant speed.

	-Sam Lantinga				(slouken@devolution.com)

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

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-25 14:35       ` Martin v. Loewis
@ 1999-03-31 23:46         ` Martin v. Loewis
  0 siblings, 0 replies; 56+ messages in thread
From: Martin v. Loewis @ 1999-03-31 23:46 UTC (permalink / raw)
  To: jason; +Cc: jbuck, hjl, slouken, egcs, mindbender

>  > Hmm.  Does the gnu.linkonce trick work for shared libraries?
> 
> I would think so, but it certainly doesn't work if you don't use the GNU
> linker, and 'cc' isn't likely to.

In Linux, it will.

regards,
Martin

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-24 15:42 Sam Lantinga
       [not found] ` < E10PxHr-0001fO-00@roboto.devolution.com >
       [not found] ` <199903242353.PAA02719.cygnus.egcs@atrus.synopsys.com>
@ 1999-03-31 23:46 ` Sam Lantinga
  2 siblings, 0 replies; 56+ messages in thread
From: Sam Lantinga @ 1999-03-31 23:46 UTC (permalink / raw)
  To: H.J. Lu; +Cc: slouken, egcs, mindbender

> > > > The egcs version (compiled with egcs 1.1.1, -O2 -funroll-loops):
> > > > -rwxrwxr-x   1 hercules devel     1534443 Mar 25  1999 robotcom.so
> > > > 
> > > > The VC++ version (compiled with VC++ 5.0, /G5 /Ox /Ot /Og /Oi /Op /Ob2)
> > > > -r-xr-xr-x   1 hercules devel      654336 Mar 14 10:26 robotcom.dll
> > > > 
> > > > Any ideas why this might be? 
> > 
> > > Did you try to apply 'strip.exe' to the resulting binary?

> What does

> # size robotcom.so
> # file robotcom.so

> say? BTW, how did you make robotcom.so?


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 ...

The final result is:

-rwxrwxr-x   1 hercules devel     1011648 Mar 25 07:35 robotcom.so
[hercules@asgard robotcom]$ size robotcom.so
   text    data     bss     dec     hex filename
 991092    9768  198820 1199680  124e40 robotcom.so
[hercules@asgard robotcom]$ file robotcom.so
robotcom.so: ELF 32-bit LSB shared object, Intel 80386, version 1, stripped
[hercules@asgard robotcom]$ ldd robotcom.so
        libc.so.6 => /lib/libc.so.6 (0x4012a000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x2aaaa000)

Removing -funroll-loops from the flags gives us:
-rwxrwxr-x   1 hercules devel      948704 Mar 25 07:42 robotcom.so

I'm rebuilding the entire application with those flags now.
--
	-Sam Lantinga				(slouken@devolution.com)

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

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-24 15:05 Sam Lantinga
       [not found] ` < E10PwfK-0001bs-00@roboto.devolution.com >
@ 1999-03-31 23:46 ` Sam Lantinga
  1 sibling, 0 replies; 56+ messages in thread
From: Sam Lantinga @ 1999-03-31 23:46 UTC (permalink / raw)
  To: Martin von Loewis; +Cc: egcs, slouken, highlander

> > It looks like exception handling is disabled by default, and we don't use it
> > in our code...  ?

> Well, then I recommend compiling with -fno-exceptions. Exception handling
> *is* activated by default.

The smallest I could get it, using -Os, -fno-exceptions, no optimization,
and -s was 950K, still 50% bigger than VC++.

I think it's the template code that might be big.  It uses templates all
over the place, templates which don't compile using gcc.  Can anyone 
confirm this?  I don't know if it's something that can be reduced to
a simple case.  (I could be wrong, too. :)

It's also interesting that linking it with cc1plus as opposed to cc1
results in a binary 24K bigger, because, according to the linker, it
links in file io stuff from /usr/lib/stdc++.  The final binary which
dynamically loads it presumably has those routines available, and is
compiled with -Wl,--export-dynamic, so it should pick them up.

Also, when linking with either cc1 or cc1plus, and specifying
-fno-exceptions, the exception.o object from libgcc.a is still
linked in.

Ideas?
	-Sam Lantinga				(slouken@devolution.com)

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

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-25  9:48 Sam Lantinga
  1999-03-25 11:24 ` Jason Merrill
@ 1999-03-31 23:46 ` Sam Lantinga
  1 sibling, 0 replies; 56+ messages in thread
From: Sam Lantinga @ 1999-03-31 23:46 UTC (permalink / raw)
  To: Jason Merrill; +Cc: slouken, egcs

> >>>>> Joe Buck <jbuck@Synopsys.COM> writes:

>  >> 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?

> I would think so, but it certainly doesn't work if you don't use the GNU
> linker, and 'cc' isn't likely to.

On our system cc --> gcc
What is this gnu.linkonce trick?  Is it automagically used by gcc?


	-Sam Lantinga				(slouken@devolution.com)

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

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-24 14:10   ` Martin v. Loewis
@ 1999-03-31 23:46     ` Martin v. Loewis
  0 siblings, 0 replies; 56+ messages in thread
From: Martin v. Loewis @ 1999-03-31 23:46 UTC (permalink / raw)
  To: slouken; +Cc: loewis, slouken, egcs

> Yup, it's on Linux, so we used 'strip', but it only cut about a hundred K
> off of it.  (It wasn't compiled with -g)

Ok. So when you call the compiler with -Wl,--verbose (on Linux), do
you see any additional objects being pulled-in?

My next guess would then be exception handling.

Martin

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Large code size?
  1999-03-24  9:38 Sam Lantinga
       [not found] ` < E10PrbT-0003Og-00@roboto.devolution.com >
@ 1999-03-31 23:46 ` Sam Lantinga
  1 sibling, 0 replies; 56+ messages in thread
From: Sam Lantinga @ 1999-03-31 23:46 UTC (permalink / raw)
  To: egcs; +Cc: hercules, slouken

I'm comparing code size of an application compiled with VC++ and with egcs,
1.1.1 and the VC++ binary is smaller than the egcs binary by an almost exact
factor of two.  The code being compared is self-contained, i.e. it calls no
library routines internally, and is pretty hairy C++ template code.

The egcs version (compiled with egcs 1.1.1, -O2 -funroll-loops):
-rwxrwxr-x   1 hercules devel     1534443 Mar 25  1999 robotcom.so

The VC++ version (compiled with VC++ 5.0, /G5 /Ox /Ot /Og /Oi /Op /Ob2)
-r-xr-xr-x   1 hercules devel      654336 Mar 14 10:26 robotcom.dll

Any ideas why this might be?  The same ratio is true for the main
application, which is 13 MB on Linux, and 6 MB on Windows.  7 MB
of difference makes a significant impact on performance, and our
application compares poorly to the Windows version.  We'd like it
to compare favorably. :)

Your thoughts, O Gurus? :)

	-Sam Lantinga				(slouken@devolution.com)

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

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-25  5:04       ` Nick Ing-Simmons
@ 1999-03-31 23:46         ` Nick Ing-Simmons
  0 siblings, 0 replies; 56+ messages in thread
From: Nick Ing-Simmons @ 1999-03-31 23:46 UTC (permalink / raw)
  To: hjl; +Cc: egcs, Sam Lantinga

H . J . Lu <hjl@lucon.org> writes:
>> 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 ...

Is not -funroll-loops by definition going to make things larger?
-- 
Nick Ing-Simmons <nik@tiuk.ti.com>
Via, but not speaking for: Texas Instruments Ltd.


^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-24 23:26   ` Martin v. Loewis
@ 1999-03-31 23:46     ` Martin v. Loewis
  0 siblings, 0 replies; 56+ messages in thread
From: Martin v. Loewis @ 1999-03-31 23:46 UTC (permalink / raw)
  To: slouken; +Cc: egcs, highlander

> I think it's the template code that might be big.  It uses templates all
> over the place, templates which don't compile using gcc.  Can anyone 
> confirm this?

If it's just the confirmation that you're after: I can confirm this
:-)

Regards,
Martin

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-25 11:24 ` Jason Merrill
@ 1999-03-31 23:46   ` Jason Merrill
  0 siblings, 0 replies; 56+ messages in thread
From: Jason Merrill @ 1999-03-31 23:46 UTC (permalink / raw)
  To: Sam Lantinga; +Cc: egcs

>>>>> Sam Lantinga <slouken@devolution.com> writes:

 >> >>>>> Joe Buck <jbuck@Synopsys.COM> writes:
 >>  >> 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?

 >> I would think so, but it certainly doesn't work if you don't use the GNU
 >> linker, and 'cc' isn't likely to.

 > On our system cc --> gcc

Then it should be OK.

 > What is this gnu.linkonce trick?  Is it automagically used by gcc?

The compiler puts template instantiations into separate sections, and the
linker discards duplicates.  Yes.

Jason

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-24 16:34 Mike Stump
@ 1999-03-31 23:46 ` Mike Stump
  0 siblings, 0 replies; 56+ messages in thread
From: Mike Stump @ 1999-03-31 23:46 UTC (permalink / raw)
  To: jbuck, slouken; +Cc: egcs, highlander

And you might use -fno-rtti, if you're not using Run Time Type Information.

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-24 16:45   ` Joe Buck
@ 1999-03-31 23:46     ` Joe Buck
  0 siblings, 0 replies; 56+ messages in thread
From: Joe Buck @ 1999-03-31 23:46 UTC (permalink / raw)
  To: Sam Lantinga; +Cc: jbuck, slouken, egcs, highlander

> 
> 
> > > 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 ...
> ...

> 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.

What happens if you replace -O2 with -Os?  (optimize for space ... which
in many cases does a fairly decent job of optimizing for speed as well)?
You should get smaller code.


^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-24 13:52 Sam Lantinga
       [not found] ` < E10PvY5-0001NJ-00@roboto.devolution.com >
@ 1999-03-31 23:46 ` Sam Lantinga
  1 sibling, 0 replies; 56+ messages in thread
From: Sam Lantinga @ 1999-03-31 23:46 UTC (permalink / raw)
  To: Martin v. Loewis; +Cc: slouken, egcs

> > The egcs version (compiled with egcs 1.1.1, -O2 -funroll-loops):
> > -rwxrwxr-x   1 hercules devel     1534443 Mar 25  1999 robotcom.so
> > 
> > The VC++ version (compiled with VC++ 5.0, /G5 /Ox /Ot /Og /Oi /Op /Ob2)
> > -r-xr-xr-x   1 hercules devel      654336 Mar 14 10:26 robotcom.dll
> > 
> > Any ideas why this might be? 

> Did you try to apply 'strip.exe' to the resulting binary?

Yup, it's on Linux, so we used 'strip', but it only cut about a hundred K
off of it.  (It wasn't compiled with -g)

	-Sam Lantinga				(slouken@devolution.com)

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

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-25  1:08   ` Jason Merrill
  1999-03-25  8:28     ` Andi Kleen
       [not found]     ` < u9n212vswe.fsf@yorick.cygnus.com >
@ 1999-03-31 23:46     ` Jason Merrill
  2 siblings, 0 replies; 56+ messages in thread
From: Jason Merrill @ 1999-03-31 23:46 UTC (permalink / raw)
  To: Joe Buck; +Cc: hjl, slouken, egcs, mindbender

>>>>> Joe Buck <jbuck@Synopsys.COM> writes:

 >> 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?

I would think so, but it certainly doesn't work if you don't use the GNU
linker, and 'cc' isn't likely to.

Jason

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-24 13:38   ` Martin v. Loewis
@ 1999-03-31 23:46     ` Martin v. Loewis
  0 siblings, 0 replies; 56+ messages in thread
From: Martin v. Loewis @ 1999-03-31 23:46 UTC (permalink / raw)
  To: slouken; +Cc: egcs, hercules, slouken

> The egcs version (compiled with egcs 1.1.1, -O2 -funroll-loops):
> -rwxrwxr-x   1 hercules devel     1534443 Mar 25  1999 robotcom.so
> 
> The VC++ version (compiled with VC++ 5.0, /G5 /Ox /Ot /Og /Oi /Op /Ob2)
> -r-xr-xr-x   1 hercules devel      654336 Mar 14 10:26 robotcom.dll
> 
> Any ideas why this might be? 

Did you try to apply 'strip.exe' to the resulting binary?

Regards,
Martin

^ permalink raw reply	[flat|nested] 56+ messages in thread

* RE: Large code size?
  1999-03-24 13:29   ` David B. Rees
@ 1999-03-31 23:46     ` David B. Rees
  0 siblings, 0 replies; 56+ messages in thread
From: David B. Rees @ 1999-03-31 23:46 UTC (permalink / raw)
  To: Sam Lantinga; +Cc: egcs

On 24-Mar-99 Sam Lantinga wrote:
> I'm comparing code size of an application compiled with VC++ and with egcs,
> 1.1.1 and the VC++ binary is smaller than the egcs binary by an almost exact
> factor of two.  The code being compared is self-contained, i.e. it calls no
> library routines internally, and is pretty hairy C++ template code.
> 
> The egcs version (compiled with egcs 1.1.1, -O2 -funroll-loops):
> -rwxrwxr-x   1 hercules devel     1534443 Mar 25  1999 robotcom.so
> 
> The VC++ version (compiled with VC++ 5.0, /G5 /Ox /Ot /Og /Oi /Op /Ob2)
> -r-xr-xr-x   1 hercules devel      654336 Mar 14 10:26 robotcom.dll
> 
> Any ideas why this might be?  The same ratio is true for the main
> application, which is 13 MB on Linux, and 6 MB on Windows.  7 MB
> of difference makes a significant impact on performance, and our
> application compares poorly to the Windows version.  We'd like it
> to compare favorably. :)
> 
> Your thoughts, O Gurus? :)

Did you try running strip on the library?  Also, compiling with the flag -Os
should optimize the code for size, instead of speed.

-Dave

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-24 23:35   ` Martin v. Loewis
@ 1999-03-31 23:46     ` Martin v. Loewis
  0 siblings, 0 replies; 56+ messages in thread
From: Martin v. Loewis @ 1999-03-31 23:46 UTC (permalink / raw)
  To: slouken; +Cc: egcs, highlander

> Also, when linking with either cc1 or cc1plus, and specifying
> -fno-exceptions, the exception.o object from libgcc.a is still
> linked in.
> 
> Ideas?

If you use ::operator new, it might throw exceptions, so you get some
exception routines in. Also, it always has to provide the frame
unwinding code for the shared library, regardless of whether some
object files never throw exceptions and don't support unwinding.

Regards,
Martin

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-24 15:18   ` H.J. Lu
@ 1999-03-31 23:46     ` H.J. Lu
  0 siblings, 0 replies; 56+ messages in thread
From: H.J. Lu @ 1999-03-31 23:46 UTC (permalink / raw)
  To: Sam Lantinga; +Cc: loewis, slouken, egcs

> 
> > > The egcs version (compiled with egcs 1.1.1, -O2 -funroll-loops):
> > > -rwxrwxr-x   1 hercules devel     1534443 Mar 25  1999 robotcom.so
> > > 
> > > The VC++ version (compiled with VC++ 5.0, /G5 /Ox /Ot /Og /Oi /Op /Ob2)
> > > -r-xr-xr-x   1 hercules devel      654336 Mar 14 10:26 robotcom.dll
> > > 
> > > Any ideas why this might be? 
> 
> > Did you try to apply 'strip.exe' to the resulting binary?
> 
> Yup, it's on Linux, so we used 'strip', but it only cut about a hundred K
> off of it.  (It wasn't compiled with -g)
> 

What does

# size robotcom.so
# file robotcom.so

say? BTW, how did you make robotcom.so?



-- 
H.J. Lu (hjl@gnu.org)

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-25 10:14   ` H.J. Lu
@ 1999-03-31 23:46     ` H.J. Lu
  0 siblings, 0 replies; 56+ messages in thread
From: H.J. Lu @ 1999-03-31 23:46 UTC (permalink / raw)
  To: Sam Lantinga; +Cc: egcs

> 
> > H . J . Lu <hjl@lucon.org> writes:
> > >> 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 ...
> 
> > Is not -funroll-loops by definition going to make things larger?
> 
> Yup, but the speedup is worth the small size increase.
> It was the Megabytes of size increase that we were worried about.
> 

Your setup doesn't sound right. You should not have seen the MB size
increase. If you want, I can compile your stuff on my machine to see
what I get.

-- 
H.J. Lu (hjl@gnu.org)

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
       [not found]     ` < u9n212vswe.fsf@yorick.cygnus.com >
@ 1999-03-25 14:35       ` Martin v. Loewis
  1999-03-31 23:46         ` Martin v. Loewis
  0 siblings, 1 reply; 56+ messages in thread
From: Martin v. Loewis @ 1999-03-25 14:35 UTC (permalink / raw)
  To: jason; +Cc: jbuck, hjl, slouken, egcs, mindbender

>  > Hmm.  Does the gnu.linkonce trick work for shared libraries?
> 
> I would think so, but it certainly doesn't work if you don't use the GNU
> linker, and 'cc' isn't likely to.

In Linux, it will.

regards,
Martin

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-25  9:48 Sam Lantinga
@ 1999-03-25 11:24 ` Jason Merrill
  1999-03-31 23:46   ` Jason Merrill
  1999-03-31 23:46 ` Sam Lantinga
  1 sibling, 1 reply; 56+ messages in thread
From: Jason Merrill @ 1999-03-25 11:24 UTC (permalink / raw)
  To: Sam Lantinga; +Cc: egcs

>>>>> Sam Lantinga <slouken@devolution.com> writes:

 >> >>>>> Joe Buck <jbuck@Synopsys.COM> writes:
 >>  >> 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?

 >> I would think so, but it certainly doesn't work if you don't use the GNU
 >> linker, and 'cc' isn't likely to.

 > On our system cc --> gcc

Then it should be OK.

 > What is this gnu.linkonce trick?  Is it automagically used by gcc?

The compiler puts template instantiations into separate sections, and the
linker discards duplicates.  Yes.

Jason

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
       [not found] ` < E10QEFo-0002NA-00@roboto.devolution.com >
@ 1999-03-25 10:14   ` H.J. Lu
  1999-03-31 23:46     ` H.J. Lu
  0 siblings, 1 reply; 56+ messages in thread
From: H.J. Lu @ 1999-03-25 10:14 UTC (permalink / raw)
  To: Sam Lantinga; +Cc: egcs

> 
> > H . J . Lu <hjl@lucon.org> writes:
> > >> 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 ...
> 
> > Is not -funroll-loops by definition going to make things larger?
> 
> Yup, but the speedup is worth the small size increase.
> It was the Megabytes of size increase that we were worried about.
> 

Your setup doesn't sound right. You should not have seen the MB size
increase. If you want, I can compile your stuff on my machine to see
what I get.

-- 
H.J. Lu (hjl@gnu.org)

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
@ 1999-03-25  9:49 Sam Lantinga
       [not found] ` < E10QEFo-0002NA-00@roboto.devolution.com >
  1999-03-31 23:46 ` Sam Lantinga
  0 siblings, 2 replies; 56+ messages in thread
From: Sam Lantinga @ 1999-03-25  9:49 UTC (permalink / raw)
  To: Nick Ing-Simmons; +Cc: egcs

> H . J . Lu <hjl@lucon.org> writes:
> >> 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 ...

> Is not -funroll-loops by definition going to make things larger?

Yup, but the speedup is worth the small size increase.
It was the Megabytes of size increase that we were worried about.

	-Sam Lantinga				(slouken@devolution.com)

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

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
@ 1999-03-25  9:48 Sam Lantinga
  1999-03-25 11:24 ` Jason Merrill
  1999-03-31 23:46 ` Sam Lantinga
  0 siblings, 2 replies; 56+ messages in thread
From: Sam Lantinga @ 1999-03-25  9:48 UTC (permalink / raw)
  To: Jason Merrill; +Cc: slouken, egcs

> >>>>> Joe Buck <jbuck@Synopsys.COM> writes:

>  >> 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?

> I would think so, but it certainly doesn't work if you don't use the GNU
> linker, and 'cc' isn't likely to.

On our system cc --> gcc
What is this gnu.linkonce trick?  Is it automagically used by gcc?


	-Sam Lantinga				(slouken@devolution.com)

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

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-25  1:08   ` Jason Merrill
@ 1999-03-25  8:28     ` Andi Kleen
  1999-03-31 23:46       ` Andi Kleen
       [not found]     ` < u9n212vswe.fsf@yorick.cygnus.com >
  1999-03-31 23:46     ` Jason Merrill
  2 siblings, 1 reply; 56+ messages in thread
From: Andi Kleen @ 1999-03-25  8:28 UTC (permalink / raw)
  To: Jason Merrill; +Cc: egcs

jason@cygnus.com (Jason Merrill) writes:

> >>>>> Joe Buck <jbuck@Synopsys.COM> writes:
> 
>  >> 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?
> 
> I would think so, but it certainly doesn't work if you don't use the GNU
> linker, and 'cc' isn't likely to.

On Linux cc is a link to gcc, and the gnu linker is the only linker.

Of course it is possible that he uses an outdated binutils version
that doesn't support it yet.

-Andi
-- 
This is like TV. I don't like TV.

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
       [not found]     ` < m10PycJ-000ErMC@ocean.lucon.org >
@ 1999-03-25  5:04       ` Nick Ing-Simmons
  1999-03-31 23:46         ` Nick Ing-Simmons
  0 siblings, 1 reply; 56+ messages in thread
From: Nick Ing-Simmons @ 1999-03-25  5:04 UTC (permalink / raw)
  To: hjl; +Cc: egcs, Sam Lantinga

H . J . Lu <hjl@lucon.org> writes:
>> 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 ...

Is not -funroll-loops by definition going to make things larger?
-- 
Nick Ing-Simmons <nik@tiuk.ti.com>
Via, but not speaking for: Texas Instruments Ltd.

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
       [not found] ` <199903242353.PAA02719.cygnus.egcs@atrus.synopsys.com>
@ 1999-03-25  1:08   ` Jason Merrill
  1999-03-25  8:28     ` Andi Kleen
                       ` (2 more replies)
  0 siblings, 3 replies; 56+ messages in thread
From: Jason Merrill @ 1999-03-25  1:08 UTC (permalink / raw)
  To: Joe Buck; +Cc: hjl, slouken, egcs, mindbender

>>>>> Joe Buck <jbuck@Synopsys.COM> writes:

 >> 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?

I would think so, but it certainly doesn't work if you don't use the GNU
linker, and 'cc' isn't likely to.

Jason

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
       [not found] ` < E10PwfK-0001bs-00@roboto.devolution.com >
  1999-03-24 23:26   ` Martin v. Loewis
@ 1999-03-24 23:35   ` Martin v. Loewis
  1999-03-31 23:46     ` Martin v. Loewis
  1 sibling, 1 reply; 56+ messages in thread
From: Martin v. Loewis @ 1999-03-24 23:35 UTC (permalink / raw)
  To: slouken; +Cc: egcs, highlander

> Also, when linking with either cc1 or cc1plus, and specifying
> -fno-exceptions, the exception.o object from libgcc.a is still
> linked in.
> 
> Ideas?

If you use ::operator new, it might throw exceptions, so you get some
exception routines in. Also, it always has to provide the frame
unwinding code for the shared library, regardless of whether some
object files never throw exceptions and don't support unwinding.

Regards,
Martin

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
       [not found] ` < E10PwfK-0001bs-00@roboto.devolution.com >
@ 1999-03-24 23:26   ` Martin v. Loewis
  1999-03-31 23:46     ` Martin v. Loewis
  1999-03-24 23:35   ` Martin v. Loewis
  1 sibling, 1 reply; 56+ messages in thread
From: Martin v. Loewis @ 1999-03-24 23:26 UTC (permalink / raw)
  To: slouken; +Cc: egcs, highlander

> I think it's the template code that might be big.  It uses templates all
> over the place, templates which don't compile using gcc.  Can anyone 
> confirm this?

If it's just the confirmation that you're after: I can confirm this
:-)

Regards,
Martin

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
       [not found]     ` < 199903242353.PAA02719@atrus.synopsys.com >
@ 1999-03-24 23:22       ` Martin v. Loewis
  1999-03-31 23:46         ` Martin v. Loewis
  0 siblings, 1 reply; 56+ messages in thread
From: Martin v. Loewis @ 1999-03-24 23:22 UTC (permalink / raw)
  To: jbuck; +Cc: slouken, hjl, slouken, egcs, mindbender

> Hmm.  Does the gnu.linkonce trick work for shared libraries?

Yes, it does:

mira% g++ -c -fPIC -ftemplate-depth-110  a.cc
mira% size a.o
   text    data     bss     dec     hex filename
 128446    9656       1  138103   21b77 a.o
mira% g++ -c -fPIC -ftemplate-depth-110  b.cc
mira% size a.o                               
   text    data     bss     dec     hex filename
 128446    9656       1  138103   21b77 a.o
mira% g++ -shared -o a.so a.o b.o 
mira% size a.so
   text    data     bss     dec     hex filename
 153487   20756      32  174275   2a8c3 a.so

What doesn't work: you can't eliminate template instantiations from a
shared library in the final link of the program.

Regards,
Martin

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
       [not found] ` < E10PxHr-0001fO-00@roboto.devolution.com >
  1999-03-24 15:54   ` Joe Buck
@ 1999-03-24 17:07   ` H.J. Lu
       [not found]     ` < m10PycJ-000ErMC@ocean.lucon.org >
  1999-03-31 23:46     ` H.J. Lu
  1 sibling, 2 replies; 56+ messages in thread
From: H.J. Lu @ 1999-03-24 17:07 UTC (permalink / raw)
  To: Sam Lantinga; +Cc: egcs

> 
> > > > > The egcs version (compiled with egcs 1.1.1, -O2 -funroll-loops):
> > > > > -rwxrwxr-x   1 hercules devel     1534443 Mar 25  1999 robotcom.so
> > > > > 
> > > > > The VC++ version (compiled with VC++ 5.0, /G5 /Ox /Ot /Og /Oi /Op /Ob2)
> > > > > -r-xr-xr-x   1 hercules devel      654336 Mar 14 10:26 robotcom.dll
> > > > > 
> > > > > Any ideas why this might be? 
> > > 
> > > > Did you try to apply 'strip.exe' to the resulting binary?
> 
> > What does
> 
> > # size robotcom.so
> > # file robotcom.so
> 
> > say? BTW, how did you make robotcom.so?
> 
> 
> 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 ...
> 

If that is exactly what you use on Linux, they are wrong. You should
use

# g++ -O2 -fPIC -funroll-loops -fno-exceptions -DLINUX_BETA -D_REENTRANT
# g++ -shared -s -o robotcom.so ...

BTW, you should read

ftp://sunsite.unc.edu/pub/Linux/GCC/elf.ps.gz

if you want to program under Linux. It is kind of dated. But it is
still quite useful.


-- 
H.J. Lu (hjl@gnu.org)

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
@ 1999-03-24 16:47 Sam Lantinga
  1999-03-31 23:46 ` Sam Lantinga
  0 siblings, 1 reply; 56+ messages in thread
From: Sam Lantinga @ 1999-03-24 16:47 UTC (permalink / raw)
  To: Joe Buck; +Cc: egcs, slouken

> > 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.

> What happens if you replace -O2 with -Os?  (optimize for space ... which
> in many cases does a fairly decent job of optimizing for speed as well)?
> You should get smaller code.

The size decrease is on the order of 5-10%, which isn't worth if it we
lose any significant speed.

	-Sam Lantinga				(slouken@devolution.com)

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

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
       [not found] ` < E10Py0p-0001gL-00@roboto.devolution.com >
@ 1999-03-24 16:45   ` Joe Buck
  1999-03-31 23:46     ` Joe Buck
  0 siblings, 1 reply; 56+ messages in thread
From: Joe Buck @ 1999-03-24 16:45 UTC (permalink / raw)
  To: Sam Lantinga; +Cc: jbuck, slouken, egcs, highlander

> 
> 
> > > 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 ...
> ...

> 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.

What happens if you replace -O2 with -Os?  (optimize for space ... which
in many cases does a fairly decent job of optimizing for speed as well)?
You should get smaller code.

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
@ 1999-03-24 16:34 Mike Stump
  1999-03-31 23:46 ` Mike Stump
  0 siblings, 1 reply; 56+ messages in thread
From: Mike Stump @ 1999-03-24 16:34 UTC (permalink / raw)
  To: jbuck, slouken; +Cc: egcs, highlander

And you might use -fno-rtti, if you're not using Run Time Type Information.

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
@ 1999-03-24 16:28 Sam Lantinga
       [not found] ` < E10Py0p-0001gL-00@roboto.devolution.com >
  1999-03-31 23:46 ` Sam Lantinga
  0 siblings, 2 replies; 56+ messages in thread
From: Sam Lantinga @ 1999-03-24 16:28 UTC (permalink / raw)
  To: Joe Buck; +Cc: slouken, egcs, highlander

> > 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/
--

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
       [not found] ` < E10PxHr-0001fO-00@roboto.devolution.com >
@ 1999-03-24 15:54   ` Joe Buck
       [not found]     ` < 199903242353.PAA02719@atrus.synopsys.com >
  1999-03-31 23:46     ` Joe Buck
  1999-03-24 17:07   ` H.J. Lu
  1 sibling, 2 replies; 56+ messages in thread
From: Joe Buck @ 1999-03-24 15:54 UTC (permalink / raw)
  To: Sam Lantinga; +Cc: hjl, slouken, egcs, mindbender

> 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).

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
@ 1999-03-24 15:42 Sam Lantinga
       [not found] ` < E10PxHr-0001fO-00@roboto.devolution.com >
                   ` (2 more replies)
  0 siblings, 3 replies; 56+ messages in thread
From: Sam Lantinga @ 1999-03-24 15:42 UTC (permalink / raw)
  To: H.J. Lu; +Cc: slouken, egcs, mindbender

> > > > The egcs version (compiled with egcs 1.1.1, -O2 -funroll-loops):
> > > > -rwxrwxr-x   1 hercules devel     1534443 Mar 25  1999 robotcom.so
> > > > 
> > > > The VC++ version (compiled with VC++ 5.0, /G5 /Ox /Ot /Og /Oi /Op /Ob2)
> > > > -r-xr-xr-x   1 hercules devel      654336 Mar 14 10:26 robotcom.dll
> > > > 
> > > > Any ideas why this might be? 
> > 
> > > Did you try to apply 'strip.exe' to the resulting binary?

> What does

> # size robotcom.so
> # file robotcom.so

> say? BTW, how did you make robotcom.so?


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 ...

The final result is:

-rwxrwxr-x   1 hercules devel     1011648 Mar 25 07:35 robotcom.so
[hercules@asgard robotcom]$ size robotcom.so
   text    data     bss     dec     hex filename
 991092    9768  198820 1199680  124e40 robotcom.so
[hercules@asgard robotcom]$ file robotcom.so
robotcom.so: ELF 32-bit LSB shared object, Intel 80386, version 1, stripped
[hercules@asgard robotcom]$ ldd robotcom.so
        libc.so.6 => /lib/libc.so.6 (0x4012a000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x2aaaa000)

Removing -funroll-loops from the flags gives us:
-rwxrwxr-x   1 hercules devel      948704 Mar 25 07:42 robotcom.so

I'm rebuilding the entire application with those flags now.
--
	-Sam Lantinga				(slouken@devolution.com)

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

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
       [not found] ` < E10PvY5-0001NJ-00@roboto.devolution.com >
  1999-03-24 14:10   ` Martin v. Loewis
@ 1999-03-24 15:18   ` H.J. Lu
  1999-03-31 23:46     ` H.J. Lu
  1 sibling, 1 reply; 56+ messages in thread
From: H.J. Lu @ 1999-03-24 15:18 UTC (permalink / raw)
  To: Sam Lantinga; +Cc: loewis, slouken, egcs

> 
> > > The egcs version (compiled with egcs 1.1.1, -O2 -funroll-loops):
> > > -rwxrwxr-x   1 hercules devel     1534443 Mar 25  1999 robotcom.so
> > > 
> > > The VC++ version (compiled with VC++ 5.0, /G5 /Ox /Ot /Og /Oi /Op /Ob2)
> > > -r-xr-xr-x   1 hercules devel      654336 Mar 14 10:26 robotcom.dll
> > > 
> > > Any ideas why this might be? 
> 
> > Did you try to apply 'strip.exe' to the resulting binary?
> 
> Yup, it's on Linux, so we used 'strip', but it only cut about a hundred K
> off of it.  (It wasn't compiled with -g)
> 

What does

# size robotcom.so
# file robotcom.so

say? BTW, how did you make robotcom.so?



-- 
H.J. Lu (hjl@gnu.org)

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
@ 1999-03-24 15:05 Sam Lantinga
       [not found] ` < E10PwfK-0001bs-00@roboto.devolution.com >
  1999-03-31 23:46 ` Sam Lantinga
  0 siblings, 2 replies; 56+ messages in thread
From: Sam Lantinga @ 1999-03-24 15:05 UTC (permalink / raw)
  To: Martin von Loewis; +Cc: egcs, slouken, highlander

> > It looks like exception handling is disabled by default, and we don't use it
> > in our code...  ?

> Well, then I recommend compiling with -fno-exceptions. Exception handling
> *is* activated by default.

The smallest I could get it, using -Os, -fno-exceptions, no optimization,
and -s was 950K, still 50% bigger than VC++.

I think it's the template code that might be big.  It uses templates all
over the place, templates which don't compile using gcc.  Can anyone 
confirm this?  I don't know if it's something that can be reduced to
a simple case.  (I could be wrong, too. :)

It's also interesting that linking it with cc1plus as opposed to cc1
results in a binary 24K bigger, because, according to the linker, it
links in file io stuff from /usr/lib/stdc++.  The final binary which
dynamically loads it presumably has those routines available, and is
compiled with -Wl,--export-dynamic, so it should pick them up.

Also, when linking with either cc1 or cc1plus, and specifying
-fno-exceptions, the exception.o object from libgcc.a is still
linked in.

Ideas?
	-Sam Lantinga				(slouken@devolution.com)

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

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
  1999-03-24 14:42 ` Martin von Loewis
@ 1999-03-24 14:49   ` Dima Volodin
  1999-03-31 23:46     ` Dima Volodin
  1999-03-31 23:46   ` Martin von Loewis
  1 sibling, 1 reply; 56+ messages in thread
From: Dima Volodin @ 1999-03-24 14:49 UTC (permalink / raw)
  To: Martin von Loewis; +Cc: Sam Lantinga, egcs

Martin von Loewis wrote:

> > It looks like exception handling is disabled by default, and we don't use it
> > in our code...  ?
>
> Well, then I recommend compiling with -fno-exceptions. Exception handling
> *is* activated by default.

And use dynamic libstdc++

> Martin

Dima

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
       [not found] <E10PwA2-0001UN-00@roboto.devolution.com>
@ 1999-03-24 14:42 ` Martin von Loewis
  1999-03-24 14:49   ` Dima Volodin
  1999-03-31 23:46   ` Martin von Loewis
  0 siblings, 2 replies; 56+ messages in thread
From: Martin von Loewis @ 1999-03-24 14:42 UTC (permalink / raw)
  To: Sam Lantinga; +Cc: egcs

> It looks like exception handling is disabled by default, and we don't use it
> in our code...  ?

Well, then I recommend compiling with -fno-exceptions. Exception handling
*is* activated by default.

Regards,
Martin

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
       [not found] ` < E10PvY5-0001NJ-00@roboto.devolution.com >
@ 1999-03-24 14:10   ` Martin v. Loewis
  1999-03-31 23:46     ` Martin v. Loewis
  1999-03-24 15:18   ` H.J. Lu
  1 sibling, 1 reply; 56+ messages in thread
From: Martin v. Loewis @ 1999-03-24 14:10 UTC (permalink / raw)
  To: slouken; +Cc: loewis, slouken, egcs

> Yup, it's on Linux, so we used 'strip', but it only cut about a hundred K
> off of it.  (It wasn't compiled with -g)

Ok. So when you call the compiler with -Wl,--verbose (on Linux), do
you see any additional objects being pulled-in?

My next guess would then be exception handling.

Martin

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
@ 1999-03-24 13:52 Sam Lantinga
       [not found] ` < E10PvY5-0001NJ-00@roboto.devolution.com >
  1999-03-31 23:46 ` Sam Lantinga
  0 siblings, 2 replies; 56+ messages in thread
From: Sam Lantinga @ 1999-03-24 13:52 UTC (permalink / raw)
  To: Martin v. Loewis; +Cc: slouken, egcs

> > The egcs version (compiled with egcs 1.1.1, -O2 -funroll-loops):
> > -rwxrwxr-x   1 hercules devel     1534443 Mar 25  1999 robotcom.so
> > 
> > The VC++ version (compiled with VC++ 5.0, /G5 /Ox /Ot /Og /Oi /Op /Ob2)
> > -r-xr-xr-x   1 hercules devel      654336 Mar 14 10:26 robotcom.dll
> > 
> > Any ideas why this might be? 

> Did you try to apply 'strip.exe' to the resulting binary?

Yup, it's on Linux, so we used 'strip', but it only cut about a hundred K
off of it.  (It wasn't compiled with -g)

	-Sam Lantinga				(slouken@devolution.com)

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

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: Large code size?
       [not found] ` < E10PrbT-0003Og-00@roboto.devolution.com >
  1999-03-24 13:29   ` David B. Rees
@ 1999-03-24 13:38   ` Martin v. Loewis
  1999-03-31 23:46     ` Martin v. Loewis
  1 sibling, 1 reply; 56+ messages in thread
From: Martin v. Loewis @ 1999-03-24 13:38 UTC (permalink / raw)
  To: slouken; +Cc: egcs, hercules, slouken

> The egcs version (compiled with egcs 1.1.1, -O2 -funroll-loops):
> -rwxrwxr-x   1 hercules devel     1534443 Mar 25  1999 robotcom.so
> 
> The VC++ version (compiled with VC++ 5.0, /G5 /Ox /Ot /Og /Oi /Op /Ob2)
> -r-xr-xr-x   1 hercules devel      654336 Mar 14 10:26 robotcom.dll
> 
> Any ideas why this might be? 

Did you try to apply 'strip.exe' to the resulting binary?

Regards,
Martin

^ permalink raw reply	[flat|nested] 56+ messages in thread

* RE: Large code size?
       [not found] ` < E10PrbT-0003Og-00@roboto.devolution.com >
@ 1999-03-24 13:29   ` David B. Rees
  1999-03-31 23:46     ` David B. Rees
  1999-03-24 13:38   ` Martin v. Loewis
  1 sibling, 1 reply; 56+ messages in thread
From: David B. Rees @ 1999-03-24 13:29 UTC (permalink / raw)
  To: Sam Lantinga; +Cc: egcs

On 24-Mar-99 Sam Lantinga wrote:
> I'm comparing code size of an application compiled with VC++ and with egcs,
> 1.1.1 and the VC++ binary is smaller than the egcs binary by an almost exact
> factor of two.  The code being compared is self-contained, i.e. it calls no
> library routines internally, and is pretty hairy C++ template code.
> 
> The egcs version (compiled with egcs 1.1.1, -O2 -funroll-loops):
> -rwxrwxr-x   1 hercules devel     1534443 Mar 25  1999 robotcom.so
> 
> The VC++ version (compiled with VC++ 5.0, /G5 /Ox /Ot /Og /Oi /Op /Ob2)
> -r-xr-xr-x   1 hercules devel      654336 Mar 14 10:26 robotcom.dll
> 
> Any ideas why this might be?  The same ratio is true for the main
> application, which is 13 MB on Linux, and 6 MB on Windows.  7 MB
> of difference makes a significant impact on performance, and our
> application compares poorly to the Windows version.  We'd like it
> to compare favorably. :)
> 
> Your thoughts, O Gurus? :)

Did you try running strip on the library?  Also, compiling with the flag -Os
should optimize the code for size, instead of speed.

-Dave

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Large code size?
@ 1999-03-24  9:38 Sam Lantinga
       [not found] ` < E10PrbT-0003Og-00@roboto.devolution.com >
  1999-03-31 23:46 ` Sam Lantinga
  0 siblings, 2 replies; 56+ messages in thread
From: Sam Lantinga @ 1999-03-24  9:38 UTC (permalink / raw)
  To: egcs; +Cc: hercules, slouken

I'm comparing code size of an application compiled with VC++ and with egcs,
1.1.1 and the VC++ binary is smaller than the egcs binary by an almost exact
factor of two.  The code being compared is self-contained, i.e. it calls no
library routines internally, and is pretty hairy C++ template code.

The egcs version (compiled with egcs 1.1.1, -O2 -funroll-loops):
-rwxrwxr-x   1 hercules devel     1534443 Mar 25  1999 robotcom.so

The VC++ version (compiled with VC++ 5.0, /G5 /Ox /Ot /Og /Oi /Op /Ob2)
-r-xr-xr-x   1 hercules devel      654336 Mar 14 10:26 robotcom.dll

Any ideas why this might be?  The same ratio is true for the main
application, which is 13 MB on Linux, and 6 MB on Windows.  7 MB
of difference makes a significant impact on performance, and our
application compares poorly to the Windows version.  We'd like it
to compare favorably. :)

Your thoughts, O Gurus? :)

	-Sam Lantinga				(slouken@devolution.com)

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

^ permalink raw reply	[flat|nested] 56+ messages in thread

end of thread, other threads:[~1999-03-31 23:46 UTC | newest]

Thread overview: 56+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-03-24 17:57 Large code size? N8TM
1999-03-31 23:46 ` N8TM
  -- strict thread matches above, loose matches on Subject: below --
1999-03-25  9:49 Sam Lantinga
     [not found] ` < E10QEFo-0002NA-00@roboto.devolution.com >
1999-03-25 10:14   ` H.J. Lu
1999-03-31 23:46     ` H.J. Lu
1999-03-31 23:46 ` Sam Lantinga
1999-03-25  9:48 Sam Lantinga
1999-03-25 11:24 ` Jason Merrill
1999-03-31 23:46   ` Jason Merrill
1999-03-31 23:46 ` Sam Lantinga
1999-03-24 16:47 Sam Lantinga
1999-03-31 23:46 ` Sam Lantinga
1999-03-24 16:34 Mike Stump
1999-03-31 23:46 ` Mike Stump
1999-03-24 16:28 Sam Lantinga
     [not found] ` < E10Py0p-0001gL-00@roboto.devolution.com >
1999-03-24 16:45   ` Joe Buck
1999-03-31 23:46     ` Joe Buck
1999-03-31 23:46 ` Sam Lantinga
1999-03-24 15:42 Sam Lantinga
     [not found] ` < E10PxHr-0001fO-00@roboto.devolution.com >
1999-03-24 15:54   ` Joe Buck
     [not found]     ` < 199903242353.PAA02719@atrus.synopsys.com >
1999-03-24 23:22       ` Martin v. Loewis
1999-03-31 23:46         ` Martin v. Loewis
1999-03-31 23:46     ` Joe Buck
1999-03-24 17:07   ` H.J. Lu
     [not found]     ` < m10PycJ-000ErMC@ocean.lucon.org >
1999-03-25  5:04       ` Nick Ing-Simmons
1999-03-31 23:46         ` Nick Ing-Simmons
1999-03-31 23:46     ` H.J. Lu
     [not found] ` <199903242353.PAA02719.cygnus.egcs@atrus.synopsys.com>
1999-03-25  1:08   ` Jason Merrill
1999-03-25  8:28     ` Andi Kleen
1999-03-31 23:46       ` Andi Kleen
     [not found]     ` < u9n212vswe.fsf@yorick.cygnus.com >
1999-03-25 14:35       ` Martin v. Loewis
1999-03-31 23:46         ` Martin v. Loewis
1999-03-31 23:46     ` Jason Merrill
1999-03-31 23:46 ` Sam Lantinga
1999-03-24 15:05 Sam Lantinga
     [not found] ` < E10PwfK-0001bs-00@roboto.devolution.com >
1999-03-24 23:26   ` Martin v. Loewis
1999-03-31 23:46     ` Martin v. Loewis
1999-03-24 23:35   ` Martin v. Loewis
1999-03-31 23:46     ` Martin v. Loewis
1999-03-31 23:46 ` Sam Lantinga
     [not found] <E10PwA2-0001UN-00@roboto.devolution.com>
1999-03-24 14:42 ` Martin von Loewis
1999-03-24 14:49   ` Dima Volodin
1999-03-31 23:46     ` Dima Volodin
1999-03-31 23:46   ` Martin von Loewis
1999-03-24 13:52 Sam Lantinga
     [not found] ` < E10PvY5-0001NJ-00@roboto.devolution.com >
1999-03-24 14:10   ` Martin v. Loewis
1999-03-31 23:46     ` Martin v. Loewis
1999-03-24 15:18   ` H.J. Lu
1999-03-31 23:46     ` H.J. Lu
1999-03-31 23:46 ` Sam Lantinga
1999-03-24  9:38 Sam Lantinga
     [not found] ` < E10PrbT-0003Og-00@roboto.devolution.com >
1999-03-24 13:29   ` David B. Rees
1999-03-31 23:46     ` David B. Rees
1999-03-24 13:38   ` Martin v. Loewis
1999-03-31 23:46     ` Martin v. Loewis
1999-03-31 23:46 ` Sam Lantinga

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).