Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Nov 2000 14:37:59 +0000
From:      Konstantin Chuguev <Konstantin.Chuguev@dante.org.uk>
To:        Peter Pentchev <roam@orbitel.bg>
Cc:        Dmitry Sychov <accelware@accelware.com>, hackers@FreeBSD.ORG
Subject:   Re: dlopen()
Message-ID:  <3A1D2BC7.65AB61AA@dante.org.uk>
References:  <001001c05552$45913f80$0e61bec3@dima> <3A1D1E52.95A9E626@dante.org.uk> <20001123154748.C7746@ringworld.oblivion.bg>

next in thread | previous in thread | raw e-mail | index | archive | help
Peter Pentchev wrote:

> > > Is it safe to remove the *.so file after it is loaded
> > > into the process space and addresses to its
> > > functions are gotten?
> >
> > It's safe to remove it as soon as it's been opened.
> > The file will still exist in the filesystem, only there won't be any
> > references to it from any directories, so you won't be able to open it
> > by its name. The file will be really removed from the file system when
> > you close your file descriptor.
>
> So the original poster's question is better translated as 'does the dynamic
> loader ever close and reopen a file after the initial loading, so it could
> accidentally open the new version of the library and use the old addresses'?
>
> I'd guess the answer is 'no' - the dynamic loader most probably opens
> the file once, and mmap()'s the needed functions; I might very well be wrong
> though.
>

This is how I think it works (don't have any FreeBSD box nearby):
For all dynamically loaded modules:
dlopen() opens the file (gets a file descriptor) and mmaps it (possibly
excluding the debug and some other sections). dlclose() unmaps and closes it.

For shared libraries:
__init() code of the binary executable dlopen()'s all the libraries, then goes
through the table of external symbols, lookups them with dlsym(RTLD_NOW) in the
libraries and replaces stub function pointers with the pointers to real
functions. The latter may be optimised somehow.
__fini() code dlclose()'s all the libraries.

But the best way is to look at the source code, of course ;-)

--
          * *        Konstantin Chuguev - Application Engineer
       *      *              Francis House, 112 Hills Road
     *                       Cambridge CB2 1PQ, United Kingdom
 D  A  N  T  E       WWW:    http://www.dante.net





To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3A1D2BC7.65AB61AA>