After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 609926 - segfault due to weak pthread symbols
segfault due to weak pthread symbols
Status: RESOLVED WONTFIX
Product: libxml2
Classification: Platform
Component: general
git master
Other Linux
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2010-02-14 17:20 UTC by Christoph Junghans
Modified: 2010-08-06 13:34 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch to remove weak symbols (3.62 KB, patch)
2010-02-14 17:20 UTC, Christoph Junghans
none Details | Review
test program (912 bytes, application/x-gtar)
2010-03-01 08:13 UTC, Christoph Junghans
  Details
test program (956 bytes, application/x-compressed-tar)
2010-03-01 12:43 UTC, Christoph Junghans
  Details
patch to fix the thread initial issue (1.20 KB, patch)
2010-08-06 13:27 UTC, Christoph Junghans
none Details | Review

Description Christoph Junghans 2010-02-14 17:20:35 UTC
Created attachment 153770 [details] [review]
patch to remove weak symbols

libxml2 uses pthreads by default, without adding -lpthread to libs in libxml2.la or libxml2-2.0.pc. Our code (see votca.org) links against libxml2.

When linking (with libtool) during build we get that some pthread symbol can not be found. Our code does not use threads at all. Ok, one can work around that by adding -lpthread by hand. 

But even worse, when building a completely static binary (common practice in HPC business) we get a segmentation fault due to a jump to address 0, in __xmlGlobalInitMutexLock(). This is also clear due to fact that the linker sees no dependency on pthread. 

The attached patch removes the weak symbols and adds -lpthread to libs -> everything works fine.
Comment 1 Daniel Veillard 2010-02-15 15:38:31 UTC
Sorry, that's a regression for most uses, and I suggest you
ask about the "common practice" of shipping static binaries
on Linux because coming from the libc experts there are a lot
of problems associated with this practice

  http://people.redhat.com/drepper/no_static_linking.html

Shipping statically linked binaries on Linux is nearly garanteed
to hit some problems, you found one with libxml2. But I won't change
libxml2 defaults over this, at best make it a configure time option,
your patch just suppress it completely so not adequate at all.

Daniel
Comment 2 Christoph Junghans 2010-02-15 16:21:43 UTC
I prefer dynamic linking as well, which is obviously the best solution.
However on HPC machines you can not do that, because the binary is compile for the compute nodes which have basically no libraries.

I can compile our code statically, if I build libxml without threads (even without the patch). But I still don't see the point why the pthread functions are weak symbols, which is the actual problem.

What does it harm if libxml is linked against pthreads (in .so and .la files)?
Comment 3 Daniel Veillard 2010-02-16 17:39:08 UTC
memory allocation on single threaded apps is way faster than
on multithreaded for a number of glibc versions. It does make
a difference !

Daniel
Comment 4 Christoph Junghans 2010-02-16 18:44:18 UTC
I see, so how to proceed here?

This there a way to force GNU libtools to link against pthread? 
Adding -lpthread to LDADD helps to solve the shared linking issue, but it doesn't help for static linking. Any ideas?
Comment 5 Christoph Junghans 2010-03-01 08:13:19 UTC
Created attachment 154931 [details]
test program

This is a small test case to see the bug. 
It builds:
-a lib, libinit, which just calls xmlInitParser
-two binaries ,a dynamic and a static one

The static one will fail, when threads are enabled.
Comment 6 Christoph Junghans 2010-03-01 12:43:46 UTC
Created attachment 154941 [details]
test program

Just a better version to avoid some warning.
Comment 7 Christoph Junghans 2010-03-01 14:24:40 UTC
Comment on attachment 154941 [details]
test program

Unneeded, simpler case below.
Comment 8 Christoph Junghans 2010-03-01 14:26:58 UTC
Here is the simplest case I can imagine:
$ cat main.c
#include <libxml/parser.h>

int main(int argc, char **argv) {
            xmlInitParser();
}
$ gcc -static main.c `xml2-config --libs --cflags` -pthread
$ ./a.out
Segmentation fault
Comment 10 Christoph Junghans 2010-08-06 13:27:18 UTC
Created attachment 167251 [details] [review]
patch to fix the thread initial issue

Even if we have switched to expat the problem still persists.

This issue is tracked under debian bug #590934:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=590934

and there is a patch to solve the issue by moving xmlInitThreads()

The patch works for me!