dltest2.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <fcntl.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <dlfcn.h>
  5. #include "thread_db.h"
  6. extern void _dlinfo();
  7. int main(int argc, char **argv) {
  8. void *handle;
  9. td_err_e (*td_init_p) (void);
  10. fprintf(stderr, "Attempting to dlopen() libpthread.so with RTLD_NOW\n");
  11. handle = dlopen ("libpthread.so", RTLD_NOW);
  12. if (!handle) {
  13. fputs (dlerror(), stderr);
  14. exit(1);
  15. }
  16. td_init_p = dlsym (handle, "__pthread_initialize");
  17. if (td_init_p == NULL) {
  18. fprintf(stderr, "yipe! __pthread_initialize() failed!\n");
  19. return EXIT_FAILURE;
  20. }
  21. #if 0 //def __UCLIBC__
  22. _dlinfo(); /* not supported by ld.so.2 */
  23. #endif
  24. dlclose(handle);
  25. fprintf(stderr, "Attempting to dlopen() libpthread.so with RTLD_LAZY\n");
  26. handle = dlopen ("libpthread.so", RTLD_LAZY);
  27. if (!handle) {
  28. fputs (dlerror(), stderr);
  29. exit(1);
  30. }
  31. td_init_p = dlsym (handle, "__pthread_initialize");
  32. if (td_init_p == NULL) {
  33. fprintf(stderr, "yipe! __pthread_initialize() failed!");
  34. return EXIT_FAILURE;
  35. }
  36. #if 0 //def __UCLIBC__
  37. _dlinfo(); /* not supported by ld.so.2 */
  38. #endif
  39. dlclose(handle);
  40. fprintf(stderr, "Everything worked as expected.\n");
  41. return EXIT_SUCCESS;
  42. }