home *** CD-ROM | disk | FTP | other *** search
- 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
- From: pavel@pixel.SLAC.Stanford.EDU (Tom Pavel)
- Newsgroups: comp.unix.aix
- Subject: Re: Help with nlist(), XCOFF, and memory architecture...
- Message-ID: <PAVEL.92Aug19163010@pixel.SLAC.Stanford.EDU>
- Date: 19 Aug 92 23:30:10 GMT
- References: <PAVEL.92Aug15180402@pixel.SLAC.Stanford.EDU>
- Sender: news@unixhub.SLAC.Stanford.EDU
- Organization: Stanford Linear Accelerator Center
- Lines: 57
- Nntp-Posting-Host: pixel.slac.stanford.edu
- In-reply-to: pavel@pixel.SLAC.Stanford.EDU's message of 16 Aug 92 01:04:02 GMT
-
-
- [Since I did so well last time, I might as well press onward...]
-
- > I'm trying to implement a dynamic function call mechanism (you find
- > out the name of the function at run-time, look it up in the symbol
- > table, and call the right address). On my Sun, this worked very
- > trivially: an nlist() call returns the symbol table value for the
- > function, which happened to be the C-callable address of the
- > function. Of course, this is not quite so trivial on an RS/6000....
-
- Many thanks to John Gerth, and to the various originators of the info
- he reposted.
-
- [ The trick is that the address of a function is actually the
- address of a 12-byte function descriptor, which contains the
- address of the text of the function in the first 4 bytes, and the
- address of the TOC table for that segment in the next 4 bytes.]
-
-
- However, I still have many questions:
-
- - Where is all this function-descriptor stuff documented? I scoured
- through everything I could find, and I didn't see a trace of it (we're
- still running 3.1.7, if that makes any diff in the docs).
-
- - So far, what I can do works ok IF all the functions I want to
- dynamically call are STATICALLY LINKED. I can compute the text
- address of the function code by adding 0x10000200 to the nlist value,
- or by comparing the nlist value of ".main" with the text address in
- its function descriptor. I can find the TOC by looking in main()'s
- function descriptor. But what if I wanted to call a function in a
- shared library (not one that I load() in, but one that my program is
- linked with)?
-
- - It seems to me that AIX is missing (or has failed to document) some
- magic system call that returns to me a list of all memory segments
- (i.e. shared libraries) in my current process, and their base
- addresses. In fact, there is a call ld_getinfo() that appears in
- <sys/ldr.h> which looks suspiciously like it does this, but that call
- does not appear in syscalls.exp (or any of the libraries). What good
- is the load() call, and all the XCOFF support for dynamic linking, if
- I can't figure out how to call an arbitrary routine in the shared
- library once I've linked it in? [Pat Gainer's solution of a priori
- knowing what the first entry point in the module is does not
- constitute a general solution.]
-
- - What is the TOC really, and how can I get its value for a given
- memory segment?
-
- - Finally, I still have no clue why IBM chose "." instead of "_" to
- prepend to all global symbols...
-
-
- Tom Pavel
-
- Stanford Linear Accelerator Center
- pavel@slac.stanford.edu
-