From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8618 invoked by alias); 8 Jun 2010 20:44:28 -0000 Received: (qmail 8609 invoked by uid 22791); 8 Jun 2010 20:44:27 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 08 Jun 2010 20:44:22 +0000 Received: from hpaq11.eem.corp.google.com (hpaq11.eem.corp.google.com [172.25.149.11]) by smtp-out.google.com with ESMTP id o58KiJNr005787 for ; Tue, 8 Jun 2010 13:44:20 -0700 Received: from fg-out-1718.google.com (fgbl26.prod.google.com [10.86.88.26]) by hpaq11.eem.corp.google.com with ESMTP id o58KiIKv015671 for ; Tue, 8 Jun 2010 13:44:18 -0700 Received: by fg-out-1718.google.com with SMTP id l26so1632307fgb.15 for ; Tue, 08 Jun 2010 13:44:18 -0700 (PDT) Received: by 10.86.6.16 with SMTP id 16mr3321365fgf.55.1276029858260; Tue, 08 Jun 2010 13:44:18 -0700 (PDT) Received: from coign.google.com ([216.239.45.130]) by mx.google.com with ESMTPS id l19sm15250292fgb.5.2010.06.08.13.44.15 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 08 Jun 2010 13:44:16 -0700 (PDT) To: Jonas Bonn Cc: gcc@gcc.gnu.org Mail-Followup-To: gcc-help@gcc.gnu.org Subject: Re: Variadic functions References: <1276012368.19806.11.camel@satguru.bonn.nu> From: Ian Lance Taylor Date: Tue, 08 Jun 2010 22:41:00 -0000 In-Reply-To: <1276012368.19806.11.camel@satguru.bonn.nu> (Jonas Bonn's message of "Tue\, 08 Jun 2010 17\:52\:48 +0200") Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-IsSubscribed: yes Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2010-06/txt/msg00347.txt.bz2 Jonas Bonn 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-help@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