home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / aix / 8936 < prev    next >
Encoding:
Internet Message Format  |  1992-08-19  |  3.1 KB

  1. Path: sparky!uunet!charon.amdahl.com!pacbell.com!mips!sdd.hp.com!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!unixhub!pixel.SLAC.Stanford.EDU!pavel
  2. From: pavel@pixel.SLAC.Stanford.EDU (Tom Pavel)
  3. Newsgroups: comp.unix.aix
  4. Subject: Re: Help with nlist(), XCOFF, and memory architecture...
  5. Message-ID: <PAVEL.92Aug19163010@pixel.SLAC.Stanford.EDU>
  6. Date: 19 Aug 92 23:30:10 GMT
  7. References: <PAVEL.92Aug15180402@pixel.SLAC.Stanford.EDU>
  8. Sender: news@unixhub.SLAC.Stanford.EDU
  9. Organization: Stanford Linear Accelerator Center
  10. Lines: 57
  11. Nntp-Posting-Host: pixel.slac.stanford.edu
  12. In-reply-to: pavel@pixel.SLAC.Stanford.EDU's message of 16 Aug 92 01:04:02 GMT
  13.  
  14.  
  15. [Since I did so well last time, I might as well press onward...]
  16.  
  17. > I'm trying to implement a dynamic function call mechanism (you find
  18. > out the name of the function at run-time, look it up in the symbol
  19. > table, and call the right address).  On my Sun, this worked very
  20. > trivially: an nlist() call returns the symbol table value for the
  21. > function, which happened to be the C-callable address of the
  22. > function. Of course, this is not quite so trivial on an RS/6000.... 
  23.  
  24. Many thanks to John Gerth, and to the various originators of the info
  25. he reposted.
  26.  
  27.   [ The trick is that the address of a function is actually the
  28.     address of a 12-byte function descriptor, which contains the
  29.     address of the text of the function in the first 4 bytes, and the
  30.     address of the TOC table for that segment in the next 4 bytes.]
  31.  
  32.  
  33. However, I still have many questions:
  34.  
  35. - Where is all this function-descriptor stuff documented?  I scoured
  36. through everything I could find, and I didn't see a trace of it (we're
  37. still running 3.1.7, if that makes any diff in the docs).
  38.  
  39. - So far, what I can do works ok IF all the functions I want to
  40. dynamically call are STATICALLY LINKED.  I can compute the text
  41. address of the function code by adding 0x10000200 to the nlist value,
  42. or by comparing the nlist value of ".main" with the text address in
  43. its function descriptor.  I can find the TOC by looking in main()'s
  44. function descriptor.  But what if I wanted to call a function in a
  45. shared library (not one that I load() in, but one that my program is
  46. linked with)?
  47.  
  48. - It seems to me that AIX is missing (or has failed to document) some
  49. magic system call that returns to me a list of all memory segments
  50. (i.e. shared libraries) in my current process, and their base
  51. addresses.  In fact, there is a call ld_getinfo() that appears in
  52. <sys/ldr.h> which looks suspiciously like it does this, but that call
  53. does not appear in syscalls.exp (or any of the libraries).  What good
  54. is the load() call, and all the XCOFF support for dynamic linking, if
  55. I can't figure out how to call an arbitrary routine in the shared
  56. library once I've linked it in?  [Pat Gainer's solution of a priori
  57. knowing what the first entry point in the module is does not
  58. constitute a general solution.]
  59.  
  60. -  What is the TOC really, and how can I get its value for a given
  61. memory segment?
  62.  
  63. -  Finally, I still have no clue why IBM chose "." instead of "_" to
  64. prepend to all global symbols...
  65.  
  66.  
  67. Tom Pavel
  68.  
  69. Stanford Linear Accelerator Center
  70. pavel@slac.stanford.edu
  71.