Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!lll-lcc!pyramid!batcomputer!garry From: garry@batcomputer.UUCP Newsgroups: comp.unix.wizards Subject: Re: Dynamic function loading Message-ID: <681@batcomputer.tn.cornell.edu> Date: Tue, 14-Apr-87 12:24:25 EST Article-I.D.: batcompu.681 Posted: Tue Apr 14 12:24:25 1987 Date-Received: Fri, 17-Apr-87 00:29:31 EST Reply-To: garry@oak.cadif.cornell.edu Organization: Cornell Engineering && Flying Moose Graphics Lines: 51 In a recent article bzs@bu-cs.BU.EDU (Barry Shein) wrote: >The code for funload() is too hairy to throw in off the top of my head >but groveling the stuff I mentioned above should steer you in the right >direction. > >Or, I could send you my consulting schedules :-) It's not that hard, but >it takes some attention to detail. Several problems come immediately to mind: - There's no way to get more than 65K bytes at a time from K&R-standard malloc(). You have to mess with sbrk(), I guess. There's a tickle in my brain which says "don't call sbrk yourself if you want the run-time library not to get confused." Is my tickle true on some systems? - How do you fix up the relocations in the image you're bringing in? Or do you link it at an absolute address? (ick) - What do you do on machines with separate Instruction/Data spaces? - Does a.out.h tend to be quite similar or quite different on different systems? As an embellishment to Barry's scheme, I'd suggest: int foo () { static int (*real_foo)() = null; if (real_foo == null) real_foo = please_load ("foo","real_library"); (*real_foo)(); } This gives you a regular entry point to call and avoids the string comparisons on calls after the first. This whole mess should be done properly and thoroughly by the system, in a new system call. Shareable library images are amazingly handy - you can play tricks at run time, executable images get a lot smaller, and, most important, software maintenance is *much* easier - there is rarely/never such a thing as a "required re-link" - you just pop the new library image into the system. I'm coming from VMS land; I know other systems have this feature too. Is there any hope for it in Unix? I'd also mention "faster linking to large libraries", but I've recently had good luck with using "ld -r" to simplify my library entries and speed up the (eventual) linking. Anyhow, this subject has come up many times. Does anyone have any code that they'd care to post to mod.sources? (For more than one machine, pray?) garry wiegand (garry@oak.cadif.cornell.edu - ARPA) (garry@crnlthry - BITNET)