home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!darwin.sura.net!mips!swrinde!news.dell.com!uudell!pensoft!mike
- From: mike@pencom.com (Mike Heath)
- Newsgroups: comp.unix.aix
- Subject: Re: A better dynamic loader???
- Message-ID: <1992Jul25.073355.7669@pencom.com>
- Date: 25 Jul 92 07:33:55 GMT
- References: <45628@shamash.cdc.com>
- Sender: usenet@pencom.com (Usenet Psuedo User)
- Organization: Pencom Software, Austin, TX
- Lines: 49
-
- In article <45628@shamash.cdc.com> pbd@runyon.cim.cdc.com (Paul Dokas) writes:
- >I need to be able to execute dynamically loaded modules from within another
- >program, but I can't seem to find the needed functionality anywhere. What I
- >have right now is a program that uses load() to pull in a module and then it
- >calls the function pointed to by the return value of load(). This works
- >fine, but I need to have several entry points in a single module. And to make
- >things even more complex, the user creates the modules, so the program has
- >no idea where to call within the module. What I really need is a function
- >like this:
- >
- > typedef void (func_t)(int, int);
- > func_t *lookup(char *module_name, char *func_name);
- >
- >The function lookup() returns a pointer to a function given the name of a
- >module to look in and a function name to look for.
- >
- >I really want to avoid writing my own dynamic loader with the ldopen, ldclose,
- >etc functions. I had to do this on an SGI and I really don't want to waste
- >another 2-3 weeks. Any input is greatly appreciated.
-
- I wrote the equivalent of Sun's dlsym() for the RS6K a little over a year
- ago for a client. I don't have a copy of the code, so I can't offer it
- to you, but I can give you some hints.
-
- You could either use loadquery() to get the module names, or better yet,
- at the time of each load() call (though, you'll still have to account for
- the shared libraries loaded at exec() time), open the file manually and
- grab all the exported symbols and their addresses (Loader symbol table).
- You'll have to "relocate" the addresses using the value returned by load().
-
- For performance reasons, you'll want to retain all these values for
- multiple calls, plus, you'll want to memory map the object files
- when you scan the Loader Symbol Table.
-
- When I did this under 3.1.5, ldopen() had a problem accessing archives.
- It shouldn't take more than two days if you understand how the
- dynamic loader works.
-
- If you want to take a slightly different approach, you could require
- that the entry routine return a structure of routine names and addresses
- contained in the module.
-
- Hope this helps.
-
- --
- Mike Heath Pencom ... We're not just headhunters anymore.
- Pencom Software
- Austin, TX
- mike@pencom.com
-