From owner-freebsd-threads@FreeBSD.ORG Wed Nov 24 16:34:03 2004 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D985A16A4E2; Wed, 24 Nov 2004 16:34:02 +0000 (GMT) Received: from r1a.corp.servercentral.net (exchange.corp.servercentral.net [66.225.247.198]) by mx1.FreeBSD.org (Postfix) with ESMTP id 309FD43D5E; Wed, 24 Nov 2004 16:34:02 +0000 (GMT) (envelope-from craig@tobuj.gank.org) Received: from mail pickup service by r1a.corp.servercentral.net with Microsoft SMTPSVC; Wed, 24 Nov 2004 10:33:55 -0600 Received: from demandindustries.net ([161.58.224.124]) by r1a.corp.servercentral.net with Microsoft SMTPSVC(6.0.3790.0); Wed, 24 Nov 2004 01:02:58 -0600 Received: from scanner.servercentral.net (scanner.servercentral.net [66.225.196.47]) by demandindustries.net (8.12.11/8.12.9) with ESMTP id iAO7309V006100 for ; Wed, 24 Nov 2004 01:03:00 -0600 (CST) Received: from localhost (localhost [127.0.0.1]) by scanner.servercentral.net (Postfix) with ESMTP id 5B4568700C3 for ; Wed, 24 Nov 2004 01:02:51 -0600 (CST) Received: from scanner.servercentral.net ([127.0.0.1]) by localhost (mb [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 01103-05 for ; Wed, 24 Nov 2004 01:02:50 -0600 (CST) Received: from mx2.freebsd.org (mx2.freebsd.org [216.136.204.119]) by scanner.servercentral.net (Postfix) with ESMTP id 335688700BF for ; Wed, 24 Nov 2004 01:02:50 -0600 (CST) Received: from hub.freebsd.org (hub.freebsd.org [216.136.204.18]) by mx2.freebsd.org (Postfix) with ESMTP id 295A056E40; Wed, 24 Nov 2004 07:02:58 +0000 (GMT) (envelope-from owner-freebsd-hackers@freebsd.org) Received: from hub.freebsd.org (localhost [127.0.0.1]) by hub.freebsd.org (Postfix) with ESMTP id 879B116A508; Wed, 24 Nov 2004 07:02:52 +0000 (GMT) Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7455616A4CE; Wed, 24 Nov 2004 07:02:48 +0000 (GMT) Received: from ion.gank.org (ion.gank.org [69.55.238.164]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2645043D3F; Wed, 24 Nov 2004 07:02:48 +0000 (GMT) (envelope-from craig@tobuj.gank.org) Received: from aldaris.auir.gank.org (arbiter.gank.org [64.81.113.221]) by ion.gank.org (mail) with ESMTP id 8D1CA2AA50; Wed, 24 Nov 2004 01:02:47 -0600 (CST) From: Craig Boston To: freebsd-hackers@freebsd.org Date: Wed, 24 Nov 2004 01:02:41 -0600 User-Agent: KMail/1.7.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200411240102.42269.craig@tobuj.gank.org> X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Sender: owner-freebsd-hackers@freebsd.org Errors-To: owner-freebsd-hackers@freebsd.org X-Virus-Scanned: by amavis for cervercentral.net X-OriginalArrivalTime: 24 Nov 2004 07:03:00.0829 (UTC) FILETIME=[A29728D0:01C4D1F3] cc: freebsd-threads@freebsd.org Subject: SSE vs. stack alignment vs. pthread X-BeenThere: freebsd-threads@freebsd.org List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Nov 2004 16:34:03 -0000 First of all, I'd like to apologize for cross-posting to -hackers and -threads. I'm not sure yet if this is an application bug, a gcc bug, or a pthreads bug, so here goes... I'm currently working on the audacity port. It's up to 1.2.3, but I want to get a problem I've observed with 1.2.2 resolved to make sure that it doesn't crop up later or affect other software... Long story short, audacity is a threaded program. A straight compile of 1.2.2 results in a 100% reproducible bus error that happens on multiple Pentium-4 machines (5.3-STABLE). It always happens at this instruction: 0x081807c4: movaps %xmm0,0xffffff68(%ebp) Now, at that time ebp is 0xbfadc6c0, so ebp+0xffffff68 (-0x152) is 0xbfadc56e. Oops, that's not 16-byte aligned like SSE wants. The offsets vary sligthly depending on the compile flags, etc., but the result is always the same -- SIGBUS. My first suspicion was compiler bug. Audacity doesn't inline any SSE code itself -- the movaps is being generated by gcc as part of the pentium4 optimizations. There are two factors that are a little suspicious, though. 1) When I switch out libpthread for libc_r, the crash goes away. Unfortunately, the gdb in 5.3 seems to have forgotten how to debug libc_r based programs so I can't really tell what is different in that case. I just get "Cannot find thread 2: Thread ID=1, generic error". 2) Some searching turned up several similar problems on Linux and NetBSD. The NetBSD post here [http://mail-index.netbsd.org/port-amd64/2004/02/27/0001.html] indicates that it may be related to stack alignment in the thread library. I'm not sure if the ABI requirement discussed there is NetBSD and/or amd64 specific though. HOWEVER -- I inserted some debugging printfs into libpthread to test this theory. The stack it allocates for that thread is located at 0xbfaad000, which is not only 16-byte aligned but page aligned... So I'm reluctant to blame libpthread as it seems to be doing everything right and even going the extra mile. I honestly don't know whether gcc is expecting the alignment to compensate for the return address push or the function prolog, or if it's just losing track of where the stack should be somewhere. I may be over-analyzing the problem at that point :) Another factor to consider is that nobody has reported similar problems in other software... I've been trying to create a simple test case, however it's proving quite difficult to coax gcc into generating SSE code on its own where I want it. It's of course possible that Audacity itself is doing something weird to cause it, but I haven't been able to find anything suspicious or low-level enough to affect the stack alignment. It could just be a heisenbug, and libc_r is different enough to mask the problem. Any and all suggestions from threads/compiler gurus would be very much appreciated. I'm about ready to throw in the towel and just force "-mno-sse -mno-sse2" compiler flags in the makefile... Thanks, Craig _______________________________________________ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"