[comp.sys.sgi] Saving megabytes of disk space

david@horizon.kai.com (David Nelson) (08/30/89)

We've been having fun trying to build a rather LARGE library on our
4D. The library of all of the objects in our development system is
just under 15 megabytes on our Sequent Symmetry (intel 80386 based),
but was well over 38 megabytes on the 4D. There is only so much one
can explain away by RISC, and the many headers in the Mips symbol
table.

It turns out that the Mips compiler does not remove external symbols
that are declared but never used. The whole symbol table is written to
the object file. Now we have this package of 900+ "capability" switches
that almost every file includes, and usually only a few of the switches
are actually used in each file. We also use nice long descriptive names
for each switch so when the source code is translated to C, 98% end up
being 31 characters long. (The translator hashes all names longer than
31 chars down to that limit.) 

Now for the estimate, a symbol takes:
        12 bytes for the symbol structure
      + strlen(name)+1 bytes of string space (usually 32 bytes)
        ----------
        44 bytes
so for 450+ files, 900+ symbols, each taking up around 44 bytes
thats . . . 17,820,000+ bytes just for the "capability" switches!

Now that I have a handle on the size (of the) problem, what can one do
to eliminate it. Our system manager gave me the number of the Hotline to
see if they could help. They were not able to provide a solution that
day, but they told me they would look into it. The next business day, I
got a call back that "ld -r" was my answer. When ld writes out the new
symbol table it does not write out unused external symbols.

I wrote a simple shell script to process each of the object files with
ld and then rebuild the library. It turns out that library is now well
under 20M. (BTW, the executable image is about 11M and when we take out
checks, debug code, other code not related to this particular version of
the product and strip the executable, it is only about 1.5M.)  We saved
18,677,648 bytes on the library and an equal amount on the object files.
Not the mention the same amount we would need to have free on the TMPDIR
file system while the library is being rebuilt.

I'm quite pleased with the response from the Hotline, now if Mips would
make this an option on the C compiler . . .

#include <std/disclaimer.h>

David Nelson               UUCP:      ...!uunet!uiucuxc!kailand!dnelson
Kuck and Associates, Inc.  Internet:  dnelson@kai.com 
1906 Fox Drive
Champaign, Ill. 61820      Optimizing software for supercomputers