This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Variadic functions


Hi,
I am forwarding to you a mail that I sent to the uClibc mailing list as
I think it is actually a compiler issue.  Please see below for the
original.  Any tips would be greatly appreciated.
/Jonas

-------- Forwarded Message --------
From: jonas at southpole dot se
To: uclibc@uclibc.org
Subject: Variadic functions
Date: Tue, 08 Jun 2010 09:22:28 +0200

Hi,
I am working on the OPENRISC32 (or32) architecture port of uClibc and
have run into a bit of conundrum that I was hoping someone could help me
understand a bit better.  Please bear with me...

----------

The preconditions:

i) The declaration of xdrproc_t is variadic:

typedef bool_t (*xdrproc_t) (XDR *, void *, ...);

ii) In libc/inet/rpc/xdr.c the functions choices->proc, which of type
xdrproc_t is called:

return (*(choices->proc)) (xdrs, unp, LASTUNSIGNED);

iii) choices->proc may be dereferenced to the function
"xdr_accepted_reply" which is defined in libc/inet/rpc/rpc_prot.c as:

bool_t
xdr_accepted_reply (XDR *xdrs, struct accepted_reply *ar) { ... }

-----------

Now, the problem:
i)  As xdr_accepted_reply is not defined as variadic, the function is
compiled to find the parameters in registers r3 and r4.
ii)  As choices->proc is variadic (according to the declaration), the
compiler puts the first parameter in a register and the second on on the
stack.

This, of course, becomes problematic!!!

-----------

Workaround:
i)  By redefining xdr_accepted_reply to be variadic, the compiler makes
the function look for paramter 1 in a register and paramter 2 on the
stack, thus matching what it does for the function call.  Like this...

bool_t
xdr_accepted_reply (XDR *xdrs, struct accepted_reply *ar, ...) { ... }

------------

Questions:
i)  Is my compiler broken?  If so, is there somewhere in GCC that
specifically handles register/stack parameter passing for variadic
functions???  (GCC 4.2, patched for or32)
ii)  What is the correct compiler behaviour variadic
declarations/definitions?  Should xdr_accepted_reply not be variadic
since it is used in such a context?  Note that there are several
functions that are cast to xdrproc_t and none of them are defined as
variadic...
iii)  Any advice on how to proceed... I know I need to patch something,
but I'm not sure if it's GCC,binutils, or uClibc.

Thanks for bearing with me on this.  Regards,
Jonas


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]