X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-0.7 required=5.0 tests=AWL,BAYES_20 X-Spam-Check-By: sourceware.org Date: Tue, 27 Dec 2011 18:06:23 -0600 From: Brian Ford Reply-To: cygwin AT cygwin DOT com To: cygwin AT cygwin DOT com Subject: Re: 16 byte pthread stack alignments In-Reply-To: <20111223135247.GM31936@calimero.vinschen.de> Message-ID: References: <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> <20111221165053 DOT GA9699 AT calimero DOT vinschen DOT de> <20111223135247 DOT GM31936 AT calimero DOT vinschen DOT de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="-559023410-543322518-1325030783=:748" X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com ---559023410-543322518-1325030783=:748 Content-Type: text/plain; charset="US-ASCII" On Fri, 23 Dec 2011, Corinna Vinschen wrote: > On Dec 22 12:51, Brian Ford wrote: > > 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. After studying this more today, I was wrong in my description of the cause and fix above. It appears the stack needs to be 16 byte aligned at the call instruction. That is, before the return address is pushed. > Sorry, but what I don't get from your reply is if the andl worked or > not. No; by itself, it does not. Adding a "subl $12, %%esp" following it so that the stack is 16 byte aligned after the thread arg is pushed does work. There are probably more efficient and/or cleaner ways of doing it though. STC attached, but note that it seems to always pass with gcc-4. Only gcc 3.4.4 appears to require the extra alignment. PS. Note that with my custom built cygwin DLL from CVS today, I can't compile the STC: gcc -g -O2 -Wall pthread_sse_align.c -o pthread_sse_align.exe pthread_sse_align.c:0: fatal error: can't open /tmp/ccMkTl4f.s for writing: No such file or directory compilation terminated. Also, every error message from an abnormally exiting application (including when the attached test case fails) mysteriously seems to print 4-6 times? -- Brian Ford Staff Realtime Software Engineer VITAL - Visual Simulation Systems FlightSafety International the best safety device in any aircraft is a well-trained crew... ---559023410-543322518-1325030783=:748 Content-Type: text/plain; charset="US-ASCII"; name="pthread_sse_align.c" Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: Content-Disposition: attachment; filename="pthread_sse_align.c" I2luY2x1ZGUgPHB0aHJlYWQuaD4NCiNpbmNsdWRlIDxzdGRpby5oPg0KI2lu Y2x1ZGUgPHN0cmluZy5oPg0KI2luY2x1ZGUgPHN0ZGxpYi5oPg0KDQojZGVm aW5lIEFMSUdOMTYoYSkgYSBfX2F0dHJpYnV0ZV9fKChhbGlnbmVkICgxNikp KQ0KDQp2b2lkICpydW5fdGVzdCh2b2lkICphcmcpDQp7DQogICAgQUxJR04x NihjaGFyIHRbMTZdKTsNCg0KICAgIGlmICgobG9uZykmdFswXSAmIDE1KQ0K ICAgIHsNCglmcHJpbnRmKHN0ZGVyciwgInB0aHJlYWQgMTYgYnl0ZSBzdGFj ayB2YXJpYWJsZSBhbGlnbm1lbnQgZmFpbGVkOiB0ICVwXG4iLCAmdFswXSk7 DQoJZXhpdCgtMSk7DQogICAgfQ0KDQogICAgcmV0dXJuIE5VTEw7DQp9DQoN CmludCBtYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pDQp7DQogICAgQUxJ R04xNihjaGFyIG1bMTZdKTsNCiAgICBpbnQgICAgICAgc3RhdDsNCiAgICBw dGhyZWFkX3QgdGlkOw0KDQogICAgaWYgKChsb25nKSZtWzBdICYgMTUpDQog ICAgew0KCWZwcmludGYoc3RkZXJyLCAibWFpbiB0aHJlYWQgMTYgYnl0ZSBz dGFjayB2YXJpYWJsZSBhbGlnbm1lbnQgZmFpbGVkOiBtICVwXG4iLCAmbVsw XSk7DQoJcmV0dXJuIC0xOw0KICAgIH0NCg0KICAgIHN0YXQgPSBwdGhyZWFk X2NyZWF0ZSgmdGlkLCBOVUxMLCAmcnVuX3Rlc3QsIE5VTEwpOw0KICAgIGlm IChzdGF0KQ0KICAgIHsNCglmcHJpbnRmKHN0ZGVyciwgInB0aHJlYWRfY3Jl YXRlIGZhaWxlZDogJXNcbiIsIHN0cmVycm9yKHN0YXQpKTsNCglyZXR1cm4g LTE7DQogICAgfQ0KDQogICAgc3RhdCA9IHB0aHJlYWRfam9pbih0aWQsIE5V TEwpOw0KICAgIGlmIChzdGF0KQ0KICAgIHsNCglmcHJpbnRmKHN0ZGVyciwg InB0aHJlYWRfam9pbiBmYWlsZWQ6ICVzXG4iLCBzdHJlcnJvcihzdGF0KSk7 DQoJcmV0dXJuIC0xOw0KICAgIH0NCg0KICAgIHByaW50ZigiVGVzdCBwYXNz ZWRcbiIpOw0KICAgIHJldHVybiAwOw0KfQ0K ---559023410-543322518-1325030783=:748 Content-Type: text/plain; charset=us-ascii -- 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 ---559023410-543322518-1325030783=:748--