Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 03 Dec 2003 01:12:56 -0800
From:      Peter Wemm <peter@wemm.org>
To:        adridg@cs.kun.nl
Cc:        freebsd-amd64@freebsd.org
Subject:   Re: floats in pthreads 
Message-ID:  <20031203091256.A47F92A7EA@canning.wemm.org>
In-Reply-To: <Pine.GSO.4.44.0312022149410.370-100000@odin.cs.kun.nl> 

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20031203091256.A47F92A7EA>