tst-tls6.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. foop = dlsym (h, "foo");
  27. if (foop == NULL)
  28. {
  29. printf ("cannot get symbol 'foo': %s\n", dlerror ());
  30. exit (1);
  31. }
  32. *foop = 42 + i;
  33. fp = dlsym (h, "in_dso");
  34. if (fp == NULL)
  35. {
  36. printf ("cannot get symbol 'in_dso': %s\n", dlerror ());
  37. exit (1);
  38. }
  39. result |= fp (42 + i, foop);
  40. foop2 = dlsym (h, "foo");
  41. if (foop2 == NULL)
  42. {
  43. printf ("cannot get symbol 'foo' the second time: %s\n", dlerror ());
  44. exit (1);
  45. }
  46. if (foop != foop2)
  47. {
  48. puts ("address of 'foo' different the second time");
  49. result = 1;
  50. }
  51. else if (*foop != 16)
  52. {
  53. puts ("foo != 16");
  54. result = 1;
  55. }
  56. dlclose (h);
  57. }
  58. return result;
  59. #else
  60. return 0;
  61. #endif
  62. }
  63. #include "../test-skeleton.c"