tst-tls7.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include <dlfcn.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <tls.h>
  5. #include <link.h>
  6. #ifdef __UCLIBC__
  7. #include "dl-elf.h"
  8. #include "dl-hash.h"
  9. #endif
  10. #define TEST_FUNCTION do_test ()
  11. static int
  12. do_test (void)
  13. {
  14. #ifdef USE_TLS
  15. static const char modname[] = "tst-tlsmod3.so";
  16. int result = 0;
  17. int (*fp) (void);
  18. void *h;
  19. int i;
  20. int modid = -1;
  21. for (i = 0; i < 10; ++i)
  22. {
  23. h = dlopen (modname, RTLD_LAZY);
  24. if (h == NULL)
  25. {
  26. printf ("cannot open '%s': %s\n", modname, 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 (modid == -1)
  34. modid = ((struct link_map *)((struct dyn_elf *)h)->dyn)->l_tls_modid;
  35. else if (((struct link_map *)((struct dyn_elf *)h)->dyn)->l_tls_modid
  36. != (size_t) modid)
  37. {
  38. printf ("round %d: modid now %zu, initially %d\n",
  39. i,
  40. ((struct link_map *)((struct dyn_elf *)h)->dyn)->l_tls_modid,
  41. modid);
  42. result = 1;
  43. }
  44. #else
  45. if (modid == -1)
  46. modid = ((struct link_map *) h)->l_tls_modid;
  47. else if (((struct link_map *) h)->l_tls_modid != (size_t) modid)
  48. {
  49. printf ("round %d: modid now %zu, initially %d\n",
  50. i, ((struct link_map *) h)->l_tls_modid, modid);
  51. result = 1;
  52. }
  53. #endif
  54. fp = dlsym (h, "in_dso2");
  55. if (fp == NULL)
  56. {
  57. printf ("cannot get symbol 'in_dso2': %s\n", dlerror ());
  58. exit (1);
  59. }
  60. result |= fp ();
  61. dlclose (h);
  62. }
  63. return result;
  64. #else
  65. return 0;
  66. #endif
  67. }
  68. #include "../test-skeleton.c"