From xemacs-m  Fri May 23 17:56:37 1997
Received: from mercury.Sun.COM (mercury.Sun.COM [192.9.25.1])
	by xemacs.org (8.8.5/8.8.5) with SMTP id RAA17994
	for <xemacs-beta@xemacs.org>; Fri, 23 May 1997 17:56:37 -0500 (CDT)
Received: from Canada.Sun.COM ([129.155.5.101]) by mercury.Sun.COM (SMI-8.6/mail.byaddr) with SMTP id QAA24594 for <xemacs-beta@xemacs.org>; Fri, 23 May 1997 16:11:53 -0700
Received: from scooter.canada.sun.com by Canada.Sun.COM (SMI-8.6/SMI-5.3)
	id SAA15707; Fri, 23 May 1997 18:55:49 -0400
Received: from verve.canada.sun.com by scooter.canada.sun.com (SMI-8.6/SMI-SVR4)
	id SAA20148; Fri, 23 May 1997 18:56:03 -0400
Received: by verve.canada.sun.com (SMI-8.6/SMI-SVR4)
	id SAA01572; Fri, 23 May 1997 18:56:06 -0400
Date: Fri, 23 May 1997 18:56:06 -0400
Message-Id: <199705232256.SAA01572@verve.canada.sun.com>
From: Georg Nikodym <georgn@Canada.Sun.COM>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
To: Martin Buchholz <mrb@Eng.Sun.COM>
Cc: georgn@Canada.Sun.COM, XEmacs Developers <xemacs-beta@xemacs.org>,
        georg.nikodym@Canada.Sun.COM
Subject: Re: b1 success
In-Reply-To: <199705220251.TAA16746@xemacs.eng.sun.com>
References: <199705191905.PAA19737@verve.canada.sun.com>
	<199705200034.RAA12761@xemacs.eng.sun.com>
	<199705211433.KAA17537@verve.canada.sun.com>
	<199705220251.TAA16746@xemacs.eng.sun.com>
X-Mailer: VM 6.31 under 20.3 XEmacs Lucid (beta2)
Reply-To: georgn@Canada.Sun.COM
X-Face:  ,~EI@l7'&P{\d++e`EMjNTNpzsxJPg(H]?Sd_T3xIlq[(PT[.D;A_/k)qfeC@m\/1]A{vZD
 r4&Lme-/M]c'Q>>:VM|L^<ED=j@dG!ld,bQ:IhT53q'x>6wZKH3iCT6Ff1-`*z{vCiT}+%(irA6TOn
 S~pFtml1bL\=kp%0PsLcF3+Q/e${o|S/<NUFDrU@;^o(D+av1g>Ce=ztlPGb$?up%c-*l'wmjw\sw;
 D__0Z;+93I+Kx6Mxdc]+|2V03aE@D8-fMT_v[~~FC9I\*|72QVW,aQ!`hHp_.gE.W&kxla2#)\Cmo

>>>>> "MB" == Martin Buchholz <mrb@Eng> writes:

 MB> Shouldn't the linker take care of making the overhead be
 MB> link-time only?  If I link with a library and use none of its
 MB> symbols, should the resulting binary even have a reference to
 MB> that useless library?

This is only true in the case of static linking where the linker is
responsible for COPYING .o's it extracts from .a's into the output
binary.

In dynamic linking (of an app), all that needs to happen is a check
that all the dependencies are met by the collection of shared objects
supplied as arguments to the link editor.  Remember, in dynamic linked 
apps the shared objects are mapped into the apps address space, there
is no dismembering going on.

Consider the classic hello world program.  It has, as far as the coder
is concerned one dependency, printf().  C on UNIX semantics supply an
implied dependency on exit(), which in turn depends on atexit() and
_exit().  Total four direct dependencies.  When built on Solaris, the
classic program ends up with 21 dependencies in total.  The additional 
17 symbols come from the guts of printf() and friends (libc depending
on libc).

