From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.bugs,gmane.comp.sysutils.autoconf.bugs Subject: bug in check for stack growth direction in _AC_LIBOBJ_ALLOCA Date: Fri, 17 Jun 2011 12:21:23 +0200 Message-ID: <87d3ic92sc.fsf@pobox.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1308329800 6449 80.91.229.12 (17 Jun 2011 16:56:40 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 17 Jun 2011 16:56:40 +0000 (UTC) Cc: bug-guile To: bug-autoconf@gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Fri Jun 17 18:56:35 2011 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QXcLM-0004D2-JL for guile-bugs@m.gmane.org; Fri, 17 Jun 2011 18:56:28 +0200 Original-Received: from localhost ([::1]:51838 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QXcLL-0000sm-H3 for guile-bugs@m.gmane.org; Fri, 17 Jun 2011 12:56:27 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:57489) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QXafc-00031A-Sq for bug-guile@gnu.org; Fri, 17 Jun 2011 11:09:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QXafa-0008Qv-Bw for bug-guile@gnu.org; Fri, 17 Jun 2011 11:09:16 -0400 Original-Received: from a-pb-sasl-sd.pobox.com ([64.74.157.62]:57780 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QXafV-0008Of-Ex; Fri, 17 Jun 2011 11:09:09 -0400 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTP id 313F45F60; Fri, 17 Jun 2011 11:11:19 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:mime-version:content-type; s=sasl; bh=a 7XzFADY2/4HrTIB0yy5FeJ+tzQ=; b=Go+HyQDP8xWVPdP8z/QUb4HU/uoV2mTpd qdvyvjhg3vb6t7HWOstBJbmEmdInUSlmBHDMy5syBpCuoEhrxrn7SAZDBbwAx/3s dQHR+u8wW9Dl3K55IidMd1fYU4/DpT3Ma6U7iUsNixx1miSPvNLk4LUF0oK9Uuft H0Zll0cdIA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:date:message-id:mime-version:content-type; q=dns; s= sasl; b=LvIDMBlPnIccc+rt7uQjrjq9IiQfATvHw6/yvXrvtygw6xs6vGrO9eiz 6g/4yOWodH3wzw9VaAH6C/RIbMA+4Z9i8kZ5lhaTiFILukx/LSS1L4TXThgTS3jJ r2EdK+AP0IqaudgvaPs20n9bUUvlYwO6svFotEodNFXRyfOetV8= Original-Received: from a-pb-sasl-sd.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTP id 2A88D5F5F; Fri, 17 Jun 2011 11:11:19 -0400 (EDT) Original-Received: from badger (unknown [90.164.198.39]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTPSA id 56BDC5F5E; Fri, 17 Jun 2011 11:11:18 -0400 (EDT) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) X-Pobox-Relay-ID: 0D5FFD30-98F4-11E0-8DC5-5875C023C68D-02397024!a-pb-sasl-sd.pobox.com X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) X-Received-From: 64.74.157.62 X-BeenThere: bug-guile@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:5653 gmane.comp.sysutils.autoconf.bugs:7946 Archived-At: Hello, The following transcript indicates a problem with the stack growth direction check, present at functions.m4:328 in autoconf 2.68: wingo@badger:/tmp$ cat foo.c int find_stack_direction () { static char *addr = 0; auto char dummy; if (addr == 0) { addr = &dummy; return find_stack_direction (); } else return (&dummy > addr) ? 1 : -1; } int main () { return find_stack_direction () < 0; } wingo@badger:/tmp$ gcc -O1 -o test foo.c wingo@badger:/tmp$ ./test; echo $? 1 wingo@badger:/tmp$ gcc -O3 -o test foo.c wingo@badger:/tmp$ ./test; echo $? 0 $ gcc --version gcc (Debian 4.6.0-13) 4.6.1 20110611 (prerelease) Copyright (C) 2011 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. As you see, the check (on an x86-64 system) gives the correct result at -O1 but not at -O3. (I don't actually use this check from _AC_LIBOBJ_ALLOCA, but Guile has the exact same test to check for stack growth direction, so it's the same issue. Reported by Marco Maggi.) Looking a bit more closely at this, I find the assembly to be a bit odd here: 00000000004004a0 : 4004a0: mov 0x2003f9(%rip),%rax # 6008a0 4004a7: test %rax,%rax 4004aa: je 4004c0 4004ac: lea -0x2(%rsp),%rdx 4004b1: cmp %rdx,%rax 4004b4: sbb %eax,%eax 4004b6: and $0x2,%eax 4004b9: sub $0x1,%eax 4004bc: retq 4004bd: nopl (%rax) 4004c0: lea -0x2(%rsp),%rax 4004c5: lea -0x1(%rsp),%rdx 4004ca: cmp %rdx,%rax 4004cd: mov %rax,0x2003cc(%rip) # 6008a0 4004d4: sbb %eax,%eax 4004d6: and $0x2,%eax 4004d9: sub $0x1,%eax 4004dc: retq 4004dd: nop 4004de: nop 4004df: nop As you can see there is no call. The test will always be true, thus the second branch is always taken. I don't know what allows GCC to do this inlining. Could it be a GCC bug? Every time I think I have a GCC bug I'm wrong, though :) I tried changing the test to the following: int find_stack_direction (char *addr) { char dummy; if (addr == 0) return find_stack_direction (&dummy); else return (&dummy > addr) ? 1 : -1; } int main () { return find_stack_direction (0) < 0; } But I get the same behavior. Andy -- http://wingolog.org/