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

Alexander Kabaev kabaev at gmail.com
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 gmail.com>
To: John Baldwin <john at baldwin.cx>
Cc: freebsd-threads at freebsd.org, Takahiro <takahiro.kurosawa at gmail.com>,
 freebsd-gnats-submit at freebsd.org, KUROSAWA at freebsd.org
Subject: Re: threads/103975: Implicit loading/unloading of libpthread.so may
 crash user processes
Date: Thu, 5 Oct 2006 19:47:56 -0400

 --Sig_olRQb9w73LRMGWxv5Pd0njU
 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 baldwin.cx> wrote:
 
 >=20
 > 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.
 >=20
 > > 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.
 >=20
 > 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
 > --=20
 > John Baldwin
 
 Linux does not allow pthread library to be unloaded presumably because
 of reasons like this. From readelf -a /compat/linux/lib/libpthread.so.0:
 
  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.
 
 
 --=20
 Alexander Kabaev
 
 --Sig_olRQb9w73LRMGWxv5Pd0njU
 Content-Type: application/pgp-signature; name=signature.asc
 Content-Disposition: attachment; filename=signature.asc
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.5 (FreeBSD)
 
 iD8DBQFFJZmvQ6z1jMm+XZYRAkaKAJ9/bV9FU6UgIVbE7QZAhBLKD7rg5ACeMjGr
 1DVtUSKdDtw5N2PFrbduuwc=
 =+av7
 -----END PGP SIGNATURE-----
 
 --Sig_olRQb9w73LRMGWxv5Pd0njU--


More information about the freebsd-threads mailing list