Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 Jun 1995 18:04:20 +0100 (BST)
From:      Doug Rabson <dfr@render.com>
To:        hackers@freebsd.org
Subject:   dlopen and friends
Message-ID:  <Pine.BSF.3.91.950616174554.291D@minnow.render.com>

next in thread | raw e-mail | index | archive | help
I have been mucking about with the latest snapshot of Fresco and have 
come up against a few problems with dlopen:

1. Only one layer of dependant libraries is loaded.  There is code which
would recursively load sub-dependants but it is broken and hence is 
commented out.

2. The manpage for dlopen specifies that _init will be called for newly
loaded libraries but dlopen actually looks up "_init"  which will end up
calling the user function init().  Is this correct?  I compiled a test 
library on SunOS containing init(),  _init() and asm(".init")() and SunOS 
4.1.3 doesn't call any of them.  I think dlopen should be using the 
string "__init" to search for _init() in the loaded object.  Similar 
comments apply to dlclose.

3. There is code in /usr/lib/c++rt0.o which calls constructors and 
destructors for shared libraries.  This is not used by libg++ which is 
the only c++ library in the core.  It also doesn't appear to be 
documented anywhere.  In addition, c++rt0.o uses atexit to register a 
function to call the destructors, however if dlclose is later used to 
remove the library, this will ensure a segfault on exit since exit() will 
still attempt to call the function.

4. dlclose does not unload dependant libraries or call destructors for 
the unloaded object.

I want to make some changes to ld.so to fix these problems, along these 
lines:

1. Fix ld.so to load all the dependant libraries for dlopen recursively.  
Ensure that initialisation of newly loaded libraries is deferred until 
all the dependants are loaded and relocated to allow sub-dependants to 
use symbols from their parent during initialisation.

2. Call ".init" to handle constructors and "__init" for user-supplied 
initialisation as per manpage.

3. Stop c++rt0.o from using atexit to call the destructors and added a
".fini" function to call them instead.

4. Change dlclose to unload dependant libraries and call ".fini" to handle
destructors.  For user-supplied closedown code, use "__fini"  instead of
"_fini". 

5. Add a dlexit function to the ld_entry function vector returned to 
crt0.o by ld.so.  This function is registered with atexit by crt0.o and 
calls all the ".fini" entry points of any shared libraries which are 
still loaded when the application exits.

--
Doug Rabson, Microsoft RenderMorphics Ltd.	Mail:  dfr@render.com
						Phone: +44 171 251 4411
						FAX:   +44 171 251 0939




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.91.950616174554.291D>