tst-tls8.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 modname1[] = "tst-tlsmod3.so";
  11. static const char modname2[] = "tst-tlsmod4.so";
  12. int result = 0;
  13. int (*fp1) (void);
  14. int (*fp2) (int, int *);
  15. void *h1;
  16. void *h2;
  17. int i;
  18. size_t modid1 = (size_t) -1;
  19. size_t modid2 = (size_t) -1;
  20. int *bazp;
  21. for (i = 0; i < 10; ++i)
  22. {
  23. h1 = dlopen (modname1, RTLD_LAZY);
  24. if (h1 == NULL)
  25. {
  26. printf ("cannot open '%s': %s\n", modname1, dlerror ());
  27. exit (1);
  28. }
  29. /* Dirty test code here: we peek into a private data structure.
  30. We make sure that the module gets assigned the same ID every
  31. time. The value of the first round is used. */
  32. #ifdef __UCLIBC__
  33. if (modid1 == (size_t) -1)
  34. modid1 = ((struct dyn_elf *) h1)->dyn->l_tls_modid;
  35. else if (((struct dyn_elf *)h1)->dyn->l_tls_modid != (size_t) modid1)
  36. {
  37. printf ("round %d: modid now %zd, initially %zd\n",
  38. i,
  39. ((struct dyn_elf *)h1)->dyn->l_tls_modid,
  40. modid1);
  41. result = 1;
  42. }
  43. #else
  44. if (modid1 == (size_t) -1)
  45. modid1 = ((struct link_map *) h1)->l_tls_modid;
  46. else if (((struct link_map *) h1)->l_tls_modid != modid1)
  47. {
  48. printf ("round %d: modid now %zd, initially %zd\n",
  49. i, ((struct link_map *) h1)->l_tls_modid, modid1);
  50. result = 1;
  51. }
  52. #endif
  53. fp1 = dlsym (h1, "in_dso2");
  54. if (fp1 == NULL)
  55. {
  56. printf ("cannot get symbol 'in_dso2' in %s\n", modname1);
  57. exit (1);
  58. }
  59. result |= fp1 ();
  60. h2 = dlopen (modname2, RTLD_LAZY);
  61. if (h2 == NULL)
  62. {
  63. printf ("cannot open '%s': %s\n", modname2, dlerror ());
  64. exit (1);
  65. }
  66. /* Dirty test code here: we peek into a private data structure.
  67. We make sure that the module gets assigned the same ID every
  68. time. The value of the first round is used. */
  69. #ifdef __UCLIBC__
  70. if (modid2 == (size_t) -1)
  71. modid2 = ((struct dyn_elf *)h2)->dyn->l_tls_modid;
  72. else if (((struct dyn_elf *)h2)->dyn->l_tls_modid
  73. != (size_t) modid2)
  74. {
  75. printf ("round %d: modid now %zd, initially %zd\n",
  76. i,
  77. ((struct dyn_elf *)h2)->dyn->l_tls_modid,
  78. modid2);
  79. result = 1;
  80. }
  81. #else
  82. if (modid2 == (size_t) -1)
  83. modid2 = ((struct link_map *) h2)->l_tls_modid;
  84. else if (((struct link_map *) h2)->l_tls_modid != modid2)
  85. {
  86. printf ("round %d: modid now %zd, initially %zd\n",
  87. i, ((struct link_map *) h2)->l_tls_modid, modid2);
  88. result = 1;
  89. }
  90. #endif
  91. bazp = dlsym (h2, "baz");
  92. if (bazp == NULL)
  93. {
  94. printf ("cannot get symbol 'baz' in %s\n", modname2);
  95. exit (1);
  96. }
  97. *bazp = 42 + i;
  98. fp2 = dlsym (h2, "in_dso");
  99. if (fp2 == NULL)
  100. {
  101. printf ("cannot get symbol 'in_dso' in %s\n", modname2);
  102. exit (1);
  103. }
  104. result |= fp2 (42 + i, bazp);
  105. dlclose (h1);
  106. dlclose (h2);
  107. h1 = dlopen (modname1, RTLD_LAZY);
  108. if (h1 == NULL)
  109. {
  110. printf ("cannot open '%s': %s\n", modname1, dlerror ());
  111. exit (1);
  112. }
  113. /* Dirty test code here: we peek into a private data structure.
  114. We make sure that the module gets assigned the same ID every
  115. time. The value of the first round is used. */
  116. #ifdef __UCLIBC__
  117. if (((struct dyn_elf *)h1)->dyn->l_tls_modid
  118. != modid1)
  119. {
  120. printf ("round %d: modid now %zd, initially %zd\n",
  121. i,
  122. ((struct dyn_elf *)h1)->dyn->l_tls_modid,
  123. modid1);
  124. result = 1;
  125. }
  126. #else
  127. if (((struct link_map *) h1)->l_tls_modid != modid1)
  128. {
  129. printf ("round %d: modid now %zd, initially %zd\n",
  130. i, ((struct link_map *) h1)->l_tls_modid, modid1);
  131. result = 1;
  132. }
  133. #endif
  134. fp1 = dlsym (h1, "in_dso2");
  135. if (fp1 == NULL)
  136. {
  137. printf ("cannot get symbol 'in_dso2' in %s\n", modname1);
  138. exit (1);
  139. }
  140. result |= fp1 ();
  141. h2 = dlopen (modname2, RTLD_LAZY);
  142. if (h2 == NULL)
  143. {
  144. printf ("cannot open '%s': %s\n", modname2, dlerror ());
  145. exit (1);
  146. }
  147. /* Dirty test code here: we peek into a private data structure.
  148. We make sure that the module gets assigned the same ID every
  149. time. The value of the first round is used. */
  150. #ifdef __UCLIBC__
  151. if (((struct dyn_elf *)h2)->dyn->l_tls_modid
  152. != modid2)
  153. {
  154. printf ("round %d: modid now %zd, initially %zd\n",
  155. i,
  156. ((struct dyn_elf *)h2)->dyn->l_tls_modid,
  157. modid2);
  158. result = 1;
  159. }
  160. #else
  161. if (((struct link_map *) h2)->l_tls_modid != modid2)
  162. {
  163. printf ("round %d: modid now %zd, initially %zd\n",
  164. i, ((struct link_map *) h2)->l_tls_modid, modid2);
  165. result = 1;
  166. }
  167. #endif
  168. bazp = dlsym (h2, "baz");
  169. if (bazp == NULL)
  170. {
  171. printf ("cannot get symbol 'baz' in %s\n", modname2);
  172. exit (1);
  173. }
  174. *bazp = 62 + i;
  175. fp2 = dlsym (h2, "in_dso");
  176. if (fp2 == NULL)
  177. {
  178. printf ("cannot get symbol 'in_dso' in %s\n", modname2);
  179. exit (1);
  180. }
  181. result |= fp2 (62 + i, bazp);
  182. /* This time the dlclose calls are in reverse order. */
  183. dlclose (h2);
  184. dlclose (h1);
  185. }
  186. return result;
  187. #else
  188. return 0;
  189. #endif
  190. }
  191. #include "../test-skeleton.c"