rick@pcrat.uucp (Rick Richardson) (06/01/90)
I recently had to reinstall the development system libraries from INTERACTIVE 386/ix 2.0.2, and this reminded me of an important tip for software developers that ought to be passed on. First, some background info: ---------------------------- COFF files have a comment section which eliminates the need to put char sccsid[] = "@(#) ..." in the .data of your program. Instead, this info is just carried around in the COFF file but never loaded into the address space. The "#ident" cpp directive and the "mcs" command are used to add this information to a COFF file. Now, some reality: ------------------ Nearly all of the common include files, such as <stdio.h> have #ident lines in them. This means that any program you compile will have COFF commentary in it, even if you don't explicitly put some in. But, worse, some of the major libraries, such as libc.a, libcurses.a, libX11.a (et al), have massive amounts of commentary. This stuff adds up. In some cases, I found that nearly *50,000* bytes of COFF commentary were present in some of these libraries, and that (especially with X11 and curses) most of this will also end up in *your* program if you don't take steps to prevent this. Check your libraries and binaries for the amount of COFF commentary: mcs -p XXX | wc -c Next, some suggestions: ----------------------- 1) Get rid of the commentary in the "standard" libraries. It just wastes space on your disk, and unless you are beta testing a new development system, it suffices to know that you loaded against Dev. Sys. 1.0 (or whatever). For each library you want to shrink, do this: mcs -d libXXX.a ar ts libXXX.a 2) Get rid of the boilerplate commentary in your object files. You have (at least) three options (XXX is a final binary, XXX.o is a component object file, $(MCS)=mcs in this discussion): 2a) Get rid of it all, including your own commentary. Run this command (from your makefile!): $(CC) $(OBJS) -o XXX $(MCS) -d XXX 2b) Get rid of commentary from #ident lines in standard headers, but retain your own #ident comentary: Edit each standard header (yecch!) Comment out or delete #ident lines 2c) Get rid of commentary from all #ident lines, but add your own new commentary using "mcs". To do this conveniently, it is easiest to change the ".c.o" (and similar) rules in your makefile: .c.o: $(CC) $(CFLAGS) -c $*.c $(MCS) -d -a "`stamp $*.c`" $*.o "stamp" is a little program we use which prints "@(#)" followed by the *external* release number (which usually has no correspondence to SCCS or RCS rev numbers) followed by the internal rev # of the source file and date of the source file). We also add a comment to the final binary: $(CC) $(OBJS) -o XXX $(MCS) -a "$(COPYRIGHT)" XXX Finally, the (Usenet) obligatory complaint or showing of ignorance: ------------------------------------------------------------------- There should be two options to cpp to control #ident lines: a) Ignore *all* #ident lines b) Ignore #ident lines in header files included with the <header.h> syntax. This latter option would be most useful, since it allows you to not include #ident lines from "standard" (e.g. stable) software, while retaining the automatic #ident lines which RCS or SCCS generates for your software. -Rick -- Rick Richardson | Looking for FAX software for UNIX/386 ??? Ask About: |Mention PC Research,Inc.| FaxiX - UNIX Facsimile System (tm) |FAX# for uunet!pcrat!rick| FaxJet - HP LJ PCL to FAX (Send WP,Word,Pagemaker...)|Sample (201) 389-8963 | JetRoff - troff postprocessor for HP LaserJet and FAX|Output
ndjc@hobbit.UUCP (Nick Crossley) (06/05/90)
In article <1990Jun1.134459.4296@pcrat.uucp> rick@pcrat.uucp
(Rick_Richardson) writes much about COFF .comment sections, and
how to reduce their size.
I don't think this is particularly relevant to this newsgroup, as
.comment sections are nothing to do with C, but are part of both
the COFF and ELF (V.4) object formats (perhaps further discussion
should be in comp.unix.questions?).
However, he did miss out perhaps the most important and simple way
to limit the size of .comment sections; use of mcs -c. Rather than
just delete the comment sections (which the software developers
and OS suppliers might make good use of for support), just insure
that each comment is included only once. If a header file contains
a #ident, that string will appear in the binary as many times as
that header file was included (plus or minus a few depending on
whether or not the header was included in the same source more than
once and whether or not the #ident was inside or outside any #ifndef
__XXX_H_ ... #endif stuff). For common header files such as
<stdio.h>, this can mean the same strings will appear many times
in a fully linked binary.
Use of mcs -c will condense the .comment section so that each unique
string appears only once. Makefiles intended for systems with
.comment sections (such as V.3 and V.4) should have mcs -c <binary>
added after final linking.
--
<<< standard disclaimers >>>
Nick Crossley, ICL NA, 9801 Muirlands, Irvine, CA 92718-2521, USA 714-458-7282
uunet!ccicpg!ndjc / ndjc@ccicpg.UUCP