NetBSD Problem Report #40694
From dholland@eecs.harvard.edu Thu Feb 19 17:55:41 2009
Return-Path: <dholland@eecs.harvard.edu>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
by narn.NetBSD.org (Postfix) with ESMTP id CBFA363B8C3
for <gnats-bugs@gnats.NetBSD.org>; Thu, 19 Feb 2009 17:55:40 +0000 (UTC)
Message-Id: <20090219175456.9016FFDCB@tanaqui.eecs.harvard.edu>
Date: Thu, 19 Feb 2009 12:54:56 -0500 (EST)
From: dholland@eecs.harvard.edu
Reply-To: dholland@eecs.harvard.edu
To: gnats-bugs@gnats.NetBSD.org
Subject: gcc tail-call vs. volatile bug
X-Send-Pr-Version: 3.95
>Number: 40694
>Category: toolchain
>Synopsis: gcc tail-call vs. volatile bug
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: toolchain-manager
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Feb 19 18:00:00 +0000 2009
>Closed-Date: Sun Jan 01 00:20:04 +0000 2017
>Last-Modified: Sun Jan 01 00:20:04 +0000 2017
>Originator: David A. Holland
>Release: NetBSD 5.99.7 (20090209)
>Organization:
>Environment:
System: NetBSD tanaqui 5.99.7 NetBSD 5.99.7 (TANAQUI) #24: Mon Feb 9 11:19:51 EST 2009 root@tanaqui:/usr/src/sys/arch/i386/compile/TANAQUI i386
Architecture: i386
Machine: i386
% gcc -v
Using built-in specs.
Target: i386--netbsdelf
Configured with: /usr/src/tools/gcc/../../gnu/dist/gcc4/configure --enable-long-long --disable-multilib --enable-threads --disable-symvers --build=x86_64-unknown-netbsd4.99.72 --host=i386--netbsdelf --target=i386--netbsdelf --enable-__cxa_atexit
Thread model: posix
gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)
>Description:
Compiling the following fragment (gcc -O2 -S foo.c) generates an
invalid tail call that does not repeat the local (volatile, no less)
variable on a new stack frame.
void
recurse_inf(void)
{
volatile char buf[16];
buf[0] = 0;
recurse_inf();
}
This is what I get out:
.file "foo.c"
.text
.p2align 2,,3
.globl recurse_inf
.type recurse_inf, @function
recurse_inf:
pushl %ebp
movl %esp, %ebp
subl $16, %esp
.p2align 2,,3
.L3:
movb $0, -16(%ebp)
jmp .L3
.size recurse_inf, .-recurse_inf
.ident "GCC: (GNU) 4.1.3 20080704 prerelease (NetBSD nb2 20081120)"
On a plain gcc 4.1.2 configured for mips I get two byte stores per
loop, too, which blatantly violates the volatile rules:
00400238 <recurse_inf>:
400238: 27bdfff0 addiu sp,sp,-16
40023c: a3a00000 sb zero,0(sp)
400240: a3a00000 sb zero,0(sp)
400244: 0810008f j 40023c <recurse_inf+0x4>
400248: 00000000 nop
I don't currently have time to build our gcc for mips and test it on
that to see if that aspect has been fixed since 4.1.2.
>How-To-Repeat:
As above.
>Fix:
?
I haven't reported this upstream because I don't currently have time
to test on a gcc they're still taking bug reports for.
>Release-Note:
>Audit-Trail:
From: David Laight <david@l8s.co.uk>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: toolchain/40694: gcc tail-call vs. volatile bug
Date: Thu, 19 Feb 2009 20:59:58 +0000
On Thu, Feb 19, 2009 at 06:00:00PM +0000, dholland@eecs.harvard.edu wrote:
> >Number: 40694
> >Category: toolchain
> >Synopsis: gcc tail-call vs. volatile bug
...
> Compiling the following fragment (gcc -O2 -S foo.c) generates an
> invalid tail call that does not repeat the local (volatile, no less)
> variable on a new stack frame.
>
> void
> recurse_inf(void)
> {
> volatile char buf[16];
> buf[0] = 0;
> recurse_inf();
> }
Surely the 'as if' rule applies?
Since 'buf' cannot be referenced it can be discarded.
I don't see why the 'volatile' would have any effect here.
David
--
David Laight: david@l8s.co.uk
From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: toolchain/40694: gcc tail-call vs. volatile bug
Date: Sat, 31 Dec 2011 19:09:24 +0000
On Thu, Feb 19, 2009 at 06:00:00PM +0000, dholland@eecs.harvard.edu wrote:
> Compiling the following fragment (gcc -O2 -S foo.c) generates an
> invalid tail call that does not repeat the local (volatile, no less)
> variable on a new stack frame.
>
> void
> recurse_inf(void)
> {
> volatile char buf[16];
> buf[0] = 0;
> recurse_inf();
> }
This is not fixed in gcc 4.5. The gcc 4.5 output for i386:
.file "foo.c"
.text
.globl recurse_inf
.type recurse_inf, @function
recurse_inf:
pushl %ebp
movl %esp, %ebp
subl $16, %esp
.L2:
movb $0, -16(%ebp)
jmp .L2
.size recurse_inf, .-recurse_inf
.ident "GCC: (NetBSD nb1 20110620) 4.5.3"
and for amd64 (excluding eh_frame gunk):
.file "foo.c"
.text
.globl recurse_inf
.type recurse_inf, @function
recurse_inf:
.LFB0:
.L2:
movb $0, -24(%rsp)
jmp .L2
.LFE0:
.size recurse_inf, .-recurse_inf
.ident "GCC: (NetBSD nb2 20110806) 4.5.3"
(Why is the gcc version slightly different? I'm not sure, both
tooldirs are pretty recent.)
> On a plain gcc 4.1.2 configured for mips I get two byte stores per
> loop, too, which blatantly violates the volatile rules:
Haven't tried this with gcc 4.5.3 but I wouldn't expect it to be much
different either.
--
David A. Holland
dholland@netbsd.org
From: matthew green <mrg@eterna.com.au>
To: gnats-bugs@NetBSD.org
Cc: toolchain-manager@netbsd.org, gnats-admin@netbsd.org,
netbsd-bugs@netbsd.org, dholland@eecs.harvard.edu
Subject: re: toolchain/40694: gcc tail-call vs. volatile bug
Date: Sun, 01 Jan 2012 14:13:08 +1100
> This is not fixed in gcc 4.5. The gcc 4.5 output for i386:
> .ident "GCC: (NetBSD nb1 20110620) 4.5.3"
>
> and for amd64 (excluding eh_frame gunk):
> .ident "GCC: (NetBSD nb2 20110806) 4.5.3"
>
>
> (Why is the gcc version slightly different? I'm not sure, both
> tooldirs are pretty recent.)
it's a mknative issue. i386 hadn't been re-done but amd64 had.
.mrg.
From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: toolchain/40694: gcc tail-call vs. volatile bug
Date: Mon, 2 Jan 2012 16:57:55 +0000
On Sun, Jan 01, 2012 at 03:15:05AM +0000, matthew green wrote:
> > (Why is the gcc version slightly different? I'm not sure, both
> > tooldirs are pretty recent.)
>
> it's a mknative issue. i386 hadn't been re-done but amd64 had.
I thought it might be that...
--
David A. Holland
dholland@netbsd.org
State-Changed-From-To: open->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sun, 01 Jan 2017 00:20:04 +0000
State-Changed-Why:
fixed in gcc4.8 and gcc5, realistically nobody is going to hunt it down in
older gcc.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.