public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Brian Inglis <Brian.Inglis@SystematicSw.ab.ca>
To: cygwin@cygwin.com
Subject: Re: stack grow direction wrongly detected
Date: Fri, 5 Mar 2021 11:58:53 -0700	[thread overview]
Message-ID: <cb59246a-5dd9-b45d-96da-45ba392b2978@SystematicSw.ab.ca> (raw)
In-Reply-To: <6eded5d3-93f3-7c98-5055-ee5ac2566bc8@gmail.com>

On 2021-03-05 05:18, Marco Atzeri via Cygwin 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)])

Report it upstream to guile and [better] autoconf for correction - suggest a 
patch or not as you feel appropriate.

It's an issue that the code does not assume --push and pop++ as that is the 
common implementation -- then do adequate due diligence to inhibit optimizations 
that avoid stack usage, eliminate tail recursion, and generate inline code, to 
prove the opposite. Some implementations (used to?) not natively support or use 
stacks and emulated them with dynamically allocated memory blocks.

I am surprised that this has not occurred previously, and wonder if someone 
recently replaced, eliminated, or "optimized" code, or some necessary settings, 
that allow such autoconf tests to do their jobs properly.

We all love the advantage such transformations provide our code at large compile 
time and space costs, but most are unaware of the effort that detection code 
like the above now has to go thru to avoid being rendered useless.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.
[Data in binary units and prefixes, physical quantities in SI.]

  parent reply	other threads:[~2021-03-05 18:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-05 12:18 Marco Atzeri
2021-03-05 14:31 ` Takashi Yano
2021-03-05 14:43   ` gs-cygwin.com
2021-03-06  8:29     ` Marco Atzeri
2021-03-06  9:29       ` Thomas Wolff
2021-03-05 15:25   ` Thomas Wolff
2021-03-05 18:58 ` Brian Inglis [this message]
2021-03-05 20:29   ` Marco Atzeri
2021-03-06  1:06     ` Takashi Yano
2021-03-06  9:12       ` Marco Atzeri

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cb59246a-5dd9-b45d-96da-45ba392b2978@SystematicSw.ab.ca \
    --to=brian.inglis@systematicsw.ab.ca \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).