Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: rhill@dale.ksc.nasa.gov (Russ Hill)
Subject: DYNAMICALLY LINKING SHARED LIBRARIES?
Date: Wed, 21 Oct 1992 12:41:29 GMT	[thread overview]
Message-ID: <1992Oct21.124129.6101@dale.ksc.nasa.gov> (raw)


I've been trying to dynamically share libraries such as (but not
neccessarily) stdio at runtime.  Suppose two processes use the
resources of a library.  Under normal circumstances, this library is
linked to each of the two programs at compile time.  After the
link-load phase, we end up with two programs, each containing a copy
of the same library.  Notice that there is some redundancy here.  If
both programs are running, two copies of the libraries are in memory
at the same time.  This wastes valuable memory and disk space.
Performance is also affected because of potential page faults.

My idea, although not new, is to create a library maintainer process
which loads libraries into and out of memory.  Running processes would
then call a simple function:

LibBase = OpenLibrary ("LibName");
   /* normal program goes here */
CloseLibrary (LibBase);

to gain or relinquish access to a library.  The Librarian is
responsible for creating a shared memory segment, copying the library
into the shared memory, and returning the base address of the library
to the calling process.  When the process is finished with the
library, it calls CloseLibrary(), which sends a message to the
Librarian to remove the library and deallocate the memory if no one
else is using it.

In order to do this, I have decided that I first should try to
dynamically link a library to a process at runtime.  Here's the steps
that I'm taking:

1. Compile the library functions into object code:
   cc -c *.c

2. link together all of the library functions:
   ld -o sharedlib *.o

3. create a dummy library with all of the global data and functions
   defined at the correct addresses and without any code or data
   defined: 
   nm sharedlib | egrep -e 'T|D' | awk '{printf ".globl %s\n%s = \
       %s\n", $3, $3, $1}' > dummy.a
   as -o dummy.o dummy.a
   ar q dummylib dummy.o

4. link the dummy library to the executable program as usual.  This
   program should open the file containing the real library and use
   the system call mmap () to map a virtual address to the library.
   This should all be performed before any calls to the library take
   place.

I was able to get to step three with little difficulty.  However, I
could go no further than that.  Someone suggested that I use mmap ()
but I have had no success in learning what the call does and how it
would be used in this context.  Can anyone help me out?

Is there an easier way?
Is there any good documentation which covers this topic?

Thanks!



-- 

Russ Hill
rhill@dale.ksc.nasa.gov
(407) 633-3950


                 reply	other threads:[~1992-10-21 12:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox