home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / aix / 8172 < prev    next >
Encoding:
Internet Message Format  |  1992-07-25  |  2.6 KB

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