From: gerth@watson.ibm.com (John Gerth)
Subject: Re: Shared libraries and dynamic loading - again
Date: Wed, 07 Oct 1992 01:11:59 GMT
Disclaimer: This posting represents the poster's views, not necessarily those of IBM
Organization: IBM T.J. Watson Research Center

In article <1992Oct6.142457.14566@spss.com> brent@spss.com (Brent Lambert) writes:
>OK folks, I'm going to raise this subject again.
>
>Many implementations of UNIX share the loaded text segments of a
>running program among multiple invocations of the program.  In other
>words, if there are 5 instances of the C shell running simultaneously,
>all 5 instances are executing the same loaded image of the code.
>
>QUESTION 1:  Is this also true for AIX 3.2?
>
Yes, the read-only text is shared essentially by using a mapped copy
of the binary in all processes which 'exec' the file.  Of course
an static data areas will be unique to each process. 

>AIX shared objects are shared among multiple instances of multiple
>_different_ executables.  In other words, there is only 1 copy of
>libc.a in memory, and it is shared by all of the C programs that are
>running.  I know this is slightly simplified, but you get the point.
>
>Now suppose a program dynamically loads an object, like this:
>        load ("foo.o", 0, NULL)
>The information I have says that the object is loaded into the process
>private segment, unless it is a shared object and has permissions
>appropriate for sharing.
>
>QUESTION 2:  Does this literally mean that if foo.o is not shareable
>             then each process which loads foo.o gets its own copy in
>             memory, even if all the processes are instances of the
>             same executable?
>
Yes, you are interpreting it correctly.  The most important fact is
that the r/w statics of foo.o will be indpendent in each load().

>If so, then basically AIX allows dynamically loaded objects either to
>be shared (in memory) among all applications or not shared at all.
>What I really want is for it to be shared among all instances of a
>single executable.  Is this possible?
>
I take this to mean that if some binary, say "fred" is exec'ed and 
it loads "foo.o", then "foo.o" will be shared among any "fred" which
loads "foo.o" --- but if some other binary, say "sam" is exec'ed, then
if "sam" loads "foo.o", it would get a unique copy (at least among
all instances of "sam").  If the preceding is roughly accurate, I would
guess that that you can't just manipulate module attributes or file
permissions to achieve your objective and the reason I suspect this
to be true really has nothing to do itself with shared libraries, rather
it's the age-old *ix question of "what's in a name?", e.g. the quest
to reconstruct the absolute pathname of argv[0].  What I mean here
is that the system only knows that one "fred" is completely identical
with another "fred" if comes from exactly the same place in the file system
and here "exactly" means some internal system feature like an inode.
Since I know of nothing in AIX which ties objects to the inode of the
issuer of load(), I suspect you can't get this directly.  Of course,
there perhaps are ways for you to program the effect you desire using
other facilities.


-- 
John Gerth	 gerth@watson.ibm.com		(914) 784-7639