From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,79b248c1cf206957 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-06-05 17:05:04 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fr.clara.net!heighliner.fr.clara.net!freenix!enst!enst.fr!not-for-mail From: "Steven Deller" Newsgroups: comp.lang.ada Subject: RE: Why is memory footprint smaller when compiled static? Date: Wed, 5 Jun 2002 19:02:30 -0500 Organization: Smooth Sailing LLC Sender: comp.lang.ada-admin@ada.eu.org Message-ID: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: avanie.enst.fr 1023321904 77319 137.194.161.2 (6 Jun 2002 00:05:04 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Thu, 6 Jun 2002 00:05:04 +0000 (UTC) Return-Path: X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 Importance: Normal In-Reply-To: X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.8 Precedence: bulk X-Reply-To: List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:25375 Date: 2002-06-05T19:02:30-05:00 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