tst-tls7.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 dyn_elf *) h)->dyn->l_tls_modid;
  35. else if (((struct dyn_elf *)h)->dyn->l_tls_modid != (size_t) modid)
  36. {
  37. printf ("round %d: modid now %zu, initially %d\n",
  38. i,
  39. ((struct dyn_elf *)h)->dyn->l_tls_modid,
  40. modid);
  41. result = 1;
  42. }
  43. #else
  44. if (modid == -1)
  45. modid = ((struct link_map *) h)->l_tls_modid;
  46. else if (((struct link_map *) h)->l_tls_modid != (size_t) modid)
  47. {
  48. printf ("round %d: modid now %zu, initially %d\n",
  49. i, ((struct link_map *) h)->l_tls_modid, modid);
  50. result = 1;
  51. }
  52. #endif
  53. fp = dlsym (h, "in_dso2");
  54. if (fp == NULL)
  55. {
  56. printf ("cannot get symbol 'in_dso2': %s\n", dlerror ());
  57. exit (1);
  58. }
  59. result |= fp ();
  60. dlclose (h);
  61. }
  62. return result;
  63. #else
  64. return 0;
  65. #endif
  66. }
  67. #include "../test-skeleton.c"