tst-tls8.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. fp1 = dlsym (h1, "in_dso2");
  30. if (fp1 == NULL)
  31. {
  32. printf ("cannot get symbol 'in_dso2' in %s\n", modname1);
  33. exit (1);
  34. }
  35. result |= fp1 ();
  36. h2 = dlopen (modname2, RTLD_LAZY);
  37. if (h2 == NULL)
  38. {
  39. printf ("cannot open '%s': %s\n", modname2, dlerror ());
  40. exit (1);
  41. }
  42. bazp = dlsym (h2, "baz");
  43. if (bazp == NULL)
  44. {
  45. printf ("cannot get symbol 'baz' in %s\n", modname2);
  46. exit (1);
  47. }
  48. *bazp = 42 + i;
  49. fp2 = dlsym (h2, "in_dso");
  50. if (fp2 == NULL)
  51. {
  52. printf ("cannot get symbol 'in_dso' in %s\n", modname2);
  53. exit (1);
  54. }
  55. result |= fp2 (42 + i, bazp);
  56. dlclose (h1);
  57. dlclose (h2);
  58. h1 = dlopen (modname1, RTLD_LAZY);
  59. if (h1 == NULL)
  60. {
  61. printf ("cannot open '%s': %s\n", modname1, dlerror ());
  62. exit (1);
  63. }
  64. fp1 = dlsym (h1, "in_dso2");
  65. if (fp1 == NULL)
  66. {
  67. printf ("cannot get symbol 'in_dso2' in %s\n", modname1);
  68. exit (1);
  69. }
  70. result |= fp1 ();
  71. h2 = dlopen (modname2, RTLD_LAZY);
  72. if (h2 == NULL)
  73. {
  74. printf ("cannot open '%s': %s\n", modname2, dlerror ());
  75. exit (1);
  76. }
  77. bazp = dlsym (h2, "baz");
  78. if (bazp == NULL)
  79. {
  80. printf ("cannot get symbol 'baz' in %s\n", modname2);
  81. exit (1);
  82. }
  83. *bazp = 62 + i;
  84. fp2 = dlsym (h2, "in_dso");
  85. if (fp2 == NULL)
  86. {
  87. printf ("cannot get symbol 'in_dso' in %s\n", modname2);
  88. exit (1);
  89. }
  90. result |= fp2 (62 + i, bazp);
  91. /* This time the dlclose calls are in reverse order. */
  92. dlclose (h2);
  93. dlclose (h1);
  94. }
  95. return result;
  96. #else
  97. return 0;
  98. #endif
  99. }
  100. #include "../test-skeleton.c"