delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2011/12/22/13:51:55

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00
X-Spam-Check-By: sourceware.org
Date: Thu, 22 Dec 2011 12:51:30 -0600
From: Brian Ford <Brian DOT Ford AT FlightSafety DOT com>
Reply-To: cygwin AT cygwin DOT com
To: cygwin AT cygwin DOT com
Subject: Re: 16 byte pthread stack alignments
In-Reply-To: <20111221165053.GA9699@calimero.vinschen.de>
Message-ID: <Pine.CYG.4.58.1112221245050.748@PC1163-8460-XP.flightsafety.com>
References: <Pine DOT CYG DOT 4 DOT 58 DOT 1112201743030 DOT 3964 AT PC1163-8460-XP DOT flightsafety DOT com> <20111221094211 DOT GH23547 AT calimero DOT vinschen DOT de> <4EF1F937 DOT 9040107 AT gmail DOT com> <20111221154104 DOT GB11841 AT calimero DOT vinschen DOT de> <Pine DOT CYG DOT 4 DOT 58 DOT 1112211020000 DOT 3076 AT PC1163-8460-XP DOT flightsafety DOT com> <20111221165053 DOT GA9699 AT calimero DOT vinschen DOT de>
MIME-Version: 1.0
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On Wed, 21 Dec 2011, Corinna Vinschen wrote:

> On second thought I'm a bit puzzled that the pthread stack isn't
> correctly aligned as well.  Ignoring the pthread_attr_setstack case
> which wasn't supported so far anyway, the OS stack set up by
> CreateThread is 64K aligned.  From that 64K aligned StackBase value, I
> subtract 12704 == 0x31a0 bytes.  So the result should be 16 byte
> aligned even without the andl $-16, %%esp.  Why isn't it?!?

It appears it is, here.

> Does anybody care to tell me what's wrong with the assembler code in
> thread_wrapper?

I don't pretend to understand why, but it appears gcc is expecting the
stack to be 16 byte aligned on entry to the called function, which
includes the 4 byte argument and the 4 byte return address in this case.
I could be wrong, but it appears that would do it.

For a long discussion by those who apparently agree with you about how
crazy this is see:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40838

It looks like gcc 4.6 may finally "do the right thing" itself.

-- 
Brian Ford
Staff Realtime Software Engineer
VITAL - Visual Simulation Systems
FlightSafety International
the best safety device in any aircraft is a well-trained crew...

--
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019