However, add "-lX11 -lXm -lm -lelf -ldl" to the compile line of
hello world and things change radically.  ldd shows:

	libX11.so.4 =>	 /usr/lib/libX11.so.4
	libXm.so.3 =>	 /usr/lib/libXm.so.3
	libm.so.1 =>	 /usr/lib/libm.so.1
	libelf.so.1 =>	 /usr/lib/libelf.so.1
	libdl.so.1 =>	 /usr/lib/libdl.so.1
	libc.so.1 =>	 /usr/lib/libc.so.1
	libXext.so.0 =>	 /usr/openwin/lib/libXext.so.0
	libsocket.so.1 =>	 /usr/lib/libsocket.so.1
	libnsl.so.1 =>	 /usr/lib/libnsl.so.1
	libXt.so.4 =>	 /usr/openwin/lib/libXt.so.4
	libmp.so.2 =>	 /usr/lib/libmp.so.2
	libSM.so.6 =>	 /usr/openwin/lib/libSM.so.6
	libICE.so.6 =>	 /usr/openwin/lib/libICE.so.6

The total number of direct dependencies remains four (obviously) but
the total number of symbol dependencies leaps to 2965.

I added a pause() call so that I could examine the address space
(/usr/proc/bin/pmap is the tool y'all can use):

Minimal:

1554:	./temp
00010000      8K read/exec         dev:172,2 ino:580999
00020000      8K read/write/exec   dev:172,2 ino:580999
EF6E0000     16K read/exec         /usr/platform/sun4u/lib/libc_psr.so.1
EF700000    584K read/exec         /usr/lib/libc.so.1
EF7A0000     32K read/write/exec   /usr/lib/libc.so.1
EF7A8000      8K read/write/exec     [ anon ]
EF7B0000      8K read/exec/shared  /usr/lib/libdl.so.1
EF7C0000    112K read/exec         /usr/lib/ld.so.1
EF7EA000     16K read/write/exec   /usr/lib/ld.so.1
EFFFC000     16K read/write/exec     [ stack ]
 total      808K

Pathological example:

1549:	./temp
00010000      8K read/exec         dev:172,2 ino:580999
00020000      8K read/write/exec   dev:172,2 ino:580999
EF260000     72K read/exec         /usr/openwin/lib/libICE.so.6
EF280000      8K read/write/exec   /usr/openwin/lib/libICE.so.6
EF282000      8K read/write/exec     [ anon ]
EF290000    328K read/exec         /usr/openwin/lib/libXt.so.4
EF2F0000     24K read/write/exec   /usr/openwin/lib/libXt.so.4
EF2F6000      8K read/write/exec     [ anon ]
EF300000    448K read/exec         /usr/lib/libnsl.so.1
EF37E000     32K read/write/exec   /usr/lib/libnsl.so.1
EF386000     24K read/write/exec     [ anon ]
EF3A0000     32K read/exec         /usr/openwin/lib/libSM.so.6
EF3B6000     16K read/write/exec   /usr/openwin/lib/libSM.so.6
EF3C0000     16K read/exec         /usr/lib/libmp.so.2
EF3D2000      8K read/write/exec   /usr/lib/libmp.so.2
EF3E0000     32K read/exec         /usr/lib/libsocket.so.1
EF3F6000      8K read/write/exec   /usr/lib/libsocket.so.1
EF3F8000      8K read/write/exec     [ anon ]
EF400000    584K read/exec         /usr/lib/libc.so.1
EF4A0000     32K read/write/exec   /usr/lib/libc.so.1
EF4A8000      8K read/write/exec     [ anon ]
EF4C0000     16K read/exec         /usr/platform/sun4u/lib/libc_psr.so.1
EF4D0000     72K read/exec         /usr/openwin/lib/libXext.so.0
EF4F0000      8K read/write/exec   /usr/openwin/lib/libXext.so.0
EF500000   1440K read/exec         /usr/dt/lib/libXm.so.3
EF676000     72K read/write/exec   /usr/dt/lib/libXm.so.3
EF688000      8K read/write/exec     [ anon ]
EF6A0000     64K read/exec         /usr/lib/libelf.so.1
EF6BE000      8K read/write/exec   /usr/lib/libelf.so.1
EF6D0000     88K read/exec         /usr/lib/libm.so.1
EF6F4000      8K read/write/exec   /usr/lib/libm.so.1
EF700000    432K read/exec         /usr/openwin/lib/libX11.so.4
EF77A000     24K read/write/exec   /usr/openwin/lib/libX11.so.4
EF790000      8K read/write/exec     [ anon ]
EF7B0000      8K read/exec/shared  /usr/lib/libdl.so.1
EF7C0000    112K read/exec         /usr/lib/ld.so.1
EF7EA000     16K read/write/exec   /usr/lib/ld.so.1
EFFFC000     16K read/write/exec     [ stack ]
 total     4112K

