From owner-freebsd-amd64@FreeBSD.ORG Tue Aug 24 18:55:30 2004 Return-Path: Delivered-To: freebsd-amd64@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 536CE16A4CE; Tue, 24 Aug 2004 18:55:30 +0000 (GMT) Received: from canning.wemm.org (canning.wemm.org [192.203.228.65]) by mx1.FreeBSD.org (Postfix) with ESMTP id 417C043D4C; Tue, 24 Aug 2004 18:55:30 +0000 (GMT) (envelope-from peter@evilpete.dyndns.org) Received: from fw.wemm.org (canning.wemm.org [192.203.228.65]) by canning.wemm.org (Postfix) with ESMTP id 110052A8DA; Tue, 24 Aug 2004 11:55:30 -0700 (PDT) (envelope-from peter@overcee.wemm.org) Received: from overcee.wemm.org (overcee.wemm.org [10.0.0.3]) by fw.wemm.org (Postfix) with ESMTP id 8CC14E2B3; Tue, 24 Aug 2004 11:55:29 -0700 (PDT) (envelope-from peter@overcee.wemm.org) Received: from overcee.wemm.org (localhost [127.0.0.1]) by overcee.wemm.org (8.12.11/8.12.11) with ESMTP id i7OItTHx009699; Tue, 24 Aug 2004 11:55:29 -0700 (PDT) (envelope-from peter@overcee.wemm.org) Received: from localhost (localhost [[UNIX: localhost]]) by overcee.wemm.org (8.12.11/8.12.11/Submit) id i7OItPvX009698; Tue, 24 Aug 2004 11:55:25 -0700 (PDT) (envelope-from peter) From: Peter Wemm To: Sean McNeil Date: Tue, 24 Aug 2004 11:55:25 -0700 User-Agent: KMail/1.6.1 References: <1093328434.6603.21.camel@server.mcneil.com> <200408240220.45554.peter@wemm.org> <1093368559.9914.15.camel@server.mcneil.com> In-Reply-To: <1093368559.9914.15.camel@server.mcneil.com> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200408241155.25406.peter@wemm.org> cc: amd64@freebsd.org cc: freebsd-amd64@freebsd.org Subject: Re: va_list structure passing as argument X-BeenThere: freebsd-amd64@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Porting FreeBSD to the AMD64 platform List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Aug 2004 18:55:30 -0000 On Tuesday 24 August 2004 10:29 am, Sean McNeil wrote: > On Tue, 2004-08-24 at 02:20, Peter Wemm wrote: > > On Monday 23 August 2004 11:20 pm, Sean McNeil wrote: > > > I'm looking at a problem I have on the amd64 with bsdtar. > > > Essentially, you get a core dump if you try to run the following: > > > > > > tar zxvvf nonexistent.tar.gz > > > > > > I've tracked it down to an issue where the ap is getting changed > > > as a side-effect of calling __vfprintf. It looks like this is > > > happening because the va_list structure is being passed by > > > reference. The va_list structure on amd64 is 24 bytes. I'm > > > guessing that it is 16 bytes or less for i386. It has been a > > > while since I've looked at the macro that determines when a > > > structure is passed by reference or value. Does anyone know what > > > that is? I'm guessing that 24 passes that cutoff but 16 does not > > > and that is why I see this bug on amd64 and not i386. > > > > Yes, its an external value. Consider it a pointer. It is the same > > on both ppc and amd64. > > > > The problem is that vfprintf "consumes" the values and advances > > the counters in the structure. (The argument passing ABI is very > > complex) > > > > What you need to do is this: > > myfunc(va_list ap) > > { > > va_list apcopy; > > > > va_copy(apcopy, ap); > > vprintf(stuff, ap1); > > va_copy(apcopy, ap); > > do_stuff_with(ap1); > > } > > etc. Using va_copy is "correct" for all our platforms, but > > neglecting to use it is only fatal for amd64 and ppc. > > > > Does that make sense? > > Makes sense and is what I tried originally. I figured this wasn't > correct, however, as it means that a side-effect of the call is > allowable. What you are indicating is that it is allowable and > expected. The problem is, the side-effect will only happen on ppc > and amd64 since i386 will pass the va_list by value. Just because you can get away with it on i386, that doesn't mean it is allowed. With C99, you're supposed to use va_copy, even if you can get away with not using it on some platforms. -- Peter Wemm - peter@wemm.org; peter@FreeBSD.org; peter@yahoo-inc.com "All of this is for nothing if we don't go to the stars" - JMS/B5