[comp.sys.sun] IMPORTANT: SunOS Shared library caveat.

casper@fwi.uva.nl (Casper H.S. Dik) (04/17/91)

The folllowing is of interest to people who change their libc.so* or
develop shared libraries.

Recently, one of our users complained that a dynamically linked tcsh or
xterm used much more (200k) swap space than a statically linked one.

Some digging in the address space of those processes revealed that a
dynamically linked tcsh/xterm did not share the text portion of the
executable.

This happens because not all references to initialized data are resolved
at link time. This leaves some resolving to be done at execution time, the
result being that the entire text portion is no longer shared.

This happens when not all external data from the library referenced by the
program is present in lib<NAME>.sa.<REV>.

In turns out that a libc.sa.<REV> of exactly the same <REV> as the highest
numbered libc.so.* must exist.  Only then all references to data exported
by libc will be resolved at link time. 

IMPORTANT: If you build a shared libc (say libc.so.1.5.1) with e.g.  the
resolver you must also create a libc.sa.1.5.1 or all% binaries linked
after installation of that library will have an unshared text portion%%.
This would defeat one of the most important purposes of shared libraries:
reduced VM usage, for all executables running more than once on the same
CPU.

[E.g.: cp libc.sa.1.5 libc.sa.1.5.1; ranlib libc.sa.1.5.1]

In case of the resolver library, you might want to add the definition (and
initialisation!) of struct state _res to libc.sa.<REV> If you have the
source, you can get the defintion from res_init.c.  If you use the object
files from libresolv.a, you can add res_init.o to libc.sa.<REV> (and to
libc.so.<REV>!)

The sad part is that the X11R4 shared libraries contain hardly any of the
data used by many X programs. This means that the X libraries must be
changed to get proper sharing of X program text images.  Best thing to do
is to link xterm statically. (Saves you approx 250k swap space per xterm)

% Actually only those programs that use data from the library.
  But this includes all programs that use e.g. errno, stdio, ctype.

%% The resulting executable is still ZMAGIC (demand paged). The runtime
   linker, ld.so, changes the protection of the text segment from r-x
   to rwx, does it dirty work, and reprotects the segment.

Casper Dik.

JANET:						|	Casper H.S. Dik
      The English Network - Another Joke	|	casper@fwi.uva.nl
						|	NIC: !cd151