Subject: Re: kernel modules on PPC/Linux
To: gabriel rosenkoetter <gr@eclipsed.net>
From: Paul Mackerras <paulus@samba.org>
List: tech-kern
Date: 09/29/2001 13:42:56
gabriel rosenkoetter writes:
> On Sat, Sep 29, 2001 at 10:12:00AM +1000, Paul Mackerras wrote:
> > Just to set the record straight, kernel modules work just fine under
> > Linux on PPC. The way we handle the problem of the branch-and-link
> > (bl) instruction not being able to jump more than 32MB from the
> > current instruction is that the module loader will create a trampoline
> > for each procedure that the module wants to call that is too far away
> > from the module. The trampoline consists of 4 instructions that load
> > the address of the procedure into a register, move that into the
> > counter register, and do a branch-to-counter (bctr) instruction.
>
> Huh.
>
> So you implement long jumps on the fly rather than doing it in the
> linker? Isn't that more expensive? How does insmod (or whatever's
> backing it) figure out which instructions do and don't need the long
> jump syntax?
Not sure what you mean by "on the fly" as opposed to "in the linker".
Linux modules are .o files with all the relocation information still
in them, and the module loader (insmod) takes the place of the linker.
In the process of loading a module, insmod processes all the
relocations in the .o file - that's how it knows which branches need
to be redirected to a trampoline.
It would be possible to do kernel modules more like the way that
shared libraries are done - that might save some time in module
loading but would result in the code executing a little more slowly
because of the need to access variables through the GOT (global offset
table). Module loading happens relatively infrequently and the time
taken to process the relocations is small.
> (Feel free to send emails like this to tech-kern, btw; it's an
> open-reception mailing list. Feel free even to reply to this
> message including tech-kern, if you like.)
Thanks. I wondered how relevant this was to netbsd but if it is
helpful to whoever is implementing LKMs for netbsd on PPC then I'm
happy to discuss it.
> Fwiw, all I said was "to the best of my knowledge, Linux doesn't do
> LKMs on PowerPC either" or something similar, but only because I
> hadn't heard that it was done. :^>
No problem.
Paul.