From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12351 invoked by alias); 5 Oct 2008 12:32:19 -0000 Received: (qmail 12339 invoked by uid 22791); 5 Oct 2008 12:32:18 -0000 X-Spam-Check-By: sourceware.org Received: from smtp8-g19.free.fr (HELO smtp8-g19.free.fr) (212.27.42.65) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sun, 05 Oct 2008 12:31:31 +0000 Received: from smtp8-g19.free.fr (localhost [127.0.0.1]) by smtp8-g19.free.fr (Postfix) with ESMTP id 91C8132A831 for ; Sun, 5 Oct 2008 14:31:28 +0200 (CEST) Received: from [192.168.0.2] (gre92-6-82-231-206-104.fbx.proxad.net [82.231.206.104]) by smtp8-g19.free.fr (Postfix) with ESMTP id 679A932A7DE for ; Sun, 5 Oct 2008 14:31:28 +0200 (CEST) Message-ID: <48E8B399.502@yahoo.fr> Date: Sun, 05 Oct 2008 12:32:00 -0000 From: =?ISO-8859-1?Q?S=E9bastien_Kunz-Jacques?= User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 To: pthreads-win32@sourceware.org Subject: pthreads-win32 2.8.0, stack alignment, and SSE code Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Mailing-List: contact pthreads-win32-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: pthreads-win32-owner@sourceware.org X-SW-Source: 2008/txt/msg00053.txt.bz2 Hi, I encountered problems with SSE code compiled with recent mingw GCC (4.3.2, TDM release, http://www.tdragon.net/recentgcc/) and using pthreads 2.8.0. After inverstigation, crashes occured because the code was trying to read operands on the stack, assuming the stack was 16-byte aligned as is the case in the main thread (the main function aligns the stack and alignment is maintained during each function call). I solved the issue with a very simple patch that uses some GCC wizardry to force stack realignment upon entry in a new thread: --- ptw32_threadStart.c Sun May 15 17:28:27 2005 +++ ptw32_threadStart.c Mon Sep 29 21:28:16 2008 @@ -116,6 +116,9 @@ #endif +#if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__>1) +__attribute__((force_align_arg_pointer)) +#endif #if ! defined (__MINGW32__) || (defined (__MSVCRT__) && ! defined (__DMC__)) unsigned __stdcall The attribute force_align_arg_pointer should be added to every function that is called with a stack with insufficient alignment; as far as I am concerned doing this for threadStart only solved my problems. Maybe this small patch could be added to the pthread code?