Subject: Re: Question about text segments and NetBSD and Solaris 2
To: Brian Buhrow <firstname.lastname@example.org>
From: David Edelsohn <email@example.com>
Date: 07/25/1997 14:08:13
>>>>> Brian Buhrow writes:
Brian> The question is: If an executable is linked statically, if multiple
Brian> instances are running, are there multiple instances of the text segment for
Brian> that executable in memory at once? In other words, is the OS smart enough
Brian> to know that multiple instances of a given executable can share their text
Brian> segments even if those text segments don't rely on shared objects?
Brian> If people know the anser for various OS's, including: SunOS 4.x and
Brian> 5.x, Linux, NetBSD, OSF1, etc. I'd be most appreciative.
Static linkage does not affect this, but other rarely used link
options and executable "magic numbers" do. Modern UNIX executables have
read-only text segments which UNIX operating systems know are shareable
The early executable format (OMAGIC) did not have text and data
separated and would not allow sharing. The next revision (NMAGIC) had a
read-only text segment allowing sharing, but the entire application was
loaded into memory and swapped to disk (drum) swapspace as a whole.
Later, demand paged executable (ZMAGIC) was introduced which allowed the
text segment to be paged from the original executable and allowed
executables to be faulted into memory on a page by page basis instead of
swapping the entire application.
I believe that all modern UNIX systems use ZMAGIC or a variant.
All of the systems you mention provide that functionality. One must use
linker options -N (OMAGIC) and -n (NMAGIC) to produce the old forms, if
even available on a particular system. -N was necessary even after ZMAGIC
was introduced to perform runtime loading and overlays prior to dynamic
linking and PIC.
Dynamic linking actually takes text sharing a step further by
allowing libraries common to executables to be shared among all
executables using them although the application itself is completely
different. Text sharing only allows the text segment of a single
applications to be shared. A statically linked executable may have libc
in common with other executables, but it will have its own copy of libc,
and other libraries, paged from the text segment of its executable instead
of the common dynamically linked library for the system.
David Edelsohn T.J. Watson Research Center
firstname.lastname@example.org P.O. Box 218
+1 914 945 4364 (TL 862) Yorktown Heights, NY 10598