problem with dlopen when used from multiple threads

Kishore K hellokishore at gmail.com
Tue Mar 14 14:28:22 UTC 2006


hi
When dlopen() is used to dynamically load libraries from different threads,
program crashes sometimes with segmentation fault. This problem is observed
with 0.9.27 as well as 0.9.28 libraries on MIPS malta platform. Tool chain
is based on gcc 3.3.6, binutils 2.14.90.0.8 and kernel is 2.4.31

My example program mt-dlbug.c is as follows

#include <stddef.h>
#include <stdio.h>
#include <unistd.h>
#include "pthread.h"
#include <dlfcn.h>
void * mtdlopen(void * arg)
{
  void *h;
  char *error;
  h=dlopen((char *)arg, RTLD_NOW|RTLD_GLOBAL);
  if(!h) {
    if ((error = dlerror()) != NULL) {
      fprintf(stderr,"dlerror: %s\n",error);
    }
  } else {
    fprintf(stderr,"dlopen ok\n");
    dlclose(h);
  }
  return NULL;
}
int main(int argc, char **argv)
{
  int retcode;
  pthread_t th_a,th_b;
  void * retval;
  void *h;
  char *error;

  retcode = pthread_create(&th_a, NULL, mtdlopen, argv[1]);
  if (retcode != 0) fprintf(stderr, "create a failed %d\n", retcode);
  retcode = pthread_create(&th_b, NULL, mtdlopen, argv[2]);
  if (retcode != 0) fprintf(stderr, "create a failed %d\n", retcode);

  retcode = pthread_join(th_a, &retval);
  if (retcode != 0) fprintf(stderr, "join a failed %d\n", retcode);
  else fprintf(stderr, "join a succeeded %d\n", retcode);
  retcode = pthread_join(th_b, &retval);
  if (retcode != 0) fprintf(stderr, "join b failed %d\n", retcode);
  else fprintf(stderr, "join b succeeded %d\n", retcode);

  return 0;
}

program is compiled as $mips-linux-gcc -rdynamic -o mt-dlbug mt-dlbug.c -ldl
-lpthread
When this program is run on
when this program is run with 0.9.27 libaries and tool chain, here is the
output
**
# ./mt-dlbug /lib/libstdc\+\+.so /lib/libncurses.so.5
dlopen ok
join a succeeded 0
Segmentation fault
#
# ./mt-dlbug /lib/libstdc\+\+.so /lib/libncurses.so.5
dlopen ok
join a succeeded 0
dlopen ok
join b succeeded 0

Similar behaviour is observed with 0.9.28 based tool chain and libraries.
Can you please let me know, what the problem is. Am I missing something here
?

thanks,
--kishore
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.busybox.net/pipermail/uclibc/attachments/20060314/f98e87f5/attachment-0001.htm 


More information about the uClibc mailing list