function arguments are passed in registers

Zheng Da
Fri Jan 4 15:23:00 GMT 2008

I'm writing a Linux kernel module which needs to call a static
function in the kernel.
Unfortunately, the static functions are compiled with arguments passed
in registers.
I don't want to change the kernel, so I have to use some trick to pass
arguments in different ways.
Currently, I use inline assembly, but I thought maybe GCC provides a better way.
By the way, how does Linux kernel handle it?
As I know, static functions pass their arguments in registers, and
others in the stack.
How does Linux kernel use them together?

Zheng Da

On Jan 2, 2008 11:45 PM, Tom St Denis <> wrote:
> Zheng Da wrote:
> > Suppose I have two libraries, A and B.
> > In library A, there is function a() whose arguments are passed in registers.
> > In library B, there is b() whose arguments are passed in the stack.
> > Now I have to use a() and b() in my program.
> > But how do I tell GCC that they use different ways to pass the
> > arguments and which is the right way.
> >
> This is why a common ABI exists.  The only "sane" way to accomplish this
> with GCC is to write a "thunking" [iirc that's the term] layer in which
> you pass the parameters in a different convention.
> How did you end up with this mess anyways?  Most assembler routines
> that interface with C are written to use the ABI so they're drop in.
> Tom

More information about the Gcc-help mailing list