Jonas Bonn <jo...@southpole.se> writes:

> 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.

This message would be more appropriate for the mailing list
gcc-h...@gcc.gnu.org.  Please take any followups to gcc-help.
Thanks.

> 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) { ... }


Casting a function pointer to a different type and then calling it is
undefined behaviour in C/C++.  The standard does not guarantee that
this program will work.


> 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)

This problem does not indicate that your program is broken.  Calling
variadic functions is handled specially in the backend.  I am not
familiar with the or32 backend, but that is where the code would be.


> 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...

That is broken.  You can not casually cast function pointers to
different types.  You especially can not cast them between variadic
and non-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.

You need to patch the source code.  It sounds like that source code is
in uClibc.

Ian

Reply via email to