tst-tls7.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include <dlfcn.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <link.h>
  5. #define TEST_FUNCTION do_test ()
  6. static int
  7. do_test (void)
  8. {
  9. #ifdef USE_TLS
  10. static const char modname[] = "tst-tlsmod3.so";
  11. int result = 0;
  12. int (*fp) (void);
  13. void *h;
  14. int i;
  15. int modid = -1;
  16. for (i = 0; i < 10; ++i)
  17. {
  18. h = dlopen (modname, RTLD_LAZY);
  19. if (h == NULL)
  20. {
  21. printf ("cannot open '%s': %s\n", modname, dlerror ());
  22. exit (1);
  23. }
  24. /* Dirty test code here: we peek into a private data structure.
  25. We make sure that the module gets assigned the same ID every
  26. time. The value of the first round is used. */
  27. #ifdef __UCLIBC__
  28. if (modid == -1)
  29. modid = ((struct dyn_elf *) h)->dyn->l_tls_modid;
  30. else if (((struct dyn_elf *)h)->dyn->l_tls_modid != (size_t) modid)
  31. {
  32. printf ("round %d: modid now %zu, initially %d\n",
  33. i,
  34. ((struct dyn_elf *)h)->dyn->l_tls_modid,
  35. modid);
  36. result = 1;
  37. }
  38. #else
  39. if (modid == -1)
  40. modid = ((struct link_map *) h)->l_tls_modid;
  41. else if (((struct link_map *) h)->l_tls_modid != (size_t) modid)
  42. {
  43. printf ("round %d: modid now %zu, initially %d\n",
  44. i, ((struct link_map *) h)->l_tls_modid, modid);
  45. result = 1;
  46. }
  47. #endif
  48. fp = dlsym (h, "in_dso2");
  49. if (fp == NULL)
  50. {
  51. printf ("cannot get symbol 'in_dso2': %s\n", dlerror ());
  52. exit (1);
  53. }
  54. result |= fp ();
  55. dlclose (h);
  56. }
  57. return result;
  58. #else
  59. return 0;
  60. #endif
  61. }
  62. #include "../test-skeleton.c"