I looked into the SF-bug [ 1012521 ] getUserEntryForID dies where a reentrant
function from libc would cause an illegal instruction. First, I thought the
maybe we'd forgotten to pass -D_POSIX_PTHREAD_SEMANTICS, but it's there after all.
It looks like something doesn't work right when Solaris wraps the reentrant
functions in the following way:

<pwd.h> does something along the lines of

static int
getpwuid_r(__uid, __pwd, __buf, __len, __res)
        uid_t __uid;
        struct passwd *__pwd;
        char *__buf;
        int __len;
        struct passwd **__res;
{
        extern int __posix_getpwuid_r();
        return (__posix_getpwuid_r(__uid, __pwd, __buf, __len, __res));
}

System/Posix/User.raw_s looks like this:

        .type    getpwuid_r,#function       (*)
        .proc   04
getpwuid_r:
        !#PROLOGUE# 0                       (*)
        save    %sp, -112, %sp              (*)
        !#PROLOGUE# 1                       (*)
        mov     %i0, %o0
        mov     %i1, %o1
        mov     %i2, %o2
        mov     %i3, %o3
        call    __posix_getpwuid_r, 0
        mov     %i4, %o4
        ret                                 (*)
        restore %g0, %o0, %o0               (*)
.LLfe6:
        .size    getpwuid_r,.LLfe6-getpwuid_r (*)
        .type    getpwnam_r,#function       (*)
        .proc   04
getpwnam_r:
 ...

The (*) marked lines get removed by the mangler. Nothing gets inserted. Judging by 
gdb's output
(the getpwnam_r doesn't really make sense)

#0  0xff317cac in __posix_getpwuid_r () from /usr/lib/libc.so.1
#1  0x12110 in getpwnam_r ()
#2  0x1b1374 in schedule (mainThread=0x20a748, initialCapability=0xff1c0000) at 
Schedule.c:912

it looks like execution of getpwuid_r falls through to getpwnam_r:

The funny thing is, if I write my own wrapper my_getpwuid_r which simply
calls getpwuid_r from cbits/HsUnix.c and use this wrapper from User.hsc,
I get a working program which doesn't SIGILL. The C-bit of course has retained the 
ret/restore
combination since it isn't mangled.

Also, I get the following warnings:

../../ghc/compiler/ghc-inplace -H32m -O0 -W -fno-warn-unused-matches 
-fwarn-unused-imports -liberty -Iinclude -D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT 
-package-name unix -O -dcore-lint -W -fno-warn-unused-matches -fwarn-unused-imports 
-keep-hc-files  -package base    -c System/Posix/User.hs -o System/Posix/User.o  -ohi 
System/Posix/User.hi
Warning: retaining unknown function `asctime_r' in output from C compiler
Warning: retaining unknown function `ctime_r' in output from C compiler
Warning: retaining unknown function `getlogin_r' in output from C compiler
Warning: retaining unknown function `ttyname_r' in output from C compiler
Warning: retaining unknown function `sigwait' in output from C compiler
Warning: retaining unknown function `getpwuid_r' in output from C compiler
Warning: retaining unknown function `getpwnam_r' in output from C compiler
Warning: retaining unknown function `getgrgid_r' in output from C compiler
Warning: retaining unknown function `getgrnam_r' in output from C compiler

Can somebody make heads and tails out of this? If this proves non-trivial to fix,
I could move all affected functions into a cbit...
-- 
Volker Stolz * http://www-i2.informatik.rwth-aachen.de/stolz/ * PGP * S/MIME
_______________________________________________
Cvs-ghc mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/cvs-ghc

Reply via email to