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

Matthew Dillon dillon at apollo.backplane.com
Tue Apr 15 17:42:28 PDT 2014


:>
: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.

    Excellent sleuthing.  The question is what do we do about it?
    Should we even support dlclose() on a load-time-opened library?

    It's hard to see how that could be implemented safely so the 'fix'
    might be to flag all load-time libraries as not being closeable.

					-Matt




More information about the Users mailing list