Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!uunet!auspex!guy From: guy@auspex.auspex.com (Guy Harris) Newsgroups: comp.unix.questions Subject: Re: Dynamic linking Message-ID: <8454@auspex.auspex.com> Date: 21 Jun 91 01:02:55 GMT References: <7508@s3.ireq.hydro.qc.ca> Distribution: comp.unix.questions, comp.sys.sun Organization: Auspex Systems, Santa Clara Lines: 48 > [asks for the possibility of dynamically linking functions > into a running program under SunOS 4.1.1] > >You should get Wilson Ho's Dld, the dynamic link/unlink editor. He can also just use the routines described in the DLOPEN(3X) manual page if he's using SunOS 4.1[.x]; those routines are also in System V Release 4. > Restrictions: > ------------ > > - I want the users to compile and link their functions with all > the necessary librairies (so they will be no unresolved external > when I'll dynamically link them). If any of the libraries with which the user-defined module would be linked are shared libraries with which the interpreter was linked, that's not necessary; the dynamically-loaded code will get bound to the libraries in question when it's loaded. Otherwise, you'll have to link the dynamically-loaded code with the library (with the disadvantage that doing so will probably introduce non-position-independent code; that may mean that two processes using the same dynamically-loaded code won't share it all, if that matters, and may tickle some dynamic loader bugs). There's also a bug in the 4.1[.x] dynamic loader (which I'm told is absent from S5R4) such that it can't handle dynamically-loaded code if it has any BSS. A workaround is to: 1) open "/dev/zero"; 2) dup that file descriptor; 3) close the original file descriptor, leaving the dup'ed one open; as the first thing you do in "main()" (basically, the dynamic loader assumes "/dev/zero" is still open from when it was used to load the shared libraries; the above sequence re-opens it to what should be the same file descriptor number). A potential win of the "dlopen()" routines is portability; this doesn't matter for SunOS 4.1[.x], as "dld" is supported on all the platforms on which 4.1[.x] is supported, but may be a win for S5R4 - the dynamic loader has to be ported by the vendor, so you don't have to port it yourself to some new platform. (I.e., it should be in S5R4 for e.g. MIPS or the 88K; none of the platforms in the list of "dld" platforms have those chips.)