From: Geoff Collyer <geoff@collyer.net> To: 9fans Subject: Virtual memory & paging Date: Mon, 4 Feb 2002 02:38:16 -0800 There isn't a copy of the entire C library in every binary. There is a copy of each library routine called, directly or indirectly, by the program in question. Sharing of instructions is done at the granularity of process text segments, as in V6 or V7 Unix. The text segment of a process that forks is shared between parent and child by page mapping. Also, running (via exec) a program multiple times concurrently causes the (pure) text segment to be shared by page mapping across those processes. So all copies of rc and on a machine should share a text segment. Given that degree of sharing, the low cost of RAM, and the increase in OS complexity, slowness and insecurity in the implementations of dynamic libraries that I've seen, I don't see a need for dynamic libraries. (Remember that the real impetus for adding them to Unix was X11 and its big and badly-factored libraries, which most of us aren't blessed with.) My terminal has 115 processes; all but 4 of them share their text segment with at least one other process, usually more. 74 of them are instances of rio, Mail, rc, acme, listen, plumber and samterm. A CPU server has 141 processes; all but 2 share text. 80 of them are listen, another 21 are rc, exportfs, kfs, dns and consolefs. A quick sampling suggests that Plan 9 programs are typically smaller than FreeBSD/386 programs even with shared libraries. Here are some FreeBSD sizes: : unix; size /bin/cat /bin/ed /usr/bin/awk /usr/X11/bin/sam text data bss dec hex filename 54188 4324 9760 68272 10ab0 /bin/cat 122835 8772 81920 213527 34217 /bin/ed 135761 4772 15756 156289 26281 /usr/bin/awk 52525 1412 53448 107385 1a379 /usr/X11/bin/sam Of those, awk and sam use shared libraries. The corresponding Plan 9 sizes are: ; cd /bin; size cat ed awk sam 15996t + 2208d + 944b = 19148 cat 45964t + 4212d + 41232b = 91408 ed 114731t + 35660d + 12040b = 162431 awk 86574t + 7800d + 66240b = 160614 sam and the Plan 9 programs cope with Unicode and UTF.
<btdn> I never, for the life of me, understand why people like dynamic linking. <aiju> btdn: for the very same reason they believe in god
vadaszi:
I request dlopen() to be added to the 'harmful' list, since it breaks the assumptions of static linking (e.g. you expect the binary to be portable across linux distributions, but by using dlopen() some weird assertion break the binary when using a differeng glibc version). Happened to me when using the ghc haskell compiler, even statically linked binaries won't work across linux distributions or glibc versions.
ldd
arbitrary code execution - One of the many security issues created by dynamic linking in Unix, explained by Peteris Krumins.