comp.lang.ada
 help / color / mirror / Atom feed
From: "Steven Deller" <deller@smsail.com>
Subject: RE: Why is memory footprint smaller when compiled static?
Date: Wed, 5 Jun 2002 19:02:30 -0500
Date: 2002-06-05T19:02:30-05:00	[thread overview]
Message-ID: <mailman.1023321903.7863.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: <slrnafs1dn.aa1.randhol+abuse@kiuk0152.chembio.ntnu.no>

Preben,
When you link with a shared library, everything in that shared library
is loaded when it is loaded.  Everything, not just what you need.

When you link statically, just what you need/use is included.  One
caveat -- libraries, whether C or Ada, come in chunks (called object
files) that often include many routines, so you get all of them even
when you just want one.  Normally linkers can't do "dead code
elimination", though some are getting almost smart enough to do that.

In your case, there are lots of parts of I/O and Ada that you are not
using, so when you link statically, much of the library's contents are
not included in the executable.

One other caveat -- just looking at an executable, even a stripped
executable, does NOT tell you how much code you have.  The executable
file includes "text" which is read-only instructions and data, "data"
which is initialized read-write data, "bss" which defines how much
uninitialized data space the program has, as well as original detailed
object file symbols, debugging symbol information, and loading symbol
table information.  If you "strip" the file, that removes the debugging
and object file symbols.

There is also overhead in an executable file that defines the structure
of the file, but usually that is under 15KB.

Check the program "size" to look in more detail about the parts that
comprise an executable file.

Even after stripping there can be significant symbol table information
included, needed for relocatable loading on most machines.  That can
make the executable file much larger than what eventually runs in
memory.  On the other hand, "bss" only takes a few words to "reserve"
all data space -- if you have huge arrays that are statically defined,
but aren't initialized, then the image in memory can be much larger than
the file.

Finally, during execution, programs use stack space (usually not much)
and heap space (can often be a lot).  On the embedded system project I
am working on, file sizes reach 33MB or more, while text, data, and bss
only sum to about 14MB.  Even after stripping, the file size is about
19MB.  I have a super-strip that strips the loading symbol table as well
(since the target loader does not use that), and I get a 13MB file
image.  When the program runs, it takes about 24MB because it uses
almost 10MB of heap.

Regards,
Steve

> -----Original Message-----
> From: comp.lang.ada-admin@ada.eu.org 
> [mailto:comp.lang.ada-admin@ada.eu.org] On Behalf Of Preben Randhol
> Sent: Wednesday, June 05, 2002 7:37 AM
> To: comp.lang.ada@ada.eu.org
> Subject: Re: Why is memory footprint smaller when compiled static?

I was only curious why the memory usage seems to drop 1 Mb after
compiling the program as static rather than shared. I don't care so much
how much memory my program takes, I just wanted to learn something about
this.

Preben Randhol
_______________________________________________
comp.lang.ada mailing list
comp.lang.ada@ada.eu.org
http://ada.eu.org/mailman/listinfo/comp.lang.ada




  parent reply	other threads:[~2002-06-06  0:02 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-05 11:37 Why is memory footprint smaller when compiled static? Grein, Christoph
2002-06-05 12:36 ` Preben Randhol
2002-06-05 13:42   ` Mark Johnson
2002-06-06  0:02   ` Steven Deller [this message]
2002-06-06 10:35     ` Preben Randhol
2002-06-06 14:26     ` Gautier
2002-06-06 15:08       ` Jean-Marc Bourguet
2002-06-06 15:24         ` Jean-Pierre Rosen
2002-06-06 19:35           ` Jeffrey Carter
2002-06-10 23:51     ` Randy Brukardt
2002-06-11  0:53       ` Robert A Duff
2002-06-11 16:45         ` Wes Groleau
2002-06-11 17:08           ` Preben Randhol
2002-06-11 19:12             ` Wes Groleau
2002-06-11 21:38               ` Randy Brukardt
2002-06-11 21:32         ` Randy Brukardt
  -- strict thread matches above, loose matches on Subject: below --
2002-06-04 15:14 Preben Randhol
2002-06-04 16:13 ` Mark Johnson
2002-06-04 21:01 ` Florian Weimer
2002-06-04 21:02 ` Florian Weimer
2002-06-04 21:03 ` Florian Weimer
2002-06-05 11:10   ` Preben Randhol
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox