Can anyone help to shed the light on mysterious bug in SBCL (probably)?

Vasily Postnicov shamaz.mazum at gmail.com
Mon Apr 14 23:42:50 PDT 2014


2014-04-14 20:50 GMT+04:00 Matthew Dillon <dillon at apollo.backplane.com>:

>
> :Hello. I use DragonFlyBSD on x86-64 machine:
> :
> :Fatal error 'Cannot allocate red zone for initial thread' at line 275 in
> :file /usr/src/lib/libthread_xu/thread/thr_init.c (errno = 12)
>
>     Hmm.  It sounds like the threading system is being started late.
>     What is happening is that the main program has already allocated stack
>     past the initial thread stack size before trying to start the pthreads
>     subsystem.  This is a lot of space... 2MB or so.  I don't know why it
>     is doing that.
>
>     Either that or some part of SBCL did some specific mmap()'s into
>     the user stack space which it should not have done.  It is one of those
>     two things.
>
>     Here is something to try real quick as a patch to libthread_xu.  It
>     requires DragonFly sources in /usr/src (if you haven't already) to test
>     this:
>
>         cd /usr/src/lib/libthread_xu
>
>         Change THR_STACK_INITIAL from THR_STACK_DEFAULT * 2 to
>         THR_STACK_DEFAULT * 4 in thread/thr_private.h.
>
>         Then recompile libthread_xu:
>
>         cd /usr/srclib/libthread_xu
>         make clean
>         make obj
>         make clean
>         make -j 4
>         make install
>
>     If that doesn't work then try * 8... I don't know how much stack lisp
>     is trying to use.  The default 2MB is already a lot.  So if it still
>     doesn't work then it must be trying to do specific mmap()'s into the
>     user stack area which the program should definitely not be doing.
>
>                                                     -Matt
>
>
I finally found the problem! This happens when the library is loaded TWICE
(one time at compile time, one time in load time in IOLIB) and calls
dlclose between two dlopens. Here is a minimal test case in lisp:

(defpackage test
  (:use :cl :cffi))
(eval-when (:compile-toplevel :load-toplevel :execute)
  (define-foreign-library libfixposix
    (t (:default "libfixposix")))
  (use-foreign-library libfixposix))

and here is the same in C:

#include <dlfcn.h>
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    printf ("testing %s\n", argv[1]);
    void *handle = dlopen (argv[1], RTLD_NOW|RTLD_GLOBAL);
    if (handle == NULL)
    {
        fprintf (stderr, "Cannot open the library\n");
        exit (1);
    }
    dlclose(handle);
    void *handle2 = dlopen (argv[1], RTLD_NOW|RTLD_GLOBAL);
    return 0;
}

You can compile my program and try the following:
find /usr/local/lib -name "*.so" -exec ./test {} \;

You will see many of these errors not for all libraries, but for many of
them. I cannot say by now why it does not work for all libraries.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dragonflybsd.org/pipermail/users/attachments/20140415/8c34ef98/attachment-0002.html>


More information about the Users mailing list