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

Alexander Kabaev kabaev at
Thu Oct 5 16:48:03 PDT 2006

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.
> -- 
> 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url :

More information about the freebsd-threads mailing list