Finding module TOC address

Alan Modra amodra at bigpond.net.au
Thu May 26 17:33:07 EST 2005


On Thu, May 26, 2005 at 04:49:58PM +1000, Benjamin Herrenschmidt wrote:
> On Thu, 2005-05-26 at 08:06 +1000, Benjamin Herrenschmidt wrote:
> > On Wed, 2005-05-25 at 21:42 +0300, Heikki Lindholm wrote:
> > > Hello,
> > > I need to use assembly jump to a function in a module. How do I find out 
> > > the TOC that the function expects to find in r2? A quick peek at 
> > > kernel/module.c didn't help much, maybe someone here could enlighten me.
> > 
> > You don't, there is no TOC on ppc32 ABI, at least the kernel version of
> > it. r2 is reserved in the kernel and always contains "current".
> 
> Ooops ! As you stated privately, wrong list :)
> 
> So yes, ppc64 has a TOC :)
> 
> When you take the function pointer, what you should obtain is a
> descriptor containing the actual pointer and the TOC (unless you are
> calling the .xxx symbol, but that isn't very good to do).
> 
> So if you are doing a pointer-based jump, just load the TOC pointer
> along with the function pointer from the descriptor. If you are doing a
> direct jump (bl .blabla), I'm not 100% sure, you'll probably just load
> the non-dot symbol address in a register to get the descriptor, and then
> peek it for the toc value... Alan ? Is there some better way ?

Rusty will know for sure.  I haven't kept up with how kernel modules
work, but I think that you just use

 bl .foo
 nop

The kernel module support turn this into

 bl foo_stub
 ld 2,40(1)

and generates foo_stub to save r2 at 40(1), load r2 from the descriptor
and jump to the address in the descriptor.

That means the module itself had better have .opd entries for functions.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre



More information about the Linuxppc64-dev mailing list