tst-tls6.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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-tlsmod2.so";
  11. int result = 0;
  12. int *foop;
  13. int *foop2;
  14. int (*fp) (int, int *);
  15. void *h;
  16. int i;
  17. int modid = -1;
  18. for (i = 0; i < 10; ++i)
  19. {
  20. h = dlopen (modname, RTLD_LAZY);
  21. if (h == NULL)
  22. {
  23. printf ("cannot open '%s': %s\n", modname, dlerror ());
  24. exit (1);
  25. }
  26. /* Dirty test code here: we peek into a private data structure.
  27. We make sure that the module gets assigned the same ID every
  28. time. The value of the first round is used. */
  29. #ifdef __UCLIBC__
  30. if (modid == -1)
  31. modid = ((struct dyn_elf *) h)->dyn->l_tls_modid;
  32. else if (((struct dyn_elf *)h)->dyn->l_tls_modid != (size_t) modid)
  33. {
  34. printf ("round %d: modid now %zu, initially %d\n",
  35. i,
  36. ((struct dyn_elf *)h)->dyn->l_tls_modid,
  37. modid);
  38. result = 1;
  39. }
  40. #else
  41. if (modid == -1)
  42. modid = ((struct link_map *) h)->l_tls_modid;
  43. else if (((struct link_map *) h)->l_tls_modid != modid)
  44. {
  45. printf ("round %d: modid now %zd, initially %d\n",
  46. i, ((struct link_map *) h)->l_tls_modid, modid);
  47. result = 1;
  48. }
  49. #endif
  50. foop = dlsym (h, "foo");
  51. if (foop == NULL)
  52. {
  53. printf ("cannot get symbol 'foo': %s\n", dlerror ());
  54. exit (1);
  55. }
  56. *foop = 42 + i;
  57. fp = dlsym (h, "in_dso");
  58. if (fp == NULL)
  59. {
  60. printf ("cannot get symbol 'in_dso': %s\n", dlerror ());
  61. exit (1);
  62. }
  63. result |= fp (42 + i, foop);
  64. foop2 = dlsym (h, "foo");
  65. if (foop2 == NULL)
  66. {
  67. printf ("cannot get symbol 'foo' the second time: %s\n", dlerror ());
  68. exit (1);
  69. }
  70. if (foop != foop2)
  71. {
  72. puts ("address of 'foo' different the second time");
  73. result = 1;
  74. }
  75. else if (*foop != 16)
  76. {
  77. puts ("foo != 16");
  78. result = 1;
  79. }
  80. dlclose (h);
  81. }
  82. return result;
  83. #else
  84. return 0;
  85. #endif
  86. }
  87. #include "../test-skeleton.c"