Strange behaviour when loading a library twice.
Hello. This is an output of uname:
Trying to port common lisp IOLib library on DragonFly, I have encountered a
strange behaviour (of RTLD as I think). Assume you have a library which
mmap's a fixed (with flag MAP_TRYFIXED) region of memory in its
constructor. When your program opens it with dlopen, then closes it with
dlcose and again opens with dlopen, the second call to mmap from the
constructor will fail. Is it OK?
I attach a testing program (test.c). Try to compile it and run with
$ cc -o test test.c
$ ./test /usr/lib/thread/libthread_xu.so.
You will get the following output:
Fatal error 'Cannot allocate red zone for initial thread' at line 275 in
it.c (errno =
Abort (core dumped)
You can try any other library which is linked against -lpthread or you can
try my own library testlib.c
Compile it as follows:
$ cc -shared -fPIC -o testlib.so testlib.c
And run the test:
$ ./test ./testlib.so
You will get:
Failed to allocate some space with initialized == 0
In FreeBSD, for example, mmap succeeds two times.
#1 Updated by shamaz about 3 years ago
UPD: Please ignore my own library, as MAP_FIXED flag in FreeBSD just overwrites existing mapping. Try any library which was linked against pthreads.
For some reason the constructor of libthread_xu.so will be called twice which will give you an error:
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)