public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: 16 byte pthread stack alignments
Date: Wed, 21 Dec 2011 09:42:00 -0000	[thread overview]
Message-ID: <20111221094211.GH23547@calimero.vinschen.de> (raw)
In-Reply-To: <Pine.CYG.4.58.1112201743030.3964@PC1163-8460-XP.flightsafety.com>

On Dec 20 17:45, Brian Ford wrote:
> I'm just headed home from work right now, but I thought I would let you
> know of a regression from 1.7.9.  It appears the effect of this patch:
> 
> http://www.cygwin.com/ml/cygwin-cvs/2004-q2/msg00124.html
> 
> is no longer working in the current snapshot.  I'll try to narrow it down
> to which change caused the regression and send in an STC tomorrow.

Is that the first Cygwin process started from a 64 bit process on 64 bit
XP or 2003?  If so, see the new wow64_revert_to_original_stack function
in wow64.cc and the wow64 code in _dll_crt0.

I don't see how any other change could have this effect.  But I also
don't see how this could occur with the patch.  Basically, what happens
is this:

  newbase = some 64K aligned address on the stack
  _main_tls = newbase - CYGTLS_PADSIZE (== 12700)
  $ebp = $esp = _main_tls - 4

So, assuming newbase == 0x10000
    ==> _main_tls == 0xce64
    ==> $ebp/$esp == 0xce60, which is certainly a 16 byte aligned value.

But OTOH I have to admit that I don't see how this alignment business
worked at all.  Aligning the stack to 16 byte in mainCRTStartup doesn't
guarantee that the stack is still 16 byte aligned in main().  If that
worked so far, it seems like a miracle.  The call stack looks like this:

  mainCRTStartup
  -> cygwin_crt0
     -> _dll_crt0
        -> _main_tls->call
	   -> _main_tls->call2
	      -> dll_crt0_1
	         -> main

Every function on the stack changes the stack pointer.  How did that
work?  Coincidence?

And then again, isn't it gcc's job to make sure that the generated code
makes sure the stack is correctly aligned for certain opcodes?

What am I missing?


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

  reply	other threads:[~2011-12-21  9:42 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-20 23:45 Brian Ford
2011-12-21  9:42 ` Corinna Vinschen [this message]
2011-12-21 10:46   ` Corinna Vinschen
2011-12-21 15:20   ` Dave Korn
2011-12-21 15:41     ` Corinna Vinschen
2011-12-21 16:22       ` Brian Ford
2011-12-21 16:51         ` Corinna Vinschen
2011-12-22 18:51           ` Brian Ford
2011-12-23 13:53             ` Corinna Vinschen
2011-12-28  0:12               ` Brian Ford
2012-01-09 14:14                 ` Corinna Vinschen
2012-01-09 15:41                   ` Brian Ford
2012-01-09 17:36                     ` Corinna Vinschen
2011-12-21 18:20         ` Brian Ford
2011-12-21 21:25           ` Brian Ford
2011-12-22  9:28             ` Corinna Vinschen
2011-12-22 15:20               ` Brian Ford
2011-12-22 15:32                 ` Corinna Vinschen
2011-12-22 15:40                   ` Corinna Vinschen
2011-12-22 15:50                     ` Brian Ford
2011-12-22 15:48                   ` Brian Ford
2011-12-21 16:13   ` Brian Ford

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=20111221094211.GH23547@calimero.vinschen.de \
    --to=corinna-cygwin@cygwin.com \
    --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).