Andrew Piskorski
2009-Oct-05 21:22 UTC
[Rd] R's --enable-threads does nothing?; gdb needs -lpthread
In the R-2-9-branch (svn revision 49914, 2009-09-24), R's configure script has an "--enable-threads" option. But, does it do anything useful? When I use "--enable-threads=posix", some of the configure output changes slightly, but it seems to have no effect on the actual link commands used when building R. Is that a bug, or am I misunderstanding what it's supposed to do? Btw, ldd said that exactly these 4 objects are linked against libpthread.so.0, regardless of whether I use --enable-threads or not: ./lib/R/modules/x86_64/R_X11.so ./lib/R/library/tcltk/libs/x86_64/tcltk.so ./lib/R/site-library/bigmemory/libs/x86_64/bigmemory.so ./lib/R/site-library/Rmpi/libs/x86_64/Rmpi.so Next I tried setting the "LIBS=-lpthread" environment variable when calling configure - that works. (Perhaps I should have also set FLIBS, I'm not sure.) The generated Makeconf file now has this: LIBS = -ldl -lm -lpthread and building with that links my libR.so against libpthread.so.0, which fixes the gdb problem described below. Is there any reason you know of NOT to link R with -lpthread on Linux, any potential downside? Now, why do I care about this -lpthread stuff in the first place? It's to work around a gdb limitation. I have a custom library of C code which I use from R, and my library needs to be linked with -lpthread. I know that R isn't thread-safe, and my code is not itself using threads, but it in turn statically links in some lower level libraries which insist on having the -lpthread. That has worked fine for me for a long time, no problems, except that gdb won't work! When I run R under the debugger with "R -d gdb", gdb only works if my own linked-with-pthread package is NOT loaded. As soon as I load it, gdb stops with this error: [Thread debugging using libthread_db enabled] Error while reading shared library symbols: Cannot find new threads: generic error Googling says that happens because the R binary starts out without thread support, and gdb doesn't know what to do when my *.so suddenly brings in the thread stuff. Since I can't stop using -lpthread in my library, the obvious fix is for me to build R itself with -lpthread, so gdb doesn't get confused. -- Andrew Piskorski <atp at piskorski.com> http://www.piskorski.com/
Prof Brian Ripley
2009-Oct-06 06:07 UTC
[Rd] R's --enable-threads does nothing?; gdb needs -lpthread
On Mon, 5 Oct 2009, Andrew Piskorski wrote:> In the R-2-9-branch (svn revision 49914, 2009-09-24), R's configure > script has an "--enable-threads" option. But, does it do anything > useful? When I use "--enable-threads=posix", some of the configure > output changes slightly, but it seems to have no effect on the actual > link commands used when building R. Is that a bug, or am I > misunderstanding what it's supposed to do?The latter. It's part of the libintl (aka gettext-runtime) configuration code included in R, and is not present in the currently active branches. It affects how libintl works when src/extra/intl in the R sources is built -- whether it is by default depends on the OS. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595