From owner-freebsd-amd64@FreeBSD.ORG Wed Dec 3 01:12:57 2003 Return-Path: Delivered-To: freebsd-amd64@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 95A3116A4CE for ; Wed, 3 Dec 2003 01:12:57 -0800 (PST) Received: from canning.wemm.org (canning.wemm.org [192.203.228.65]) by mx1.FreeBSD.org (Postfix) with ESMTP id BDF7E43FBF for ; Wed, 3 Dec 2003 01:12:56 -0800 (PST) (envelope-from peter@wemm.org) Received: from wemm.org (localhost [127.0.0.1]) by canning.wemm.org (Postfix) with ESMTP id A47F92A7EA; Wed, 3 Dec 2003 01:12:56 -0800 (PST) (envelope-from peter@wemm.org) X-Mailer: exmh version 2.6.3 04/04/2003 with nmh-1.0.4 To: adridg@cs.kun.nl In-Reply-To: Date: Wed, 03 Dec 2003 01:12:56 -0800 From: Peter Wemm Message-Id: <20031203091256.A47F92A7EA@canning.wemm.org> cc: freebsd-amd64@freebsd.org Subject: Re: floats in pthreads X-BeenThere: freebsd-amd64@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Porting FreeBSD to the AMD64 platform List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Dec 2003 09:12:57 -0000 Adriaan de Groot wrote: > Thanks to Peter's patch to libc_r, both my test program and ogg123 are > working properly now. This makes PR 59650 fixed, if someone feels like > closing it. Now, if you're feeling game, please try this too. First, edit /etc/libmap.conf to be like this: libc_r.so.5 libkse.so.1 libc_r.so libkse.so Then check if ogg123 etc work. They should blow up or hang. Its actually in a SIGBUS loop. I found that ctrl-\ kills it easily. Then try this patch: http://people.freebsd.org/~peter/amd64_kse.diff Index: libc/amd64/gen/makecontext.c =================================================================== RCS file: /home/ncvs/src/lib/libc/amd64/gen/makecontext.c,v retrieving revision 1.1 diff -u -r1.1 makecontext.c --- libc/amd64/gen/makecontext.c 19 Jul 2003 04:41:08 -0000 1.1 +++ libc/amd64/gen/makecontext.c 3 Dec 2003 08:45:22 -0000 @@ -70,8 +70,12 @@ /* Allocate space for a maximum of 6 arguments on the stack. */ args = sp - 6; - /* Account for arguments on stack and align to 16 bytes. */ - sp -= 8; + /* + * Account for arguments on stack and do the funky C entry alignment. + * This means that we need an 8-byte-odd alignment since the ABI expects + * the return address to be pushed, thus breaking the 16 byte alignment. + */ + sp -= 7; /* Add the arguments: */ va_start(ap, argc); Index: libpthread/arch/amd64/amd64/enter_uts.S =================================================================== RCS file: /home/ncvs/src/lib/libpthread/arch/amd64/amd64/enter_uts.S,v retrieving revision 1.3 diff -u -r1.3 enter_uts.S --- libpthread/arch/amd64/amd64/enter_uts.S 2 Aug 2003 22:39:10 -0000 1.3 +++ libpthread/arch/amd64/amd64/enter_uts.S 3 Dec 2003 08:59:00 -0000 @@ -35,7 +35,7 @@ ENTRY(_amd64_enter_uts) addq %rcx, %rdx /* get stack base */ andq $~0xf, %rdx /* align to 16 bytes */ + subq $8,%rdx /* simulate "call" */ movq %rdx, %rsp /* switch to UTS stack */ movq %rdx, %rbp /* set frame */ - pushq %rsi - ret + jmpq *%rsi You'll need to rebuild src/lib/libc *and* src/lib/libpthread. This fixes ogg123 for me when using libkse. I get a segfault when I ^C ogg123 when using the oss output driver. If I use '-d raw' or '-d arts', it exits cleanly. The same happens with libc_r, but I think thats a bug in the application and/or the libao sound driver plugins, not the system thread libraries. The pushq/ret -> jmp *%rsi is cosmetic (and a little bit of CYA insurance), not a part of the bug fix. Note that I have not found a place to take care of the 128 byte stack red-zone yet, and I'm not sure if I even need to yet or not. I suspect I do. Anyway, please let me know success/failure if anybody tries this. Cheers, -Peter -- Peter Wemm - peter@wemm.org; peter@FreeBSD.org; peter@yahoo-inc.com "All of this is for nothing if we don't go to the stars" - JMS/B5