Description of problem: The getaddrinfo() function causes a internal segmentation fault if the binary is linked static and the system has more than one core (e.g. dualcore, quadcore). This behavior is not expected the function is described to be thread safe! How reproducible: Steps to Reproduce: 1. Need a system with multiple cores, it does not crash on single core system 2. Compile the following code ----- dnstest.cpp ---- #include <stdio.h> #include <netdb.h> #include <pthread.h> #include <unistd.h> void *test(void *) { struct addrinfo *res = NULL; fprintf(stderr, "x="); int ret = getaddrinfo("localhost", NULL, NULL, &res); fprintf(stderr, "%d ", ret); return NULL; } int main() { for (int i = 0; i < 512; i++) { pthread_t thr; pthread_create(&thr, NULL, test, NULL); } sleep(5); return 0; } ----- dnstest.cpp ---- g++ -o dnstest -g -static dnstest.cpp -lpthread 3. Let it run ./dnstest x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=x=Segmentation fault (core dumped) If the "-static" is not used it works fine. But we need a static binary and this should work also if linked statically. There is nothing mentioned that static linking won't work. Expected results: The program should print some lines with "x=0" and then end after 5 seconds.
This happens on RedHat 5.3 or Fedora Core 11 or also older systems.
If you want a thread safe nss service you must link dynamically against libpthread, otherwise the dynamically loaded nss service modules cannot find the pthread functions. Alternatively, you need to statically link against the nss modules.