Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 192711 - multiple threading libraries cause symbol mixing/ambiguity and resultant crashes/instability
Summary: multiple threading libraries cause symbol mixing/ambiguity and resultant cras...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo/Alt
Classification: Unclassified
Component: FreeBSD (show other bugs)
Hardware: All FreeBSD
: High critical (vote)
Assignee: Gentoo/BSD Team
URL:
Whiteboard:
Keywords:
Depends on: 193695
Blocks:
  Show dependency tree
 
Reported: 2007-09-16 17:55 UTC by Joe Peterson (RETIRED)
Modified: 2007-10-23 12:03 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
freebsd-lib-6.2-r3.ebuild (freebsd-lib-6.2-r3.diff,767 bytes, patch)
2007-09-16 18:15 UTC, Joe Peterson (RETIRED)
Details | Diff
freebsd-lib-6.2-r3.ebuild (freebsd-lib-6.2-r3.diff,1.54 KB, patch)
2007-09-25 01:56 UTC, Joe Peterson (RETIRED)
Details | Diff
freebsd-lib-6.2-r3.ebuild (x.patch,1.70 KB, patch)
2007-09-25 11:06 UTC, Roy Marples (RETIRED)
Details | Diff
Move libthr to / (libthr.patch,421 bytes, patch)
2007-09-25 11:06 UTC, Roy Marples (RETIRED)
Details | Diff
freebsd-lib-6.2-r3.euild (x.patch,1.66 KB, patch)
2007-09-25 14:13 UTC, Roy Marples (RETIRED)
Details | Diff
freebsd-lib (x.patch,1.68 KB, patch)
2007-09-26 13:09 UTC, Roy Marples (RETIRED)
Details | Diff
freebsd-lib-6.2-r2.ebuild (freebsd-lib-6.2-r2.ebuild.diff,1.68 KB, patch)
2007-09-27 02:51 UTC, Joe Peterson (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joe Peterson (RETIRED) gentoo-dev 2007-09-16 17:55:36 UTC
In future versions of FreeBSD, the new threading lib (libthr) will replace libpthreads and libc_r.  In 6.2, we now use libmap.conf to map these older libs to libthr, but this does not always prevent symbols from the older libs from sneaking into executables, either dynamically or statically.

If the symbols become mixed, on the i386 arch (in this case), the %%gs register can get stomped on by different libraries and wreak havoc, sometimes resulting in a crash.  If no crash results, even more bizarre instability could potentially occur.

I first found this running ImageMagick's mogrify utility.  Many mutex locks and unlocks happen, and at some point the "curthread" value (stored in %%gs) changes to point to an unitialized thread, and a crash results.  Not all of us could initially get the crash to happen (could have been memory layout?).  Note that compiling ImageMagick with "--without-threads" still reveals the issue; the linker seems to still want to pull in pthreads.

Removing /usr/lib/libpthread.so *after* mogrify was compiled fixed the issue, since the older symbols could not then be used.  However, compiling Imagemagick without libpthread.so in place then resulted in /usr/lib/libpthread.a being linked statically, and the problem continued.

One solution is to replace the actual libpthread files (.a and .so) with links to the libthr files.  Since libmap.conf now also maps libc_r to libthr, we should probably also do the same and link these to libthr.

I am testing this now.
Comment 1 Joe Peterson (RETIRED) gentoo-dev 2007-09-16 18:15:36 UTC
Created attachment 131069 [details, diff]
freebsd-lib-6.2-r3.ebuild

This ebuild patch will re-link the libs as described; I am testing this setup now.
Comment 2 Joe Peterson (RETIRED) gentoo-dev 2007-09-23 22:37:22 UTC
I have been testing two g/fbsd systems with this patch installed.  One uses GCC 4.1.2, and the other 4.2.0, and both now use Xorg 1.4 (one upgraded while patch installed).  Both systems also have had 'emerge system' performed.

Both have worked flawlessly, so I recommend incorporating this patch into freebsd-lib until the specific cause of the symbol mixing is determined.  When the symbols are confused, we know segfaults can result, but I suspect even worse insidious issues could result from the corruption of the %%gs register contents.
Comment 3 Joe Peterson (RETIRED) gentoo-dev 2007-09-25 01:56:16 UTC
Created attachment 131821 [details, diff]
freebsd-lib-6.2-r3.ebuild

New version of the ebuild that does not build libpthread or libc_r (done with make options).  It then does not need to remove these libs before making the symlinks.
Comment 4 Roy Marples (RETIRED) gentoo-dev 2007-09-25 11:06:13 UTC
Created attachment 131840 [details, diff]
freebsd-lib-6.2-r3.ebuild

I think is is better so that bins built against libpthread.so.2 still work.
Also, we need to move libthr to / now.
Comment 5 Roy Marples (RETIRED) gentoo-dev 2007-09-25 11:06:43 UTC
Created attachment 131841 [details, diff]
Move libthr to /
Comment 6 Roy Marples (RETIRED) gentoo-dev 2007-09-25 14:13:04 UTC
Created attachment 131864 [details, diff]
freebsd-lib-6.2-r3.euild
Comment 7 Roy Marples (RETIRED) gentoo-dev 2007-09-26 13:09:24 UTC
Created attachment 131934 [details, diff]
freebsd-lib

Preserve old libs is probably better.
Comment 8 Joe Peterson (RETIRED) gentoo-dev 2007-09-26 19:23:16 UTC
Hmm, only thing I don't like about preserving the libs is that some people will have them and some won't.  For example, they are gone now on my sys, so I will not get them back by re-installing freebsd-lib...  So freebsd-lib is not then as consistent machine to machine.

Also, the latest patch doesn't build libc_r, but it also does not link it to libthr.  Did you intend to get rid of it completely?  That might be OK (it's not in 7.0-CURRENT at all anyway)...
Comment 9 Joe Peterson (RETIRED) gentoo-dev 2007-09-27 02:51:50 UTC
Created attachment 132001 [details, diff]
freebsd-lib-6.2-r2.ebuild

Roy, what do you think of this patch?
Comment 10 Roy Marples (RETIRED) gentoo-dev 2007-10-23 12:03:19 UTC
In portage now, hope we haven't broken too much!