From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp1.atof.net (smtp1.atof.net [52.86.233.228]) by sourceware.org (Postfix) with ESMTPS id 4F09B3972004 for ; Fri, 5 Mar 2021 14:43:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4F09B3972004 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gluelogic.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gs-cygwin.com@gluelogic.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-Spam-Language: en X-Spam-Relay-Country: X-Spam-DCC: B=sonic; R=smtp1.atof.net 1255; Body=1 Fuz1=1 Fuz2=1 X-Spam-RBL: X-Spam-PYZOR: Reported 0 times. Date: Fri, 5 Mar 2021 09:43:26 -0500 From: gs-cygwin.com@gluelogic.com To: cygwin@cygwin.com Subject: Re: stack grow direction wrongly detected Message-ID: References: <6eded5d3-93f3-7c98-5055-ee5ac2566bc8@gmail.com> <20210305233104.782838da83161a90f56a5369@nifty.ne.jp> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline In-Reply-To: <20210305233104.782838da83161a90f56a5369@nifty.ne.jp> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-BeenThere: cygwin@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Mar 2021 14:43:39 -0000 On Fri, Mar 05, 2021 at 11:31:04PM +0900, Takashi Yano via Cygwin wrote: > On Fri, 5 Mar 2021 13:18:38 +0100 > Marco Atzeri wrote: > > Hi Guys, > > noted trying to rebuild guile 1.8.8. > > > > The following piece of code in the past > > was setting SCM_I_GSC_STACK_GROWS_UP=0 > > and now produces SCM_I_GSC_STACK_GROWS_UP=1 > > > > I assume some change in the gcc compiler is causing the issue. > > I presume most of the programs and libraries do not care, > > but some special one like guile crashes during build for this issue, > > so be aware. > > > > Regards > > Marco > > > > > > #-------------------------------------------------------------------- > > # > > # Which way does the stack grow? > > # > > # Following code comes from Autoconf 2.61's internal _AC_LIBOBJ_ALLOCA > > # macro (/usr/share/autoconf/autoconf/functions.m4). Gnulib has > > # very similar code, so in future we could look at using that. > > # > > # An important detail is that the code involves find_stack_direction > > # calling _itself_ - which means that find_stack_direction (or at > > # least the second find_stack_direction() call) cannot be inlined. > > # If the code could be inlined, that might cause the test to give > > # an incorrect answer. > > #-------------------------------------------------------------------- > > > > SCM_I_GSC_STACK_GROWS_UP=0 > > AC_RUN_IFELSE([AC_LANG_SOURCE( > > [AC_INCLUDES_DEFAULT > > 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; > > }])], > > [SCM_I_GSC_STACK_GROWS_UP=1], > > [], > > [AC_MSG_WARN(Guessing that stack grows down -- see > > scmconfig.h)]) > > This seems to be a result of optimization. With gcc v10.2.0, > the return value of the code is: > -O0: 1 > -O1: 1 > -O2: 0 > -O3: 1 > -O4: 1 > > If find_stack_direction() is implemented as recursive call, > and auto variable is allocated in the stack every time, > in the first call, addr is initialized to the first stack > position, and in the second call, second address of dummy > is reduced because stack of x86 is reverse direction. > Therefore (&dummy > addr) ? 1 : -1; returns -1. > As a result, the return value find_stack_direction() < 0 > is 1. With -O0 or -O1 this implemented as recursive call, > so the return value is 1. If the compiler is gcc or clang: __attribute__(__noinline__) int find_stack_direction () { ... } Cheers, Glenn