Path: utzoo!utgpu!cunews!bnrgate!brtph3!brchh104!brchs1!bnr.ca!rice.edu!sun-spots-request From: casper@fwi.uva.nl (Casper H.S. Dik) Newsgroups: comp.sys.sun Subject: IMPORTANT: SunOS Shared library caveat. Keywords: Miscellaneous Message-ID: <2469@brchh104.bnr.ca> Date: 17 Apr 91 01:00:00 GMT Sender: news@brchh104.bnr.ca Organization: Sun-Spots Lines: 53 Approved: Sun-Spots@rice.edu X-Original-Date: Thu, 11 Apr 91 08:02:36 GMT X-Sun-Spots-Digest: Volume 10, Issue 81, message 8 X-Note: Submissions: sun-spots@rice.edu, Admin: sun-spots-request@rice.edu 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.sa.. In turns out that a libc.sa. of exactly the same 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. 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. (and to libc.so.!) 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