threads/103975: Implicit loading/unloading of may crash user processes

Alexander Kabaev kabaev at
Thu Oct 5 16:50:28 PDT 2006

The following reply was made to PR threads/103975; it has been noted by GNATS.

From: Alexander Kabaev <kabaev at>
To: John Baldwin <john at>
Cc: freebsd-threads at, Takahiro <takahiro.kurosawa at>,
 freebsd-gnats-submit at, KUROSAWA at
Subject: Re: threads/103975: Implicit loading/unloading of may
 crash user processes
Date: Thu, 5 Oct 2006 19:47:56 -0400

 Content-Type: text/plain; charset=US-ASCII
 Content-Transfer-Encoding: quoted-printable
 On Thu, 5 Oct 2006 09:06:20 -0400
 John Baldwin <john at> wrote:
 > Actually, I wonder if it should be allowed to unload at all.  On 4.x
 > at work we ran into an issue with the linuxthreads library loading,
 > setting _is_threaded, then unloading with a malloc() occurring during
 > the destructors resolving a _spinlock() weak symbol, then after the
 > libraries were completely unloaded, the next malloc() blew up when
 > _spinlock() pointed off into space.  Hmm, this specific condition is
 > handled I think since __isthreaded in 6.x libpthread isn't set until
 > you do pthread_create() which at that point means a symbol is
 > resolved, and the library won't be unloaded (I think).  Hmm, maybe
 > not since that doesn't guarantee that libc depends on libpthread
 > (that is what keeps it from being unloaded IIRC). So, maybe when the
 > library sets __isthreaded it should call one of the libc functions
 > (like malloc) to force one of the weak symbols to be resolved so it
 > isn't unloaded.
 > > To fix the problem, a function that has __attribute__((destructor))
 > > in libpthread should probably be implemented in order to recover
 > > the initial state before unloading.
 > I'm not sure you can recover the state actually, hence why I think
 > maybe we should make it so that libpthread doesn't unload once it has
 > been loaded.
 > --=20
 > John Baldwin
 Linux does not allow pthread library to be unloaded presumably because
 of reasons like this. From readelf -a /compat/linux/lib/
  0x6ffffffb (FLAGS_1)                    Flags: NODELETE INITFIRST
 Infortunately, rtld does not implement NODELETE and INITFIRST. Both are
 addressed in my patch that I am yet to commit.
 Alexander Kabaev
 Content-Type: application/pgp-signature; name=signature.asc
 Content-Disposition: attachment; filename=signature.asc
 Version: GnuPG v1.4.5 (FreeBSD)

More information about the freebsd-threads mailing list