Re: dlopen() and dlclose() are not MT-safe?



Kostik Belousov wrote:
Oops. Completely reversed condition in the if. :(. Also, I don't think it
shall returns the error in this situation. New take:

Index: libexec/rtld-elf/rtld.c
===================================================================
RCS file: /usr/local/arch/ncvs/src/libexec/rtld-elf/rtld.c,v
retrieving revision 1.112
diff -u -r1.112 rtld.c
--- libexec/rtld-elf/rtld.c 24 Dec 2005 15:37:30 -0000 1.112
+++ libexec/rtld-elf/rtld.c 22 Mar 2006 19:03:12 -0000
@@ -1688,6 +1688,11 @@
wlock_release(rtld_bind_lock, lockstate);
objlist_call_fini(&list_fini);
lockstate = wlock_acquire(rtld_bind_lock);
+ if (root->refcount != 0) {
+ wlock_release(rtld_bind_lock, lockstate);
+ return 0;
+ }
+
objlist_remove_unref(&list_fini);

/* Finish cleaning up the newly-unreferenced objects. */

Thanks. I applied your patch and ran the test program once more.

When linked with libpthread:
% ./dltest
Segmentation fault (core dumped)

When linked with libthr:
% ./dltest
ld-elf.so.1: assert failed: /usr/src/libexec/rtld-elf/rtld.c:1728

In libpthread case, the result was changed. I got no "assert failed"
message, and it took longer time to crash than before. In libthr
case, I could not find any difference.

BTW do you know the reason why lock is released before calling
objlist_call_fini()? If we don't release the lock, what problem will
occur? deadlock?

--
Kazuaki Oda
_______________________________________________
freebsd-hackers@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: libpthread vs libthr.
    ... I suggest the following simple patch. ... Its effect on platforms where libpthread is available is to link ... libthr to libpthread if WITHOUT_LIBPTHREAD is set in /etc/src.conf. ...
    (freebsd-current)
  • Re: libpthread vs libthr.
    ... I suggest the following simple patch. ... Its effect on platforms where libpthread is available is to link ... libthr to libpthread if WITHOUT_LIBPTHREAD is set in /etc/src.conf. ...
    (freebsd-current)
  • Re: libthr & atomic_xxx ops
    ... libpthread and libthr grew the following warnings in ... > Can you try this patch, and see if the warnings go away? ... I'm testing a patch for libpthread. ...
    (freebsd-current)
  • Re: libc_r is deprecated
    ... In the libthr vs. libpthread ... it could well be that libpthread reduces kernel lock ...
    (freebsd-arch)
  • Re: libc_r is deprecated
    ... libpthread, and libthr is way behind. ... how libpthread doesn't handle SMP scheduling well either. ... especially embarresing because libc_r is a single process, ...
    (freebsd-arch)